ftp: use memdup0 to store the OS from a SYST 215 response

avoid malloc + direct buffer fiddle

Closes #12639
This commit is contained in:
Daniel Stenberg 2024-01-05 11:58:48 +01:00
parent f4beef524a
commit 8edcfedc1a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -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");