bug-coreutils
[Top][All Lists]
Advanced

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

modechange.c off-by-1 bug


From: Paul Eggert
Subject: modechange.c off-by-1 bug
Date: Fri, 24 Sep 2004 00:04:30 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

modechange.c decrements a pointer past the start of the string,
which is theoretically a no-no.  I installed this:

2004-09-23  Paul Eggert  <address@hidden>

        * lib/modechange.c (mode_compile): Don't decrement a pointer that
        points to the start of a string, as the C Standard says the
        resulting behavior is undefined.

--- lib/modechange.c    30 Jul 2004 04:06:16 -0000      1.27
+++ lib/modechange.c    24 Sep 2004 07:00:59 -0000      1.28
@@ -211,10 +211,9 @@ mode_compile (const char *mode_string, u
 
   umask_value = umask (0);
   umask (umask_value);         /* Restore the old value. */
-  --mode_string;
 
   /* One loop iteration for each "ugoa...=+-rwxXstugo...[=+-rwxXstugo...]". */
-  do
+  for (;; mode_string++)
     {
       /* Which bits in the mode are operated on. */
       mode_t affected_bits = 0;
@@ -226,7 +225,7 @@ mode_compile (const char *mode_string, u
       bool who_specified_p;
 
       /* Turn on all the bits in `affected_bits' for each group given. */
-      for (++mode_string;; ++mode_string)
+      for (;; mode_string++)
        switch (*mode_string)
          {
          case 'u':
@@ -349,7 +348,11 @@ mode_compile (const char *mode_string, u
              }
        no_more_values:;
        }
-  } while (*mode_string == ',');
+
+      if (*mode_string != ',')
+       break;
+    }
+
   if (*mode_string == 0)
     return head;
 invalid:




reply via email to

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