diff options
Diffstat (limited to 'bin/ksh/c_ulimit.c')
-rw-r--r-- | bin/ksh/c_ulimit.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/bin/ksh/c_ulimit.c b/bin/ksh/c_ulimit.c index deb26986fc8..153e68d0f79 100644 --- a/bin/ksh/c_ulimit.c +++ b/bin/ksh/c_ulimit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ulimit.c,v 1.4 1998/01/17 19:00:44 millert Exp $ */ +/* $OpenBSD: c_ulimit.c,v 1.5 1998/10/29 04:09:20 millert Exp $ */ /* ulimit -- handle "ulimit" builtin @@ -34,6 +34,12 @@ extern long ulimit(); #define SOFT 0x1 #define HARD 0x2 +#ifdef RLIM_INFINITY +# define KSH_RLIM_INFINITY RLIM_INFINITY +#else +# define KSH_RLIM_INFINITY ((rlim_t) 1 << (sizeof(rlim_t) * 8 - 1) - 1) +#endif /* RLIM_INFINITY */ + int c_ulimit(wp) char **wp; @@ -156,25 +162,28 @@ c_ulimit(wp) wp += builtin_opt.optind; set = *wp ? 1 : 0; if (set) { - char *p = *wp; - if (all || wp[1]) { bi_errorf("too many arguments"); return 1; } -#ifdef RLIM_INFINITY - if (strcmp(p, "unlimited") == 0) - val = RLIM_INFINITY; - else -#endif /* RLIM_INFINITY */ - if (!isdigit(*p)) { - bi_errorf("\"%s\" is not a valid limit", p); - return 1; - } else { + if (strcmp(wp[0], "unlimited") == 0) + val = KSH_RLIM_INFINITY; + else { long rval; - if (!evaluate(p, &rval, TRUE)) + if (!evaluate(wp[0], &rval, TRUE)) return 1; + /* Avoid problems caused by typos that + * evaluate misses due to evaluating unset + * parameters to 0... + * If this causes problems, will have to + * add parameter to evaluate() to control + * if unset params are 0 or an error. + */ + if (!rval && !digit(wp[0][0])) { + bi_errorf("invalid limit: %s", wp[0]); + return 1; + } val = rval * l->factor; } } |