Issue #217 - avoid len going negative, ever...

This commit is contained in:
Geoff McLane 2015-06-03 20:26:03 +02:00
parent 0fb7ccdfc6
commit c18f27a587

View file

@ -48,6 +48,7 @@
#endif #endif
#if !defined(NDEBUG) && defined(_MSC_VER) #if !defined(NDEBUG) && defined(_MSC_VER)
/* #define DEBUG_ALLOCATION special EXTRA allocation debug information - VERY NOISY */
static void check_me(char *name); static void check_me(char *name);
static Bool show_attrs = yes; static Bool show_attrs = yes;
#define MX_TXT 5 #define MX_TXT 5
@ -3739,16 +3740,17 @@ static tmbstr ParseValue( TidyDocImpl* doc, ctmbstr name,
/* and prompts attributes unless --literal-attributes is set to yes */ /* and prompts attributes unless --literal-attributes is set to yes */
/* #994841 - Whitespace is removed from value attributes */ /* #994841 - Whitespace is removed from value attributes */
if (munge && /* Issue #217 - Also only if/while (len > 0) - MUST NEVER GO NEGATIVE! */
if ((len > 0) && munge &&
TY_(tmbstrcasecmp)(name, "alt") && TY_(tmbstrcasecmp)(name, "alt") &&
TY_(tmbstrcasecmp)(name, "title") && TY_(tmbstrcasecmp)(name, "title") &&
TY_(tmbstrcasecmp)(name, "value") && TY_(tmbstrcasecmp)(name, "value") &&
TY_(tmbstrcasecmp)(name, "prompt")) TY_(tmbstrcasecmp)(name, "prompt"))
{ {
while (TY_(IsWhite)(lexer->lexbuf[start+len-1])) while (TY_(IsWhite)(lexer->lexbuf[start+len-1]) && (len > 0))
--len; --len;
while (TY_(IsWhite)(lexer->lexbuf[start]) && start < len) while (TY_(IsWhite)(lexer->lexbuf[start]) && (start < len) && (len > 0))
{ {
++start; ++start;
--len; --len;