ftp: use memdup0 to store the OS from a SYST 215 response
avoid malloc + direct buffer fiddle Closes #12639
This commit is contained in:
parent
f4beef524a
commit
8edcfedc1a
15
lib/ftp.c
15
lib/ftp.c
@ -2951,23 +2951,20 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
|
||||
if(ftpcode == 215) {
|
||||
char *ptr = &data->state.buffer[4]; /* start on the first letter */
|
||||
char *os;
|
||||
char *store;
|
||||
|
||||
os = malloc(nread + 1);
|
||||
if(!os)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
char *start;
|
||||
|
||||
/* Reply format is like
|
||||
215<space><OS-name><space><commentary>
|
||||
*/
|
||||
while(*ptr == ' ')
|
||||
ptr++;
|
||||
for(store = os; *ptr && *ptr != ' ';)
|
||||
*store++ = *ptr++;
|
||||
*store = '\0'; /* null-terminate */
|
||||
for(start = ptr; *ptr && *ptr != ' '; ptr++)
|
||||
;
|
||||
os = Curl_memdup0(start, ptr - start);
|
||||
if(!os)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
/* Check for special servers here. */
|
||||
|
||||
if(strcasecompare(os, "OS/400")) {
|
||||
/* Force OS400 name format 1. */
|
||||
result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SITE NAMEFMT 1");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user