diff options
author | Georg Brandl <georg@python.org> | 2008-01-19 19:27:05 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-19 19:27:05 (GMT) |
commit | 14404b68d8c5a501a2f5ee6f45494865b7b38276 (patch) | |
tree | f1db16ee7f39d81414ad24bd682e9df61b74e4dd /Python/mystrtoul.c | |
parent | 2686f4d9d14e2b30a61e5350dcb4a56c43c82b57 (diff) | |
download | cpython-14404b68d8c5a501a2f5ee6f45494865b7b38276.zip cpython-14404b68d8c5a501a2f5ee6f45494865b7b38276.tar.gz cpython-14404b68d8c5a501a2f5ee6f45494865b7b38276.tar.bz2 |
Fix #1679: "0x" was taken as a valid integer literal.
Fixes the tokenizer, tokenize.py and int() to reject this.
Patches by Malte Helmert.
Diffstat (limited to 'Python/mystrtoul.c')
-rw-r--r-- | Python/mystrtoul.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c index f007057..a02992f 100644 --- a/Python/mystrtoul.c +++ b/Python/mystrtoul.c @@ -112,27 +112,40 @@ PyOS_strtoul(register char *str, char **ptr, int base) /* check for leading 0 or 0x for auto-base or base 16 */ switch (base) { - case 0: /* look for leading 0, 0x or 0X */ - if (*str == '0') { - ++str; - if (*str == 'x' || *str == 'X') { - ++str; - base = 16; + case 0: /* look for leading 0, 0x or 0X */ + if (*str == '0') { + ++str; + if (*str == 'x' || *str == 'X') { + /* there must be at least one digit after 0x */ + if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) { + if (ptr) + *ptr = str; + return 0; } - else - base = 8; + ++str; + base = 16; } else - base = 10; - break; + base = 8; + } + else + base = 10; + break; - case 16: /* skip leading 0x or 0X */ - if (*str == '0') { + case 16: /* skip leading 0x or 0X */ + if (*str == '0') { + ++str; + if (*str == 'x' || *str == 'X') { + /* there must be at least one digit after 0x */ + if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) { + if (ptr) + *ptr = str; + return 0; + } ++str; - if (*str == 'x' || *str == 'X') - ++str; } - break; + } + break; } /* catch silly bases */ |