Skip to content

Commit

Permalink
ftp: use memdup0 to store the OS from a SYST 215 response
Browse files Browse the repository at this point in the history
avoid malloc + direct buffer fiddle

Closes curl#12639
  • Loading branch information
bagder committed Jan 6, 2024
1 parent f4beef5 commit 8edcfed
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8edcfed

Please sign in to comment.