Skip to content

Commit c211398

Browse files
lemenkovorgads
authored andcommitted
Replace xp_get_content_length() with get_header()
The old xp_get_content_length() only checked five hardcoded case variants (Content-Length, Content-length, content-Length, content-length, CONTENT-LENGTH), which did not comply with RFC 3261 requiring case-insensitive header matching. Replace with get_header() which uses strcasestr() for proper case-insensitive search and already handles the compact form "l:". Signed-off-by: Peter Lemenkov <[email protected]> Assisted-by: Claude (Anthropic) <https://claude.ai>
1 parent c3dab05 commit c211398

File tree

3 files changed

+2
-42
lines changed

3 files changed

+2
-42
lines changed

include/xp_parser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ int xp_is_invalid();
3232
int xp_get_invalid_line();
3333
const char* xp_get_value(const char *name);
3434
char* xp_get_cdata(void);
35-
int xp_get_content_length(const char *P_buffer);
3635

3736
#ifdef __cplusplus
3837
}

src/scenario.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ scenario::scenario(char * filename, int deflt)
849849
int removed_clrf = 0;
850850
char * msg = clean_cdata(ptr, &removed_clrf);
851851

852-
L_content_length = xp_get_content_length(msg);
852+
char* cl_str = get_header(msg, "Content-Length:", true);
853+
L_content_length = (cl_str && *cl_str) ? atoi(cl_str) : -1;
853854
switch (L_content_length) {
854855
case -1 :
855856
// the msg does not contain content-length field

src/xp_parser.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -596,43 +596,3 @@ char* xp_get_cdata(void)
596596
buffer[end-ptr] = 0;
597597
return buffer;
598598
}
599-
600-
int xp_get_content_length(const char *P_buffer)
601-
{
602-
const char *L_ctl_hdr;
603-
int L_content_length = -1;
604-
unsigned char short_form;
605-
606-
short_form = 0;
607-
608-
L_ctl_hdr = strstr(P_buffer, "\nContent-Length:");
609-
if (!L_ctl_hdr) {
610-
L_ctl_hdr = strstr(P_buffer, "\nContent-length:");
611-
}
612-
if (!L_ctl_hdr) {
613-
L_ctl_hdr = strstr(P_buffer, "\ncontent-Length:");
614-
}
615-
if (!L_ctl_hdr) {
616-
L_ctl_hdr = strstr(P_buffer, "\ncontent-length:");
617-
}
618-
if (!L_ctl_hdr) {
619-
L_ctl_hdr = strstr(P_buffer, "\nCONTENT-LENGTH:");
620-
}
621-
if (!L_ctl_hdr) {
622-
L_ctl_hdr = strstr(P_buffer, "\nl:");
623-
short_form = 1;
624-
}
625-
626-
if (L_ctl_hdr) {
627-
if (short_form) {
628-
L_ctl_hdr += 3;
629-
} else {
630-
L_ctl_hdr += 16;
631-
}
632-
while (isspace(*L_ctl_hdr))
633-
L_ctl_hdr++;
634-
sscanf(L_ctl_hdr, "%d", &L_content_length);
635-
}
636-
/* L_content_length = -1 the message does not contain content-length */
637-
return (L_content_length);
638-
}

0 commit comments

Comments
 (0)