]> granicus.if.org Git - python/commitdiff
Patch #1357836:
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 2 Jun 2006 06:23:00 +0000 (06:23 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 2 Jun 2006 06:23:00 +0000 (06:23 +0000)
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered.  I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.

This code looks like it should be refactored.

Backport candidate (also the early break above if decoding_fgets fails)

Parser/tokenizer.c

index 4a281050be3d5bd2c897ce90eedeb8345b8eb22c..92c2087262e74ac4073f69573d9e7ced4fea11f9 100644 (file)
@@ -893,15 +893,17 @@ tok_nextc(register struct tok_state *tok)
                                tok->inp = strchr(tok->inp, '\0');
                                done = tok->inp[-1] == '\n';
                        }
-                       tok->cur = tok->buf + cur;
-                       tok->line_start = tok->cur;
-                       /* replace "\r\n" with "\n" */
-                       /* For Mac we leave the \r, giving a syntax error */
-                       pt = tok->inp - 2;
-                       if (pt >= tok->buf && *pt == '\r') {
-                               *pt++ = '\n';
-                               *pt = '\0';
-                               tok->inp = pt;
+                       if (tok->buf != NULL) {
+                               tok->cur = tok->buf + cur;
+                               tok->line_start = tok->cur;
+                               /* replace "\r\n" with "\n" */
+                               /* For Mac leave the \r, giving syntax error */
+                               pt = tok->inp - 2;
+                               if (pt >= tok->buf && *pt == '\r') {
+                                       *pt++ = '\n';
+                                       *pt = '\0';
+                                       tok->inp = pt;
+                               }
                        }
                }
                if (tok->done != E_OK) {