]> granicus.if.org Git - postgresql/commitdiff
Avoid reading below the start of a stack variable in tokenize_file().
authorNoah Misch <noah@leadboat.com>
Wed, 12 Jun 2013 23:50:52 +0000 (19:50 -0400)
committerNoah Misch <noah@leadboat.com>
Wed, 12 Jun 2013 23:50:52 +0000 (19:50 -0400)
We would wrongly overwrite the prior stack byte if it happened to
contain '\n' or '\r'.  New in 9.3, so no back-patch.

src/backend/libpq/hba.c

index e946a4659f29e470875f5e09bbcdff42f70b7830..91f6ced0d2f526836b15fa3bcb877a920f2f813c 100644 (file)
@@ -411,9 +411,9 @@ tokenize_file(const char *filename, FILE *file,
                                                                line_number, filename)));
 
                /* Strip trailing linebreak from rawline */
-               while (rawline[strlen(rawline) - 1] == '\n' ||
-                          rawline[strlen(rawline) - 1] == '\r')
-                       rawline[strlen(rawline) - 1] = '\0';
+               lineptr = rawline + strlen(rawline) - 1;
+               while (lineptr >= rawline && (*lineptr == '\n' || *lineptr == '\r'))
+                       *lineptr-- = '\0';
 
                lineptr = rawline;
                while (strlen(lineptr) > 0)