mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-30 17:50:58 +01:00
36559: test earlier for overflow in pattern range
This commit is contained in:
parent
cc44b10da1
commit
df0d86b847
3 changed files with 28 additions and 5 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
2015-09-19 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2015-09-19 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 36559: Src/pattern.c: test earlier for overflow in pattern
|
||||||
|
range.
|
||||||
|
|
||||||
* unposted: Test/D07multibyte.ztst: fix typo.
|
* unposted: Test/D07multibyte.ztst: fix typo.
|
||||||
|
|
||||||
2015-09-18 Barton E. Schaefer <schaefer@zsh.org>
|
2015-09-18 Barton E. Schaefer <schaefer@zsh.org>
|
||||||
|
|
|
||||||
|
|
@ -220,8 +220,10 @@ typedef union upat *Upat;
|
||||||
#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
|
#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
|
||||||
typedef zlong zrange_t;
|
typedef zlong zrange_t;
|
||||||
#define ZRANGE_T_IS_SIGNED (1)
|
#define ZRANGE_T_IS_SIGNED (1)
|
||||||
|
#define ZRANGE_MAX ZLONG_MAX
|
||||||
#else
|
#else
|
||||||
typedef unsigned long zrange_t;
|
typedef unsigned long zrange_t;
|
||||||
|
#define ZRANGE_MAX ULONG_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MULTIBYTE_SUPPORT
|
#ifdef MULTIBYTE_SUPPORT
|
||||||
|
|
@ -2641,19 +2643,30 @@ patmatch(Upat prog)
|
||||||
start = compend = patinput;
|
start = compend = patinput;
|
||||||
comp = 0;
|
comp = 0;
|
||||||
while (patinput < patinend && idigit(*patinput)) {
|
while (patinput < patinend && idigit(*patinput)) {
|
||||||
if (comp)
|
int out_of_range = 0;
|
||||||
comp *= 10;
|
int digit = *patinput - '0';
|
||||||
comp += *patinput - '0';
|
if (comp > ZRANGE_MAX / (zlong)10) {
|
||||||
|
out_of_range = 1;
|
||||||
|
} else {
|
||||||
|
zrange_t c10 = comp ? comp * 10 : 0;
|
||||||
|
if (ZRANGE_MAX - c10 < digit) {
|
||||||
|
out_of_range = 1;
|
||||||
|
} else {
|
||||||
|
comp = c10;
|
||||||
|
comp += digit;
|
||||||
|
}
|
||||||
|
}
|
||||||
patinput++;
|
patinput++;
|
||||||
compend++;
|
compend++;
|
||||||
|
|
||||||
if (comp & ((zrange_t)1 << (sizeof(comp)*8 -
|
if (out_of_range ||
|
||||||
|
(comp & ((zrange_t)1 << (sizeof(comp)*8 -
|
||||||
#ifdef ZRANGE_T_IS_SIGNED
|
#ifdef ZRANGE_T_IS_SIGNED
|
||||||
2
|
2
|
||||||
#else
|
#else
|
||||||
1
|
1
|
||||||
#endif
|
#endif
|
||||||
))) {
|
)))) {
|
||||||
/*
|
/*
|
||||||
* Out of range (allowing for signedness, which
|
* Out of range (allowing for signedness, which
|
||||||
* we need if we are using zlongs).
|
* we need if we are using zlongs).
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@
|
||||||
*/
|
*/
|
||||||
#ifdef ZSH_64_BIT_TYPE
|
#ifdef ZSH_64_BIT_TYPE
|
||||||
typedef ZSH_64_BIT_TYPE zlong;
|
typedef ZSH_64_BIT_TYPE zlong;
|
||||||
|
#if defind(ZLONG_IS_LONG_LONG) && defined(LLONG_MAX)
|
||||||
|
#define ZLONG_MAX LLONG_MAX
|
||||||
|
#else
|
||||||
|
/* umm... */
|
||||||
|
#define ZLONG_MAX ((zlong)9223372036854775807)
|
||||||
|
#endif
|
||||||
#ifdef ZSH_64_BIT_UTYPE
|
#ifdef ZSH_64_BIT_UTYPE
|
||||||
typedef ZSH_64_BIT_UTYPE zulong;
|
typedef ZSH_64_BIT_UTYPE zulong;
|
||||||
#else
|
#else
|
||||||
|
|
@ -44,6 +50,7 @@ typedef unsigned zlong zulong;
|
||||||
#else
|
#else
|
||||||
typedef long zlong;
|
typedef long zlong;
|
||||||
typedef unsigned long zulong;
|
typedef unsigned long zulong;
|
||||||
|
#define ZLONG_MAX LONG_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue