Patch to fix behaviou when char is signed

it seems to me that there is still something wrong:

	1)  the new is_qdtext_char() is incorrect.
	There is a trap if char is implemented as signed char.
	Suppose that c is '\xFF', it will be -1 when converted to an int.
	By definition, c should be qdtext:
	qdtext = <any TEXT except <">>
	TEXT = <any OCTET except CTLs, but including LWS>
	OCTET = <any 8-bit sequence of data>

	2) the character after '\\' could be either part of a quoted-pair
	(together with '\\'), or a normal qdtext, since '\\' itself can
	be treated as a qdtext. This is equivalent to saying that the
	character after '\\' in a quoted string could be ANY octet.

	A patch based on the above two observations is attached.

	Peng
(cherry picked from commit f10730f616)
This commit is contained in:
Peng 2013-08-16 14:16:47 -03:00 committed by Marcelo Roberto Jimenez
parent 61d2950fa5
commit 8bcc4b41d1
2 changed files with 25 additions and 2 deletions

View File

@ -357,6 +357,29 @@ Version 1.8.0
Version 1.6.19
*******************************************************************************
2013-08-13 Peng <howtofly(at)gmail.com>
Patch to fix behaviou when char is signed
it seems to me that there is still something wrong:
1) the new is_qdtext_char() is incorrect.
There is a trap if char is implemented as signed char.
Suppose that c is '\xFF', it will be -1 when converted to an int.
By definition, c should be qdtext:
qdtext = <any TEXT except <">>
TEXT = <any OCTET except CTLs, but including LWS>
OCTET = <any 8-bit sequence of data>
2) the character after '\\' could be either part of a quoted-pair
(together with '\\'), or a normal qdtext, since '\\' itself can
be treated as a qdtext. This is equivalent to saying that the
character after '\\' in a quoted string could be ANY octet.
A patch based on the above two observations is attached.
Peng
2013-08-13 Marcelo Roberto Jimenez <mroberto(at)users.sourceforge.net>
Enforce RFC 2616 and accept "0" after a backslash for quoted-strings.

View File

@ -192,6 +192,7 @@ static UPNP_INLINE int is_qdtext_char(IN int c)
return
(c >= 32 && c != 127) ||
c < 0 ||
c == TOKCHAR_CR ||
c == TOKCHAR_LF ||
c == '\t';
@ -290,8 +291,7 @@ static parse_status_t scanner_get_token(
} else if (c == '\\') {
if (cursor < null_terminator) {
c = *cursor++;
if (c < 0 || c > 127)
return PARSE_FAILURE;
/* the char after '\\' could be ANY octet */
}
/* else, while loop handles incomplete buf */
} else if (is_qdtext_char(c)) {