1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-24 00:58:48 -05:00

ftp: shrink temp buffers used for PORT

These two stack based buffers only need to be 46 + 66 bytes instead of
256 + 1024.

Closes #4880
This commit is contained in:
Daniel Stenberg 2020-02-04 23:27:39 +01:00
parent 1cc97ba6e4
commit 671c48eb1a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -920,7 +920,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
struct ftp_conn *ftpc = &conn->proto.ftpc; struct ftp_conn *ftpc = &conn->proto.ftpc;
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
curl_socket_t portsock = CURL_SOCKET_BAD; curl_socket_t portsock = CURL_SOCKET_BAD;
char myhost[256] = ""; char myhost[MAX_IPADR_LEN + 1] = "";
struct Curl_sockaddr_storage ss; struct Curl_sockaddr_storage ss;
Curl_addrinfo *res, *ai; Curl_addrinfo *res, *ai;
@ -931,7 +931,6 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
struct sockaddr_in6 * const sa6 = (void *)sa; struct sockaddr_in6 * const sa6 = (void *)sa;
#endif #endif
char tmp[1024];
static const char mode[][5] = { "EPRT", "PORT" }; static const char mode[][5] = { "EPRT", "PORT" };
int rc; int rc;
int error; int error;
@ -1246,8 +1245,10 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
break; break;
} }
if(PORT == fcmd) { if(PORT == fcmd) {
/* large enough for [IP address],[num],[num] */
char target[sizeof(myhost) + 20];
char *source = myhost; char *source = myhost;
char *dest = tmp; char *dest = target;
/* translate x.x.x.x to x,x,x,x */ /* translate x.x.x.x to x,x,x,x */
while(source && *source) { while(source && *source) {
@ -1261,7 +1262,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
*dest = 0; *dest = 0;
msnprintf(dest, 20, ",%d,%d", (int)(port>>8), (int)(port&0xff)); msnprintf(dest, 20, ",%d,%d", (int)(port>>8), (int)(port&0xff));
result = Curl_pp_sendf(&ftpc->pp, "%s %s", mode[fcmd], tmp); result = Curl_pp_sendf(&ftpc->pp, "%s %s", mode[fcmd], target);
if(result) { if(result) {
failf(data, "Failure sending PORT command: %s", failf(data, "Failure sending PORT command: %s",
curl_easy_strerror(result)); curl_easy_strerror(result));