Fixed a few quirks in misc.c

. MAX used where it should've been MIN
  . buffer byte too short
  . inobvious use of & with && without parantheses
  . funny length checking
This commit is contained in:
Ben Gras 2005-06-20 09:35:23 +00:00
parent 5e17902a0d
commit c9c6983cc1

View file

@ -92,18 +92,18 @@ PUBLIC int do_getsysinfo()
PUBLIC int do_getprocnr() PUBLIC int do_getprocnr()
{ {
register struct mproc *rmp; register struct mproc *rmp;
static char search_key[PROC_NAME_LEN]; static char search_key[PROC_NAME_LEN+1];
int key_len; int key_len;
int s; int s;
if (m_in.namelen > 0) { /* lookup process by name */ if (m_in.namelen > 0) { /* lookup process by name */
key_len = MAX(m_in.namelen, PROC_NAME_LEN); key_len = MIN(m_in.namelen, PROC_NAME_LEN);
if (OK != (s=sys_datacopy(who, (vir_bytes) m_in.addr, if (OK != (s=sys_datacopy(who, (vir_bytes) m_in.addr,
SELF, (vir_bytes) search_key, key_len))) SELF, (vir_bytes) search_key, key_len)))
return(s); return(s);
search_key[key_len] = '\0'; /* terminate for safety */ search_key[key_len] = '\0'; /* terminate for safety */
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if (rmp->mp_flags & IN_USE && if ((rmp->mp_flags & IN_USE) &&
strncmp(rmp->mp_name, search_key, key_len)==0) { strncmp(rmp->mp_name, search_key, key_len)==0) {
mp->mp_reply.procnr = (int) (rmp - mproc); mp->mp_reply.procnr = (int) (rmp - mproc);
return(OK); return(OK);
@ -210,14 +210,17 @@ PUBLIC int do_svrctl()
val_len = strlen(val_start) + 1; val_len = strlen(val_start) + 1;
} }
/* See if it fits in the client's buffer. */
if (val_len > sysgetenv.vallen)
return E2BIG;
/* Value found, make the actual copy (as far as possible). */ /* Value found, make the actual copy (as far as possible). */
copy_len = MAX(val_len, sysgetenv.vallen); copy_len = MIN(val_len, sysgetenv.vallen);
if ((s=sys_datacopy(SELF, (vir_bytes) val_start, if ((s=sys_datacopy(SELF, (vir_bytes) val_start,
who, (vir_bytes) sysgetenv.val, copy_len)) != OK) who, (vir_bytes) sysgetenv.val, copy_len)) != OK)
return(s); return(s);
/* See if it fits in the client's buffer. */ return OK;
return (copy_len > sysgetenv.vallen) ? E2BIG : OK;
} }
case MMSIGNON: { case MMSIGNON: {
/* A user process becomes a task. Simulate an exit by /* A user process becomes a task. Simulate an exit by
@ -243,7 +246,7 @@ PUBLIC int do_svrctl()
/* Disinherit children. */ /* Disinherit children. */
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if (rmp->mp_flags & IN_USE && rmp->mp_parent == who) { if ((rmp->mp_flags & IN_USE) && rmp->mp_parent == who) {
rmp->mp_parent = INIT_PROC_NR; rmp->mp_parent = INIT_PROC_NR;
} }
} }