add some bounds, for a subsequent commit:
• all writers of exstat ensure the value is in [0; 0xFF] • all readers of exstat AND it with 0xFF (not strictly needed thus) • trap_exstat is “safe”, i.e. always either -1 or [0; 0xFF]
This commit is contained in:
parent
bebb2d2254
commit
31f24a4040
10
exec.c
10
exec.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.102 2012/10/21 21:26:39 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.103 2012/10/21 21:39:01 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||
@ -464,7 +464,7 @@ execute(struct op * volatile t,
|
||||
errorf("%s: %s", s, strerror(rv));
|
||||
}
|
||||
Break:
|
||||
exstat = rv;
|
||||
exstat = rv & 0xFF;
|
||||
if (vp_pipest->flag & INT_L) {
|
||||
unset(vp_pipest, 1);
|
||||
vp_pipest->flag = DEFINED | ISSET | INTEGER | RDONLY |
|
||||
@ -741,7 +741,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
e->type = E_FUNC;
|
||||
if (!(i = kshsetjmp(e->jbuf))) {
|
||||
/* seems odd to pass XERROK here, but AT&T ksh does */
|
||||
exstat = execute(tp->val.t, flags & XERROK, xerrok);
|
||||
exstat = execute(tp->val.t, flags & XERROK, xerrok) & 0xFF;
|
||||
i = LRETURN;
|
||||
}
|
||||
kshname = old_kshname;
|
||||
@ -762,7 +762,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
switch (i) {
|
||||
case LRETURN:
|
||||
case LERROR:
|
||||
rv = exstat;
|
||||
rv = exstat & 0xFF;
|
||||
break;
|
||||
case LINTR:
|
||||
case LEXIT:
|
||||
@ -822,7 +822,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
}
|
||||
Leave:
|
||||
if (flags & XEXEC) {
|
||||
exstat = rv;
|
||||
exstat = rv & 0xFF;
|
||||
unwind(LLEAVE);
|
||||
}
|
||||
return (rv);
|
||||
|
4
funcs.c
4
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.226 2012/10/03 17:24:19 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.227 2012/10/21 21:39:02 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -2280,7 +2280,7 @@ c_exitreturn(const char **wp)
|
||||
exstat = 1;
|
||||
warningf(true, "%s: %s", arg, "bad number");
|
||||
} else
|
||||
exstat = n;
|
||||
exstat = n & 0xFF;
|
||||
} else if (trap_exstat != -1)
|
||||
exstat = trap_exstat;
|
||||
if (wp[0][0] == 'r') {
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.126 2012/06/24 19:47:11 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.127 2012/10/21 21:39:03 tg Exp $");
|
||||
|
||||
Trap sigtraps[NSIG + 1];
|
||||
static struct sigaction Sigact_ign;
|
||||
@ -1224,12 +1224,12 @@ runtrap(Trap *p, bool is_last)
|
||||
/* SIG_DFL */
|
||||
if (p->flags & TF_FATAL) {
|
||||
/* eg, SIGHUP */
|
||||
exstat = 128 + i;
|
||||
exstat = (int)ksh_min(128U + (unsigned)i, 255U);
|
||||
unwind(LLEAVE);
|
||||
}
|
||||
if (p->flags & TF_DFL_INTR) {
|
||||
/* eg, SIGINT, SIGQUIT, SIGTERM, etc. */
|
||||
exstat = 128 + i;
|
||||
exstat = (int)ksh_min(128U + (unsigned)i, 255U);
|
||||
unwind(LINTR);
|
||||
}
|
||||
goto donetrap;
|
||||
@ -1244,7 +1244,7 @@ runtrap(Trap *p, bool is_last)
|
||||
p->trap = NULL;
|
||||
}
|
||||
if (trap_exstat == -1)
|
||||
trap_exstat = exstat;
|
||||
trap_exstat = exstat & 0xFF;
|
||||
/*
|
||||
* Note: trapstr is fully parsed before anything is executed, thus
|
||||
* no problem with afree(p->trap) in settrap() while still in use.
|
||||
|
12
main.c
12
main.c
@ -34,7 +34,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.230 2012/10/21 21:26:40 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.231 2012/10/21 21:39:04 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -711,7 +711,7 @@ include(const char *name, int argc, const char **argv, int intr_ok)
|
||||
* intr_ok is set if we are including .profile or $ENV.
|
||||
* If user ^Cs out, we don't want to kill the shell...
|
||||
*/
|
||||
if (intr_ok && (exstat - 128) != SIGTERM)
|
||||
if (intr_ok && ((exstat & 0xFF) - 128) != SIGTERM)
|
||||
return (1);
|
||||
/* FALLTHROUGH */
|
||||
case LEXIT:
|
||||
@ -855,7 +855,7 @@ shell(Source * volatile s, volatile bool toplevel)
|
||||
t->u.evalflags |= DOTCOMEXEC;
|
||||
#endif
|
||||
if (!Flag(FNOEXEC) || (s->flags & SF_TTY))
|
||||
exstat = execute(t, 0, NULL);
|
||||
exstat = execute(t, 0, NULL) & 0xFF;
|
||||
|
||||
if (t->type != TEOF && interactive && really_exit)
|
||||
really_exit = false;
|
||||
@ -865,7 +865,7 @@ shell(Source * volatile s, volatile bool toplevel)
|
||||
}
|
||||
quitenv(NULL);
|
||||
source = old_source;
|
||||
return (exstat);
|
||||
return (exstat & 0xFF);
|
||||
}
|
||||
|
||||
/* return to closest error handler or shell(), exit if none found */
|
||||
@ -961,7 +961,7 @@ quitenv(struct shf *shf)
|
||||
#endif
|
||||
j_exit();
|
||||
if (ep->flags & EF_FAKE_SIGDIE) {
|
||||
int sig = exstat - 128;
|
||||
int sig = (exstat & 0xFF) - 128;
|
||||
|
||||
/*
|
||||
* ham up our death a bit (AT&T ksh
|
||||
@ -980,7 +980,7 @@ quitenv(struct shf *shf)
|
||||
if (shf)
|
||||
shf_close(shf);
|
||||
reclaim();
|
||||
exit(exstat);
|
||||
exit(exstat & 0xFF);
|
||||
}
|
||||
if (shf)
|
||||
shf_close(shf);
|
||||
|
4
sh.h
4
sh.h
@ -157,7 +157,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.593 2012/10/21 21:26:41 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.594 2012/10/21 21:39:05 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R40 2012/10/03"
|
||||
|
||||
@ -293,6 +293,8 @@ struct rusage {
|
||||
#define ksh_toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
|
||||
#define ksh_isdash(s) (((s) != NULL) && ((s)[0] == '-') && ((s)[1] == '\0'))
|
||||
#define ksh_isspace(c) ((((c) >= 0x09) && ((c) <= 0x0D)) || ((c) == 0x20))
|
||||
#define ksh_min(x,y) ((x) < (y) ? (x) : (y))
|
||||
#define ksh_max(x,y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
#ifdef MKSH__NO_PATH_MAX
|
||||
#undef PATH_MAX
|
||||
|
4
var.c
4
var.c
@ -27,7 +27,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.153 2012/07/30 21:37:17 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.154 2012/10/21 21:39:06 tg Exp $");
|
||||
|
||||
/*-
|
||||
* Variables
|
||||
@ -260,7 +260,7 @@ global(const char *n)
|
||||
vp->flag &= ~(ISSET|INTEGER);
|
||||
break;
|
||||
case '?':
|
||||
vp->val.i = exstat;
|
||||
vp->val.i = exstat & 0xFF;
|
||||
break;
|
||||
case '#':
|
||||
vp->val.i = l->argc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user