Mladen Turk wrote:
Rainer Jung wrote:
Yes Mladen, I know. But we never really use len :) I know, that we can
do it with memcmp, but then you, me or someone else has to add a
couple of if(len>=...) before each memcmp(). Go ahead if you like to.
Look, we have a local header[16] on which we copy toupper, and there is no
chance for overflow. Like said, we can test for "xxx\0" and that'll be
fine.
Good, I didn't notice, that the header names are actually in a constant
size array.
OK, but then why don't we simply add 1 to all sizes used in the memcmp?
I think we don't need to add "\0" to the constant values, because the
string constants are automatically null terminated. Am I correct?
So the realy patch would be simply:
@@ -260,18 +260,20 @@
header[i] = '\0';
p = &header[1];
+ /* Always do memcmp including the final \0-termination character.
+ */
switch (header[0]) {
case 'A':
- if (memcmp(p, "CCEPT", 5) == 0) {
+ if (memcmp(p, "CCEPT", 6) == 0) {
if (!header[6])
return SC_ACCEPT;
else if (header[6] == '-') {
p += 6;
- if (memcmp(p, "CHARSET", 7) == 0)
+ if (memcmp(p, "CHARSET", 8) == 0)
return SC_ACCEPT_CHARSET;
- else if (memcmp(p, "ENCODING", 8) == 0)
+ else if (memcmp(p, "ENCODING", 9) == 0)
return SC_ACCEPT_ENCODING;
- else if (memcmp(p, "LANGUAGE", 8) == 0)
+ else if (memcmp(p, "LANGUAGE", 9) == 0)
return SC_ACCEPT_LANGUAGE;
else
return UNKNOWN_METHOD;
...
OK?
Regards,
Rainer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]