bug-bash
[Top][All Lists]
Advanced

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

bash 2.05 fixes for undesirable truncation in long->string conversion


From: Paul Eggert
Subject: bash 2.05 fixes for undesirable truncation in long->string conversion
Date: Fri, 13 Apr 2001 00:34:32 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' 
-DCONF_VENDOR='sun' -DSHELL  -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
-I/opt/reb/include -g -O2 -Wall
uname output: SunOS shade.twinsun.com 5.8 Generic_108528-06 sun4u sparc 
SUNW,Ultra-1
Machine Type: sparc-sun-solaris2.8

Bash Version: 2.05
Patch Level: 0
Release Status: release

Description:
        In several places, Bash 2.05 truncates to int before
        converting to a string.  This loses information when the value
        being converted is wider than int (e.g. 64-bit Solaris 8
        'long').  For example, expr.c's expassign passes a 'long' to
        itos, but itos accepts an arg of type int, and hence the
        result of the computation is arbitrarily and incorrectly
        truncated to 'int' range.

Repeat-By:

Fix:

2001-04-13  Paul Eggert  <address@hidden>

        Convert long values to string without truncating to 'int' first.

        * externs.h (itos): Take long arg, not int.
        (inttostr): Likewise.  Also take size_t arg, not int.
        * expr.c (itos): Likewise.
        * lib/sh/itos.c (inttostr, itos): Likewise.
        (inttostr): Handle the case of the minimum possible int
        correctly, even on weird hosts with padding.

        * subst.c (parameter_brace_expand_length, param_expand):
        Do not truncate pid values that do not fit in int.
        * lib/malloc/malloc.c (trace_malloc_stats): Likewise.
        * variables.c (set_ppid): Likewise.
        Do not truncate pid values that do not fit in int.
        (get_seconds): Do not truncate seconds_value_assigned to int.
        (get_random): Remove redundant cast to int.

        * general.c (get_group_list):
        Do not truncate gid values that do not fit in int.

===================================================================
RCS file: externs.h,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- externs.h   2000/11/03 16:25:31     2.5
+++ externs.h   2001/04/13 07:08:33     2.5.0.1
@@ -122,8 +122,8 @@ extern char *getcwd __P((char *, size_t)
 #endif
 
 /* Declarations for functions defined in lib/sh/itos.c */
-extern char *inttostr __P((int, char *, int));
-extern char *itos __P((int));
+extern char *inttostr __P((long, char *, size_t));
+extern char *itos __P((long));
 
 /* declarations for functions defined in lib/sh/makepath.c */
 #define MP_DOTILDE     0x01
===================================================================
RCS file: expr.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- expr.c      2001/02/14 21:58:32     2.5
+++ expr.c      2001/04/13 07:08:33     2.5.0.1
@@ -1155,7 +1155,7 @@ builtin_error (format, arg1, arg2, arg3,
 
 char *
 itos (n)
-     int n;
+     long n;
 {
   return ("42");
 }
===================================================================
RCS file: lib/sh/itos.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/sh/itos.c       1999/08/05 12:21:11     2.5
+++ lib/sh/itos.c       2001/04/13 07:08:33     2.5.0.1
@@ -36,21 +36,15 @@
    does not. */
 char *
 inttostr (i, buf, len)
-     int i;
+     long i;
      char *buf;
-     int len;
+     size_t len;
 {
   char *p;
-  int negative = 0;
-  unsigned int ui;
+  unsigned long ui = i;
 
   if (i < 0)
-    {
-      negative++;
-      i = -i;
-    }
-
-  ui = (unsigned int) i;
+    ui = -ui;
 
   p = buf + len - 2;
   p[1] = '\0';
@@ -59,7 +53,7 @@ inttostr (i, buf, len)
     *p-- = (ui % 10) + '0';
   while (ui /= 10);
 
-  if (negative)
+  if (i < 0)
     *p-- = '-';
 
   return (p + 1);
@@ -69,7 +63,7 @@ inttostr (i, buf, len)
    caller should free it. */
 char *
 itos (i)
-     int i;
+     long i;
 {
   char *p, lbuf[MAX_INT_LEN];
 
===================================================================
RCS file: subst.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- subst.c     2001/03/26 18:06:16     2.5
+++ subst.c     2001/04/13 07:08:33     2.5.0.1
@@ -4095,7 +4095,7 @@ parameter_brace_expand_length (name)
          if (last_asynchronous_pid == NO_PID)
            t = (char *)NULL;
          else
-           t = itos ((int)last_asynchronous_pid);
+           t = itos (last_asynchronous_pid);
          break;
        case '#':
          t = itos (number_of_args ());
@@ -5046,7 +5046,7 @@ param_expand (string, sindex, quoted, ex
            }
        }
       else
-       temp = itos ((int)last_asynchronous_pid);
+       temp = itos (last_asynchronous_pid);
       break;
 
     /* The only difference between this and $@ is when the arg is quoted. */
===================================================================
RCS file: lib/malloc/malloc.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/malloc/malloc.c 2001/02/14 22:01:50     2.5
+++ lib/malloc/malloc.c 2001/04/13 07:08:33     2.5.0.1
@@ -963,10 +963,10 @@ trace_malloc_stats (s)
 {
   char ibuf[32], *ip;
   char fname[64];
-  int p;
+  long p;
   FILE *fp;
 
-  p = (int)getpid();
+  p = getpid ();
   ip = inttostr(p, ibuf, sizeof(ibuf));
   strcpy (fname, TRACEROOT);
   strcat (fname, ip);
===================================================================
RCS file: variables.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- variables.c 2001/02/21 18:47:11     2.5
+++ variables.c 2001/04/13 07:08:33     2.5.0.1
@@ -616,7 +616,7 @@ set_ppid ()
   char namebuf[32], *name;
   SHELL_VAR *temp_var;
 
-  name = inttostr ((int) getppid (), namebuf, sizeof(namebuf));
+  name = inttostr (getppid (), namebuf, sizeof (namebuf));
   temp_var = find_variable ("PPID");
   if (temp_var)
     VUNSETATTR (temp_var, (att_readonly | att_exported));
@@ -1002,7 +1002,7 @@ get_seconds (var)
   char *p;
 
   time_since_start = NOW - shell_start_time;
-  p = itos((int) seconds_value_assigned + time_since_start);
+  p = itos (seconds_value_assigned + time_since_start);
 
   FREE (var->value);
 
@@ -1069,7 +1069,7 @@ get_random (var)
 
   rv = get_random_number ();
   last_random_value = rv;
-  p = itos ((int)rv);
+  p = itos (rv);
 
   FREE (var->value);
 
===================================================================
RCS file: general.c,v
retrieving revision 2.5.0.1
retrieving revision 2.5.0.2
diff -pu -r2.5.0.1 -r2.5.0.2
--- general.c   2001/04/11 05:56:29     2.5.0.1
+++ general.c   2001/04/13 07:08:33     2.5.0.2
@@ -793,7 +793,7 @@ get_group_list (ngp)
   group_vector = alloc_array (ngroups);
   for (i = 0; i < ngroups; i++)
     {
-      nbuf = itos ((int)group_array[i]);
+      nbuf = itos (group_array[i]);
       group_vector[i] = nbuf;
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]