dfilter: Fix parsing of octal character escape sequences

Octal escape sequences \NNN can have between 1 and 3 digits. If
the sequence had less than 3 digits the parser got out of sync
with an incorrect double increment of the pointer and errors out
parsing sequences like \0, \2 or \33.

Before:
  Filter: ip.proto == '\33'
  dftest: "'\33'" is too long to be a valid character constant.

After:
  Filter: ip.proto == '\33'

  Constants:
  00000 PUT_FVALUE	27 <FT_UINT8> -> reg#1

  Instructions:
  00000 READ_TREE		ip.proto -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_EQ		reg#0 == reg#1
  00003 RETURN

Fixes #16525.
This commit is contained in:
João Valverde 2021-10-07 19:05:41 +01:00 committed by Wireshark GitLab Utility
parent 0eda51a646
commit 9dab2280ca
1 changed files with 10 additions and 5 deletions

View File

@ -57,7 +57,11 @@ parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg)
cp = s + 1; /* skip the leading ' */
if (*cp == '\\') {
/*
* Escape.
* C escape sequence.
* An escape sequence is an octal number \NNN,
* an hex number \xNN, or one of \' \" \? \\ \a \b \f \n \r
* \t \v that stands for the byte value of the equivalent
* C-escape in ASCII encoding.
*/
cp++;
switch (*cp) {
@ -138,6 +142,7 @@ parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg)
break;
default:
/* Octal */
if (*cp >= '0' && *cp <= '7')
value = *cp - '0';
else {
@ -145,8 +150,8 @@ parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg)
*err_msg = g_strdup_printf("\"%s\" isn't a valid character constant.", s);
return FALSE;
}
cp++;
if (*cp != '\'') {
if (*(cp + 1) != '\'') {
cp++;
value <<= 3;
if (*cp >= '0' && *cp <= '7')
value |= *cp - '0';
@ -155,8 +160,8 @@ parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg)
*err_msg = g_strdup_printf("\"%s\" isn't a valid character constant.", s);
return FALSE;
}
cp++;
if (*cp != '\'') {
if (*(cp + 1) != '\'') {
cp++;
value <<= 3;
if (*cp >= '0' && *cp <= '7')
value |= *cp - '0';