]> Savannah Git Hosting - gnulib.git/commitdiff
modechange: avoid memory leaks for invalid octal modes
authorBernhard Voelker <mail@bernhard-voelker.de>
Wed, 26 Mar 2014 00:42:11 +0000 (01:42 +0100)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 26 Mar 2014 01:25:27 +0000 (18:25 -0700)
* lib/modechange.c (mode_compile): During the parsing of
notations like +40, free the 'mc' buffer for invalid mode
strings like +17777 (greater than the maximum octal mode),
=18 (bad octal mode characters) or u=1 ('affected' with
octal modes).
Reproducer, e.g.:

    $ valgrind --leak-check=full chmod +17777 file

Introduced via the 2012-03-09 commit, 4730c3e3, "modechange:
add notations +40, 00440, etc.".
Spotted by coverity (RESOURCE_LEAK).

ChangeLog
lib/modechange.c

index 8fa880d0a7cb2c00c2f23f494d965e805f0253f4..30b364b119fea6e42f93329842bdff9141beb2f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2014-03-26  Bernhard Voelker  <mail@bernhard-voelker.de>
+
+       modechange: avoid memory leaks for invalid octal modes
+       * lib/modechange.c (mode_compile): During the parsing of
+       notations like +40, free the 'mc' buffer for invalid mode
+       strings like +17777 (greater than the maximum octal mode),
+       =18 (bad octal mode characters) or u=1 ('affected' with
+       octal modes).
+       Reproducer, e.g.:
+           $ valgrind --leak-check=full chmod +17777 file
+       Introduced via the 2012-03-09 commit, 4730c3e3, "modechange:
+       add notations +40, 00440, etc.".
+       Spotted by coverity (RESOURCE_LEAK).
+
 2014-03-24  Paul Eggert  <eggert@cs.ucla.edu>
 
        gitlog-to-changelog: include a dummy git-log-fix file
index 8ac18799f8091534900d3ae25721ca8e42f2dba8..412fe1d27fef07f93985d83f9d62cf4cba41456c 100644 (file)
@@ -220,12 +220,12 @@ mode_compile (char const *mode_string)
                   {
                     octal_mode = 8 * octal_mode + *p++ - '0';
                     if (ALLM < octal_mode)
-                      return NULL;
+                      goto invalid;
                   }
                 while ('0' <= *p && *p < '8');
 
                 if (affected || (*p && *p != ','))
-                  return NULL;
+                  goto invalid;
                 affected = mentioned = CHMOD_MODE_BITS;
                 value = octal_to_mode (octal_mode);
                 flag = MODE_ORDINARY_CHANGE;