mirror of
https://github.com/curl/curl.git
synced 2026-08-26 10:53:36 +03:00
curl: writeout: fix repeated header outputs
The function stored a terminating zero into the buffer for convenience, but when on repeated calls that would cause problems. Starting now, the passed in buffer is not modified. Reported-by: highmtworks on github Fixes #9150 Closes #9152
This commit is contained in:
parent
a88dbe410f
commit
0ef4f087cd
1 changed files with 16 additions and 11 deletions
|
|
@ -338,8 +338,8 @@ void ourWriteOut(const char *writeinfo, struct per_transfer *per,
|
||||||
else {
|
else {
|
||||||
/* this is meant as a variable to output */
|
/* this is meant as a variable to output */
|
||||||
char *end;
|
char *end;
|
||||||
|
size_t vlen;
|
||||||
if('{' == ptr[1]) {
|
if('{' == ptr[1]) {
|
||||||
char keepit;
|
|
||||||
int i;
|
int i;
|
||||||
bool match = FALSE;
|
bool match = FALSE;
|
||||||
end = strchr(ptr, '}');
|
end = strchr(ptr, '}');
|
||||||
|
|
@ -348,10 +348,10 @@ void ourWriteOut(const char *writeinfo, struct per_transfer *per,
|
||||||
fputs("%{", stream);
|
fputs("%{", stream);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
keepit = *end;
|
vlen = end - ptr;
|
||||||
*end = 0; /* null-terminate */
|
|
||||||
for(i = 0; variables[i].name; i++) {
|
for(i = 0; variables[i].name; i++) {
|
||||||
if(curl_strequal(ptr, variables[i].name)) {
|
if((strlen(variables[i].name) == vlen) &&
|
||||||
|
curl_strnequal(ptr, variables[i].name, vlen)) {
|
||||||
match = TRUE;
|
match = TRUE;
|
||||||
switch(variables[i].id) {
|
switch(variables[i].id) {
|
||||||
case VAR_ONERROR:
|
case VAR_ONERROR:
|
||||||
|
|
@ -380,21 +380,26 @@ void ourWriteOut(const char *writeinfo, struct per_transfer *per,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!match) {
|
if(!match) {
|
||||||
fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
|
fprintf(stderr, "curl: unknown --write-out variable: '%.*s'\n",
|
||||||
|
(int)vlen, ptr);
|
||||||
}
|
}
|
||||||
ptr = end + 1; /* pass the end */
|
ptr = end + 1; /* pass the end */
|
||||||
*end = keepit;
|
|
||||||
}
|
}
|
||||||
else if(!strncmp("header{", &ptr[1], 7)) {
|
else if(!strncmp("header{", &ptr[1], 7)) {
|
||||||
ptr += 8;
|
ptr += 8;
|
||||||
end = strchr(ptr, '}');
|
end = strchr(ptr, '}');
|
||||||
if(end) {
|
if(end) {
|
||||||
|
char hname[256]; /* holds the longest header field name */
|
||||||
struct curl_header *header;
|
struct curl_header *header;
|
||||||
*end = 0;
|
vlen = end - ptr;
|
||||||
if(CURLHE_OK == curl_easy_header(per->curl, ptr, 0, CURLH_HEADER,
|
if(vlen < sizeof(hname)) {
|
||||||
-1, &header))
|
memcpy(hname, ptr, vlen);
|
||||||
fputs(header->value, stream);
|
hname[vlen] = 0;
|
||||||
ptr = end + 1; /* pass the end */
|
if(CURLHE_OK == curl_easy_header(per->curl, hname, 0,
|
||||||
|
CURLH_HEADER, -1, &header))
|
||||||
|
fputs(header->value, stream);
|
||||||
|
}
|
||||||
|
ptr = end + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fputs("%header{", stream);
|
fputs("%header{", stream);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue