Subject: Re: bin/31377: ksh: cannot set limit indicated by ulimit -H
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, sjg@juniper.net>
From: Frederick Bruckman <fredb@immanent.net>
List: netbsd-bugs
Date: 10/09/2006 01:30:02
The following reply was made to PR bin/31377; it has been noted by GNATS.

From: Frederick Bruckman <fredb@immanent.net>
To: Simon Gerraty <sjg@juniper.net>
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/31377: ksh: cannot set limit indicated by ulimit -H
Date: Sun, 8 Oct 2006 19:05:06 -0500 (CDT)

 Hi,
 
 The problem seems to be that rlim_t is a "quad_t" (i.e., 64-bits), 
 while pdksh's evaluate() only works for "long" (which is, of course, 
 only 32-bits on i386). I suggest that the right fix is to "promote" 
 evaluate() to 64-bits, adjusting all of its callers, as below...
 
 Frederick
 
 
 Index: ./bin/ksh/c_ksh.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/c_ksh.c,v
 retrieving revision 1.15
 diff -u -r1.15 c_ksh.c
 --- ./bin/ksh/c_ksh.c	24 Apr 2006 20:00:31 -0000	1.15
 +++ ./bin/ksh/c_ksh.c	17 Sep 2006 19:39:01 -0000
 @@ -1083,7 +1083,7 @@
   	char **wp;
   {
   	int rv = 1;
 -	long val;
 +	int64_t val;
 
   	if (wp[1] == (char *) 0) /* at&t ksh does this */
   		bi_errorf("no arguments");
 Index: ./bin/ksh/c_sh.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/c_sh.c,v
 retrieving revision 1.12
 diff -u -r1.12 c_sh.c
 --- ./bin/ksh/c_sh.c	1 Apr 2006 23:39:58 -0000	1.12
 +++ ./bin/ksh/c_sh.c	17 Sep 2006 19:39:01 -0000
 @@ -32,7 +32,7 @@
   {
   	register struct block *l = e->loc;
   	register int n;
 -	long val;
 +	int64_t val;
   	char *arg;
 
   	if (ksh_getopt(wp, &builtin_opt, null) == '?')
 Index: ./bin/ksh/c_test.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/c_test.c,v
 retrieving revision 1.6
 diff -u -r1.6 c_test.c
 --- ./bin/ksh/c_test.c	26 Jun 2005 19:09:00 -0000	1.6
 +++ ./bin/ksh/c_test.c	17 Sep 2006 19:39:01 -0000
 @@ -369,7 +369,7 @@
   	  case TO_INTLE: /* -le */
   	  case TO_INTLT: /* -lt */
   		{
 -			long v1, v2;
 +			int64_t v1, v2;
 
   			if (!evaluate(opnd1, &v1, KSH_RETURN_ERROR)
   			    || !evaluate(opnd2, &v2, KSH_RETURN_ERROR))
 Index: ./bin/ksh/c_ulimit.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/c_ulimit.c,v
 retrieving revision 1.7
 diff -u -r1.7 c_ulimit.c
 --- ./bin/ksh/c_ulimit.c	7 Jul 2004 19:20:09 -0000	1.7
 +++ ./bin/ksh/c_ulimit.c	17 Sep 2006 19:39:01 -0000
 @@ -178,7 +178,7 @@
   		if (strcmp(wp[0], "unlimited") == 0)
   			val = KSH_RLIM_INFINITY;
   		else {
 -			long rval;
 +			rlim_t rval;
 
   			if (!evaluate(wp[0], &rval, KSH_RETURN_ERROR))
   				return 1;
 Index: ./bin/ksh/expr.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/expr.c,v
 retrieving revision 1.8
 diff -u -r1.8 expr.c
 --- ./bin/ksh/expr.c	26 Jun 2005 19:09:00 -0000	1.8
 +++ ./bin/ksh/expr.c	17 Sep 2006 19:39:01 -0000
 @@ -151,7 +151,7 @@
   int
   evaluate(expr, rval, error_ok)
   	const char *expr;
 -	long *rval;
 +	int64_t *rval;
   	int error_ok;
   {
   	struct tbl v;
 Index: ./bin/ksh/proto.h
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/proto.h,v
 retrieving revision 1.7
 diff -u -r1.7 proto.h
 --- ./bin/ksh/proto.h	26 Jun 2005 19:09:00 -0000	1.7
 +++ ./bin/ksh/proto.h	17 Sep 2006 19:39:01 -0000
 @@ -78,7 +78,7 @@
   int	pr_menu		ARGS((char *const *));
   int	pr_list		ARGS((char *const *));
   /* expr.c */
 -int 	evaluate	ARGS((const char *, long *, int));
 +int 	evaluate	ARGS((const char *, int64_t *, int));
   int	v_evaluate	ARGS((struct tbl *, const char *, volatile int));
   /* history.c */
   void	init_histvec	ARGS((void));
 Index: ./bin/ksh/var.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/var.c,v
 retrieving revision 1.14
 diff -u -r1.14 var.c
 --- ./bin/ksh/var.c	29 Mar 2006 15:51:00 -0000	1.14
 +++ ./bin/ksh/var.c	17 Sep 2006 19:39:02 -0000
 @@ -148,7 +148,7 @@
   	p = skip_varname(n, FALSE);
   	if (p != n && *p == '[' && (len = array_ref_len(p))) {
   		char *sub, *tmp;
 -		long rval;
 +		int64_t rval;
 
   		/* Calculate the value of the subscript */
   		*arrayp = TRUE;