diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/tools.c | 17 | ||||
-rw-r--r-- | mdk-stage1/tools.h | 1 | ||||
-rw-r--r-- | mdk-stage1/url.c | 14 |
3 files changed, 21 insertions, 11 deletions
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 5b2128fe9..7724c6e72 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -476,6 +476,23 @@ int kernel_version(void) return charstar_to_int(val.release + 2); } +char * asprintf_(const char *msg, ...) +{ + int n; + char * s; + va_list arg_ptr; + va_start(arg_ptr, msg); + n = vsnprintf(0, 1000000, msg, arg_ptr); + va_start(arg_ptr, msg); + if ((s = malloc(n + 1))) { + vsnprintf(s, n + 1, msg, arg_ptr); + va_end(arg_ptr); + return s; + } + va_end(arg_ptr); + return strdup(""); +} + int scall_(int retval, char * msg, char * file, int line) { char tmp[5000]; diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index d8892a1ed..be3883eb5 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -43,6 +43,7 @@ char ** grab_env(void); char ** list_directory(char * direct); int string_array_length(char ** a); int kernel_version(void); +char * asprintf_(const char *msg, ...); int scall_(int retval, char * msg, char * file, int line); #define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__) diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index 4d8a3f5c9..d3b03f942 100644 --- a/mdk-stage1/url.c +++ b/mdk-stage1/url.c @@ -171,7 +171,6 @@ int ftp_open_connection(char * host, char * name, char * password, char * proxy) int sock; struct in_addr serverAddress; struct sockaddr_in destPort; - char * buf; int rc; int port = 21; @@ -181,9 +180,7 @@ int ftp_open_connection(char * host, char * name, char * password, char * proxy) } if (strcmp(proxy, "")) { - buf = alloca(strlen(name) + strlen(host) + 5); - sprintf(buf, "%s@%s", name, host); - name = buf; + name = asprintf_("%s@%s", name, host); host = proxy; } @@ -437,13 +434,8 @@ int http_download_file(char * hostname, char * remotename, int * size, char * pr return FTPERR_FAILED_CONNECT; } - if (proxyprotocol) { - buf = alloca(4 + strlen(proxyprotocol) + 3 + strlen(hostname) + strlen(remotename) + 11 + 6 + strlen(hostname) + 4 + 1); - sprintf(buf, "GET %s://%s%s HTTP/0.9\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname); - } else { - buf = alloca(4 + strlen(remotename) + 11 + 6 + strlen(hostname) + 4 + 1); - sprintf(buf, "GET %s HTTP/0.9\r\nHost: %s\r\n\r\n", remotename, hostname); - } + buf = proxyprotocol ? asprintf_("GET %s://%s%s HTTP/0.9\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname) + : asprintf_("GET %s HTTP/0.9\r\nHost: %s\r\n\r\n", remotename, hostname); write(sock, buf, strlen(buf)); |