Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/modules/lua Fix cargo cult ioctl implementation for LUAI...



details:   https://anonhg.NetBSD.org/src/rev/10009041fe74
branches:  trunk
changeset: 828675:10009041fe74
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Dec 26 12:43:59 2017 +0000

description:
Fix cargo cult ioctl implementation for LUAINFO: the name and desc fields
are arrays, not pointers, so don't use copyoutstr on them, but instead
copyin/copyout the whole array of structures.
Fixes PR 52864 for me (on sparc64).

diffstat:

 sys/modules/lua/lua.c |  24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (48 lines):

diff -r 90cb1b771b34 -r 10009041fe74 sys/modules/lua/lua.c
--- a/sys/modules/lua/lua.c     Tue Dec 26 11:40:47 2017 +0000
+++ b/sys/modules/lua/lua.c     Tue Dec 26 12:43:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lua.c,v 1.23 2017/05/20 09:46:17 mbalmer Exp $ */
+/*     $NetBSD: lua.c,v 1.24 2017/12/26 12:43:59 martin Exp $ */
 
 /*
  * Copyright (c) 2011 - 2017 by Marc Balmer <mbalmer%NetBSD.org@localhost>.
@@ -288,6 +288,7 @@
        struct pathbuf *pb;
        struct vattr va;
        struct lua_loadstate ls;
+       struct lua_state_info *states;
        int error, n;
        klua_State *K;
 
@@ -307,14 +308,25 @@
                        LIST_FOREACH(s, &lua_states, lua_next) {
                                if (n > info->num_states)
                                        break;
-                               copyoutstr(s->lua_name, info->states[n].name,
-                                   MAX_LUA_NAME, NULL);
-                               copyoutstr(s->lua_desc, info->states[n].desc,
-                                   MAX_LUA_DESC, NULL);
-                               info->states[n].user = s->K->ks_user;
                                n++;
                        }
                        info->num_states = n;
+                       states = kmem_alloc(sizeof(*states) * n, KM_SLEEP);
+                       if (copyin(info->states, states, sizeof(*states) * n)
+                           == 0) {
+                               n = 0;
+                               LIST_FOREACH(s, &lua_states, lua_next) {
+                                       if (n > info->num_states)
+                                               break;
+                                       strcpy(states[n].name, s->lua_name);
+                                       strcpy(states[n].desc, s->lua_desc);
+                                       states[n].user = s->K->ks_user;
+                                       n++;
+                               }
+                               copyout(states, info->states,
+                                   sizeof(*states) * n);
+                               kmem_free(states, sizeof(*states) * n);
+                       }
                }
                break;
        case LUACREATE:



Home | Main Index | Thread Index | Old Index