com php-src: Kill some more strlen() calls and fix a possible missing NULL pointer check: ext/ftp/ftp.c ext/ftp/ftp.h ext/ftp/php_ftp. c
| From: | Kalle Sommer Nielsen | Date: | Sun, 20 Nov 2016 22:36:19 +0000 |
| Subject: | com php-src: Kill some more strlen() calls and fix a possible missing NULL pointer check: ext/ftp/ftp.c ext/ftp/ftp.h ext/ftp/php_ftp. c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95922@lists.php.net to get a copy of this message | ||
Commit: 3ed0af3252dc85d4c4570d8fafd48147e6d44ab5
Author: Kalle Sommer Nielsen <kalle@php.net> Sun, 20 Nov 2016 23:36:19 +0100
Parents: d711798813d6a1297716174de4382f42695a9e92
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3ed0af3252dc85d4c4570d8fafd48147e6d44ab5
Log:
Kill some more strlen() calls and fix a possible missing NULL pointer check
Thanks to Anatol for review
Changed paths:
M ext/ftp/ftp.c
M ext/ftp/ftp.h
M ext/ftp/php_ftp.c
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index fccfa75..32b16bb 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -70,7 +70,9 @@ */ static int ftp_putcmd( ftpbuf_t *ftp, const char *cmd, - const char *args); + const size_t cmd_len, + const char *args, + const size_t args_len); /* wrapper around send/recv to handle timeouts */ static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); @@ -96,7 +98,7 @@ static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp); static databuf_t* data_close(ftpbuf_t *ftp, databuf_t *data); /* generic file lister */ -static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path); +static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len); /* IP and port conversion box */ union ipbox { @@ -211,7 +213,7 @@ ftp_quit(ftpbuf_t *ftp) return 0; } - if (!ftp_putcmd(ftp, "QUIT", NULL)) { + if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 221) { @@ -230,7 +232,7 @@ ftp_quit(ftpbuf_t *ftp) /* {{{ ftp_login */ int -ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) +ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len) { #ifdef HAVE_FTP_SSL SSL_CTX *ctx = NULL; @@ -244,7 +246,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) #ifdef HAVE_FTP_SSL if (ftp->use_ssl && !ftp->ssl_active) { - if (!ftp_putcmd(ftp, "AUTH", "TLS")) { + if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -252,7 +254,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } if (ftp->resp != 234) { - if (!ftp_putcmd(ftp, "AUTH", "SSL")) { + if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -333,7 +335,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) if (!ftp->old_ssl) { /* set protection buffersize to zero */ - if (!ftp_putcmd(ftp, "PBSZ", "0")) { + if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -341,7 +343,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } /* enable data conn encryption */ - if (!ftp_putcmd(ftp, "PROT", "P")) { + if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -353,7 +355,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } #endif - if (!ftp_putcmd(ftp, "USER", user)) { + if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { return 0; } if (!ftp_getresp(ftp)) { @@ -365,7 +367,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) if (ftp->resp != 331) { return 0; } - if (!ftp_putcmd(ftp, "PASS", pass)) { + if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { return 0; } if (!ftp_getresp(ftp)) { @@ -388,7 +390,7 @@ ftp_reinit(ftpbuf_t *ftp) ftp->nb = 0; - if (!ftp_putcmd(ftp, "REIN", NULL)) { + if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 220) { @@ -414,7 +416,7 @@ ftp_syst(ftpbuf_t *ftp) if (ftp->syst) { return ftp->syst; } - if (!ftp_putcmd(ftp, "SYST", NULL)) { + if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 215) { @@ -450,7 +452,7 @@ ftp_pwd(ftpbuf_t *ftp) if (ftp->pwd) { return ftp->pwd; } - if (!ftp_putcmd(ftp, "PWD", NULL)) { + if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 257) { @@ -472,12 +474,12 @@ ftp_pwd(ftpbuf_t *ftp) /* {{{ ftp_exec */ int -ftp_exec(ftpbuf_t *ftp, const char *cmd) +ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "SITE EXEC", cmd)) { + if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -491,12 +493,12 @@ ftp_exec(ftpbuf_t *ftp, const char *cmd) /* {{{ ftp_raw */ void -ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) +ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) { if (ftp == NULL || cmd == NULL) { RETURN_NULL(); } - if (!ftp_putcmd(ftp, cmd, NULL)) { + if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { RETURN_NULL(); } array_init(return_value); @@ -512,7 +514,7 @@ ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) /* {{{ ftp_chdir */ int -ftp_chdir(ftpbuf_t *ftp, const char *dir) +ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { return 0; @@ -523,7 +525,7 @@ ftp_chdir(ftpbuf_t *ftp, const char *dir) ftp->pwd = NULL; } - if (!ftp_putcmd(ftp, "CWD", dir)) { + if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -547,7 +549,7 @@ ftp_cdup(ftpbuf_t *ftp) ftp->pwd = NULL; } - if (!ftp_putcmd(ftp, "CDUP", NULL)) { + if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -568,7 +570,7 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) if (ftp == NULL) { return NULL; } - if (!ftp_putcmd(ftp, "MKD", dir)) { + if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 257) { @@ -592,12 +594,12 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) /* {{{ ftp_rmdir */ int -ftp_rmdir(ftpbuf_t *ftp, const char *dir) +ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "RMD", dir)) { + if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -613,14 +615,19 @@ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) { char *buffer; + size_t buffer_len; if (ftp == NULL || filename_len <= 0) { return 0; } - spprintf(&buffer, 0, "CHMOD %o %s", mode, filename); + buffer_len = spprintf(&buffer, 0, "CHMOD %o %s", mode, filename); - if (!ftp_putcmd(ftp, "SITE", buffer)) { + if (!buffer) { + return 0; + } + + if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { efree(buffer); return 0; } @@ -641,14 +648,19 @@ int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) { char buffer[64]; + int buffer_len; if (ftp == NULL || size <= 0) { return 0; } - snprintf(buffer, sizeof(buffer) - 1, ZEND_LONG_FMT, size); + buffer_len = snprintf(buffer, sizeof(buffer) - 1, ZEND_LONG_FMT, size); + + if (buffer_len < 0) { + return 0; + } - if (!ftp_putcmd(ftp, "ALLO", buffer)) { + if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { return 0; } @@ -671,18 +683,18 @@ ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) /* {{{ ftp_nlist */ char** -ftp_nlist(ftpbuf_t *ftp, const char *path) +ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) { - return ftp_genlist(ftp, "NLST", path); + return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); } /* }}} */ /* {{{ ftp_list */ char** -ftp_list(ftpbuf_t *ftp, const char *path, int recursive) +ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) { - return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), path); + return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : sizeof("LIST")-1), path, path_len); } /* }}} */ @@ -691,7 +703,7 @@ ftp_list(ftpbuf_t *ftp, const char *path, int recursive) int ftp_type(ftpbuf_t *ftp, ftptype_t type) { - char typechar[2] = "?"; + char typechar[2]; if (ftp == NULL) { return 0; @@ -706,7 +718,7 @@ ftp_type(ftpbuf_t *ftp, ftptype_t type) } else { return 0; } - if (!ftp_putcmd(ftp, "TYPE", typechar)) { + if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 2)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -754,7 +766,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) char *endptr, delimiter; /* try EPSV first */ - if (!ftp_putcmd(ftp, "EPSV", NULL)) { + if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp)) { @@ -785,7 +797,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) /* fall back to PASV */ #endif - if (!ftp_putcmd(ftp, "PASV", NULL)) { + if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 227) { @@ -815,7 +827,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) /* {{{ ftp_get */ int -ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos) +ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { databuf_t *data = NULL; size_t rcvd; @@ -835,8 +847,12 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, ftp->data = data; if (resumepos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -844,7 +860,7 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, } } - if (!ftp_putcmd(ftp, "RETR", path)) { + if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -907,7 +923,7 @@ bail: /* {{{ ftp_put */ int -ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos) +ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; zend_long size; @@ -927,8 +943,12 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, z ftp->data = data; if (startpos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -936,7 +956,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, z } } - if (!ftp_putcmd(ftp, "STOR", path)) { + if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -985,7 +1005,7 @@ bail: /* {{{ ftp_size */ zend_long -ftp_size(ftpbuf_t *ftp, const char *path) +ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { return -1; @@ -993,7 +1013,7 @@ ftp_size(ftpbuf_t *ftp, const char *path) if (!ftp_type(ftp, FTPTYPE_IMAGE)) { return -1; } - if (!ftp_putcmd(ftp, "SIZE", path)) { + if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { return -1; } if (!ftp_getresp(ftp) || ftp->resp != 213) { @@ -1006,7 +1026,7 @@ ftp_size(ftpbuf_t *ftp, const char *path) /* {{{ ftp_mdtm */ time_t -ftp_mdtm(ftpbuf_t *ftp, const char *path) +ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) { time_t stamp; struct tm *gmt, tmbuf; @@ -1017,7 +1037,7 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) if (ftp == NULL) { return -1; } - if (!ftp_putcmd(ftp, "MDTM", path)) { + if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { return -1; } if (!ftp_getresp(ftp) || ftp->resp != 213) { @@ -1054,12 +1074,12 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) /* {{{ ftp_delete */ int -ftp_delete(ftpbuf_t *ftp, const char *path) +ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "DELE", path)) { + if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -1073,18 +1093,18 @@ ftp_delete(ftpbuf_t *ftp, const char *path) /* {{{ ftp_rename */ int -ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) +ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "RNFR", src)) { + if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 350) { return 0; } - if (!ftp_putcmd(ftp, "RNTO", dest)) { + if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -1097,12 +1117,12 @@ ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) /* {{{ ftp_site */ int -ftp_site(ftpbuf_t *ftp, const char *cmd) +ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "SITE", cmd)) { + if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { @@ -1118,7 +1138,7 @@ ftp_site(ftpbuf_t *ftp, const char *cmd) /* {{{ ftp_putcmd */ int -ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) +ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t args_len) { int size; char *data; @@ -1129,7 +1149,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) /* build the output buffer */ if (args && args[0]) { /* "cmd args\r\n\0" */ - if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE) { + if (cmd_len + args_len + 4 > FTP_BUFSIZE) { return 0; } if (strpbrk(args, "\r\n")) { @@ -1138,7 +1158,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); } else { /* "cmd\r\n\0" */ - if (strlen(cmd) + 3 > FTP_BUFSIZE) { + if (cmd_len + 3 > FTP_BUFSIZE) { return 0; } size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); @@ -1500,7 +1520,7 @@ my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrl databuf_t* ftp_getdata(ftpbuf_t *ftp) { - int fd = -1; + int fd = -1; databuf_t *data; php_sockaddr_storage addr; struct sockaddr *sa; @@ -1508,6 +1528,7 @@ ftp_getdata(ftpbuf_t *ftp) union ipbox ipbox; char arg[sizeof("255, 255, 255, 255, 255, 255")]; struct timeval tv; + int arg_len; /* ask for a passive connection if we need one */ @@ -1577,10 +1598,15 @@ ftp_getdata(ftpbuf_t *ftp) /* need to use EPRT */ char eprtarg[INET6_ADDRSTRLEN + sizeof("|x||xxxxx|")]; char out[INET6_ADDRSTRLEN]; + int eprtarg_len; inet_ntop(AF_INET6, &((struct sockaddr_in6*) sa)->sin6_addr, out, sizeof(out)); - snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port)); + eprtarg_len = snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port)); - if (!ftp_putcmd(ftp, "EPRT", eprtarg)) { + if (eprtarg_len < 0) { + goto bail; + } + + if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { goto bail; } @@ -1596,9 +1622,12 @@ ftp_getdata(ftpbuf_t *ftp) /* send the PORT */ ipbox.ia[0] = ((struct sockaddr_in*) sa)->sin_addr; ipbox.s[2] = ((struct sockaddr_in*) &addr)->sin_port; - snprintf(arg, sizeof(arg), "%u,%u,%u,%u,%u,%u", ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3], ipbox.c[4], ipbox.c[5]); + arg_len = snprintf(arg, sizeof(arg), "%u,%u,%u,%u,%u,%u", ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3], ipbox.c[4], ipbox.c[5]); - if (!ftp_putcmd(ftp, "PORT", arg)) { + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -1771,7 +1800,7 @@ data_close(ftpbuf_t *ftp, databuf_t *data) /* {{{ ftp_genlist */ char** -ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path) +ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len) { php_stream *tmpstream = NULL; databuf_t *data = NULL; @@ -1798,7 +1827,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path) } ftp->data = data; - if (!ftp_putcmd(ftp, cmd, path)) { + if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { @@ -1876,7 +1905,7 @@ bail: /* {{{ ftp_nb_get */ int -ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos) +ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { databuf_t *data = NULL; char arg[11]; @@ -1894,8 +1923,12 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t typ } if (resumepos>0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -1903,7 +1936,7 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t typ } } - if (!ftp_putcmd(ftp, "RETR", path)) { + if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -1993,7 +2026,7 @@ bail: /* {{{ ftp_nb_put */ int -ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos) +ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; char arg[11]; @@ -2008,8 +2041,12 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type goto bail; } if (startpos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -2017,7 +2054,7 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type } } - if (!ftp_putcmd(ftp, "STOR", path)) { + if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index d355242..acd1ed6 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -109,7 +109,7 @@ void ftp_gc(ftpbuf_t *ftp); ftpbuf_t* ftp_close(ftpbuf_t *ftp); /* logs into the FTP server, returns true on success, false on error */ -int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass); +int ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len); /* reinitializes the connection, returns true on success, false on error */ int ftp_reinit(ftpbuf_t *ftp); @@ -121,13 +121,13 @@ const char* ftp_syst(ftpbuf_t *ftp); const char* ftp_pwd(ftpbuf_t *ftp); /* exec a command [special features], return true on success, false on error */ -int ftp_exec(ftpbuf_t *ftp, const char *cmd); +int ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* send a raw ftp command, return response as a hashtable, NULL on error */ -void ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value); +void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value); /* changes directories, return true on success, false on error */ -int ftp_chdir(ftpbuf_t *ftp, const char *dir); +int ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* changes to parent directory, return true on success, false on error */ int ftp_cdup(ftpbuf_t *ftp); @@ -138,7 +138,7 @@ int ftp_cdup(ftpbuf_t *ftp); zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* removes a directory, return true on success, false on error */ -int ftp_rmdir(ftpbuf_t *ftp, const char *dir); +int ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* Set permissions on a file */ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len); @@ -154,14 +154,14 @@ int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response); * or NULL on error. the return array must be freed (but don't * free the array elements) */ -char** ftp_nlist(ftpbuf_t *ftp, const char *path); +char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns a NULL-terminated array of lines returned by the ftp * LIST command for the given path or NULL on error. the return * array must be freed (but don't * free the array elements) */ -char** ftp_list(ftpbuf_t *ftp, const char *path, int recursive); +char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive); /* switches passive mode on or off * returns true on success, false on error @@ -171,37 +171,37 @@ int ftp_pasv(ftpbuf_t *ftp, int pasv); /* retrieves a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos); +int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos); +int ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* returns the size of the given file, or -1 on error */ -zend_long ftp_size(ftpbuf_t *ftp, const char *path); +zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns the last modified time of the given file, or -1 on error */ -time_t ftp_mdtm(ftpbuf_t *ftp, const char *path); +time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len); /* renames a file on the server */ -int ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest); +int ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len); /* deletes the file from the server */ -int ftp_delete(ftpbuf_t *ftp, const char *path); +int ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len); /* sends a SITE command to the server */ -int ftp_site(ftpbuf_t *ftp, const char *cmd); +int ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* retrieves part of a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos); +int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos); +int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* continues a previous nb_(f)get command */ diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index b0b4c4b..914a8c7 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -440,7 +440,7 @@ PHP_FUNCTION(ftp_login) } /* log in */ - if (!ftp_login(ftp, user, pass)) { + if (!ftp_login(ftp, user, user_len, pass, pass_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -516,7 +516,7 @@ PHP_FUNCTION(ftp_chdir) } /* change directories */ - if (!ftp_chdir(ftp, dir)) { + if (!ftp_chdir(ftp, dir, dir_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -543,7 +543,7 @@ PHP_FUNCTION(ftp_exec) } /* execute serverside command */ - if (!ftp_exec(ftp, cmd)) { + if (!ftp_exec(ftp, cmd, cmd_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -570,7 +570,7 @@ PHP_FUNCTION(ftp_raw) } /* execute arbitrary ftp command */ - ftp_raw(ftp, cmd, return_value); + ftp_raw(ftp, cmd, cmd_len, return_value); } /* }}} */ @@ -620,7 +620,7 @@ PHP_FUNCTION(ftp_rmdir) } /* remove directorie */ - if (!ftp_rmdir(ftp, dir)) { + if (!ftp_rmdir(ftp, dir, dir_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -705,7 +705,7 @@ PHP_FUNCTION(ftp_nlist) } /* get list of files */ - if (NULL == (nlist = ftp_nlist(ftp, dir))) { + if (NULL == (nlist = ftp_nlist(ftp, dir, dir_len))) { RETURN_FALSE; } @@ -736,7 +736,7 @@ PHP_FUNCTION(ftp_rawlist) } /* get raw directory listing */ - if (NULL == (llist = ftp_list(ftp, dir, recursive))) { + if (NULL == (llist = ftp_list(ftp, dir, dir_len, recursive))) { RETURN_FALSE; } @@ -810,7 +810,7 @@ PHP_FUNCTION(ftp_fget) } } - if (!ftp_get(ftp, stream, file, xtype, resumepos)) { + if (!ftp_get(ftp, stream, file, file_len, xtype, resumepos)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -860,7 +860,7 @@ PHP_FUNCTION(ftp_nb_fget) ftp->direction = 0; /* recv */ ftp->closestream = 0; /* do not close */ - if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos)) == PHP_FTP_FAILED) { + if ((ret = ftp_nb_get(ftp, stream, file, file_len, xtype, resumepos)) == PHP_FTP_FAILED) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_LONG(ret); } @@ -946,7 +946,7 @@ PHP_FUNCTION(ftp_get) RETURN_FALSE; } - if (!ftp_get(ftp, outstream, remote, xtype, resumepos)) { + if (!ftp_get(ftp, outstream, remote, remote_len, xtype, resumepos)) { php_stream_close(outstream); VCWD_UNLINK(local); php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -1014,7 +1014,7 @@ PHP_FUNCTION(ftp_nb_get) ftp->direction = 0; /* recv */ ftp->closestream = 1; /* do close */ - if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos)) == PHP_FTP_FAILED) { + if ((ret = ftp_nb_get(ftp, outstream, remote, remote_len, xtype, resumepos)) == PHP_FTP_FAILED) { php_stream_close(outstream); ftp->stream = NULL; VCWD_UNLINK(local); @@ -1101,7 +1101,7 @@ PHP_FUNCTION(ftp_fput) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1111,7 +1111,7 @@ PHP_FUNCTION(ftp_fput) } } - if (!ftp_put(ftp, remote, stream, xtype, startpos)) { + if (!ftp_put(ftp, remote, remote_len, stream, xtype, startpos)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1151,7 +1151,7 @@ PHP_FUNCTION(ftp_nb_fput) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1165,7 +1165,7 @@ PHP_FUNCTION(ftp_nb_fput) ftp->direction = 1; /* send */ ftp->closestream = 0; /* do not close */ - if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos)) == PHP_FTP_FAILED)) { + if (((ret = ftp_nb_put(ftp, remote, remote_len, stream, xtype, startpos)) == PHP_FTP_FAILED)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_LONG(ret); } @@ -1208,7 +1208,7 @@ PHP_FUNCTION(ftp_put) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1218,7 +1218,7 @@ PHP_FUNCTION(ftp_put) } } - if (!ftp_put(ftp, remote, instream, xtype, startpos)) { + if (!ftp_put(ftp, remote, remote_len, instream, xtype, startpos)) { php_stream_close(instream); php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; @@ -1263,7 +1263,7 @@ PHP_FUNCTION(ftp_nb_put) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1277,7 +1277,7 @@ PHP_FUNCTION(ftp_nb_put) ftp->direction = 1; /* send */ ftp->closestream = 1; /* do close */ - ret = ftp_nb_put(ftp, remote, instream, xtype, startpos); + ret = ftp_nb_put(ftp, remote, remote_len, instream, xtype, startpos); if (ret != PHP_FTP_MOREDATA) { php_stream_close(instream); @@ -1310,7 +1310,7 @@ PHP_FUNCTION(ftp_size) } /* get file size */ - RETURN_LONG(ftp_size(ftp, file)); + RETURN_LONG(ftp_size(ftp, file, file_len)); } /* }}} */ @@ -1332,7 +1332,7 @@ PHP_FUNCTION(ftp_mdtm) } /* get file mod time */ - RETURN_LONG(ftp_mdtm(ftp, file)); + RETURN_LONG(ftp_mdtm(ftp, file, file_len)); } /* }}} */ @@ -1354,7 +1354,7 @@ PHP_FUNCTION(ftp_rename) } /* rename the file */ - if (!ftp_rename(ftp, src, dest)) { + if (!ftp_rename(ftp, src, src_len, dest, dest_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1381,7 +1381,7 @@ PHP_FUNCTION(ftp_delete) } /* delete the file */ - if (!ftp_delete(ftp, file)) { + if (!ftp_delete(ftp, file, file_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1408,7 +1408,7 @@ PHP_FUNCTION(ftp_site) } /* send the site command */ - if (!ftp_site(ftp, cmd)) { + if (!ftp_site(ftp, cmd, cmd_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; }
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index fccfa75..32b16bb 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -70,7 +70,9 @@ */ static int ftp_putcmd( ftpbuf_t *ftp, const char *cmd, - const char *args); + const size_t cmd_len, + const char *args, + const size_t args_len); /* wrapper around send/recv to handle timeouts */ static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); @@ -96,7 +98,7 @@ static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp); static databuf_t* data_close(ftpbuf_t *ftp, databuf_t *data); /* generic file lister */ -static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path); +static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len); /* IP and port conversion box */ union ipbox { @@ -211,7 +213,7 @@ ftp_quit(ftpbuf_t *ftp) return 0; } - if (!ftp_putcmd(ftp, "QUIT", NULL)) { + if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 221) { @@ -230,7 +232,7 @@ ftp_quit(ftpbuf_t *ftp) /* {{{ ftp_login */ int -ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) +ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len) { #ifdef HAVE_FTP_SSL SSL_CTX *ctx = NULL; @@ -244,7 +246,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) #ifdef HAVE_FTP_SSL if (ftp->use_ssl && !ftp->ssl_active) { - if (!ftp_putcmd(ftp, "AUTH", "TLS")) { + if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -252,7 +254,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } if (ftp->resp != 234) { - if (!ftp_putcmd(ftp, "AUTH", "SSL")) { + if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -333,7 +335,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) if (!ftp->old_ssl) { /* set protection buffersize to zero */ - if (!ftp_putcmd(ftp, "PBSZ", "0")) { + if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -341,7 +343,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } /* enable data conn encryption */ - if (!ftp_putcmd(ftp, "PROT", "P")) { + if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { return 0; } if (!ftp_getresp(ftp)) { @@ -353,7 +355,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) } #endif - if (!ftp_putcmd(ftp, "USER", user)) { + if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { return 0; } if (!ftp_getresp(ftp)) { @@ -365,7 +367,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) if (ftp->resp != 331) { return 0; } - if (!ftp_putcmd(ftp, "PASS", pass)) { + if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { return 0; } if (!ftp_getresp(ftp)) { @@ -388,7 +390,7 @@ ftp_reinit(ftpbuf_t *ftp) ftp->nb = 0; - if (!ftp_putcmd(ftp, "REIN", NULL)) { + if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 220) { @@ -414,7 +416,7 @@ ftp_syst(ftpbuf_t *ftp) if (ftp->syst) { return ftp->syst; } - if (!ftp_putcmd(ftp, "SYST", NULL)) { + if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 215) { @@ -450,7 +452,7 @@ ftp_pwd(ftpbuf_t *ftp) if (ftp->pwd) { return ftp->pwd; } - if (!ftp_putcmd(ftp, "PWD", NULL)) { + if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 257) { @@ -472,12 +474,12 @@ ftp_pwd(ftpbuf_t *ftp) /* {{{ ftp_exec */ int -ftp_exec(ftpbuf_t *ftp, const char *cmd) +ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "SITE EXEC", cmd)) { + if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -491,12 +493,12 @@ ftp_exec(ftpbuf_t *ftp, const char *cmd) /* {{{ ftp_raw */ void -ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) +ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) { if (ftp == NULL || cmd == NULL) { RETURN_NULL(); } - if (!ftp_putcmd(ftp, cmd, NULL)) { + if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { RETURN_NULL(); } array_init(return_value); @@ -512,7 +514,7 @@ ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) /* {{{ ftp_chdir */ int -ftp_chdir(ftpbuf_t *ftp, const char *dir) +ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { return 0; @@ -523,7 +525,7 @@ ftp_chdir(ftpbuf_t *ftp, const char *dir) ftp->pwd = NULL; } - if (!ftp_putcmd(ftp, "CWD", dir)) { + if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -547,7 +549,7 @@ ftp_cdup(ftpbuf_t *ftp) ftp->pwd = NULL; } - if (!ftp_putcmd(ftp, "CDUP", NULL)) { + if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -568,7 +570,7 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) if (ftp == NULL) { return NULL; } - if (!ftp_putcmd(ftp, "MKD", dir)) { + if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { return NULL; } if (!ftp_getresp(ftp) || ftp->resp != 257) { @@ -592,12 +594,12 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) /* {{{ ftp_rmdir */ int -ftp_rmdir(ftpbuf_t *ftp, const char *dir) +ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "RMD", dir)) { + if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -613,14 +615,19 @@ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) { char *buffer; + size_t buffer_len; if (ftp == NULL || filename_len <= 0) { return 0; } - spprintf(&buffer, 0, "CHMOD %o %s", mode, filename); + buffer_len = spprintf(&buffer, 0, "CHMOD %o %s", mode, filename); - if (!ftp_putcmd(ftp, "SITE", buffer)) { + if (!buffer) { + return 0; + } + + if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { efree(buffer); return 0; } @@ -641,14 +648,19 @@ int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) { char buffer[64]; + int buffer_len; if (ftp == NULL || size <= 0) { return 0; } - snprintf(buffer, sizeof(buffer) - 1, ZEND_LONG_FMT, size); + buffer_len = snprintf(buffer, sizeof(buffer) - 1, ZEND_LONG_FMT, size); + + if (buffer_len < 0) { + return 0; + } - if (!ftp_putcmd(ftp, "ALLO", buffer)) { + if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { return 0; } @@ -671,18 +683,18 @@ ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) /* {{{ ftp_nlist */ char** -ftp_nlist(ftpbuf_t *ftp, const char *path) +ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) { - return ftp_genlist(ftp, "NLST", path); + return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); } /* }}} */ /* {{{ ftp_list */ char** -ftp_list(ftpbuf_t *ftp, const char *path, int recursive) +ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) { - return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), path); + return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : sizeof("LIST")-1), path, path_len); } /* }}} */ @@ -691,7 +703,7 @@ ftp_list(ftpbuf_t *ftp, const char *path, int recursive) int ftp_type(ftpbuf_t *ftp, ftptype_t type) { - char typechar[2] = "?"; + char typechar[2]; if (ftp == NULL) { return 0; @@ -706,7 +718,7 @@ ftp_type(ftpbuf_t *ftp, ftptype_t type) } else { return 0; } - if (!ftp_putcmd(ftp, "TYPE", typechar)) { + if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 2)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -754,7 +766,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) char *endptr, delimiter; /* try EPSV first */ - if (!ftp_putcmd(ftp, "EPSV", NULL)) { + if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp)) { @@ -785,7 +797,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) /* fall back to PASV */ #endif - if (!ftp_putcmd(ftp, "PASV", NULL)) { + if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 227) { @@ -815,7 +827,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) /* {{{ ftp_get */ int -ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos) +ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { databuf_t *data = NULL; size_t rcvd; @@ -835,8 +847,12 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, ftp->data = data; if (resumepos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -844,7 +860,7 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, } } - if (!ftp_putcmd(ftp, "RETR", path)) { + if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -907,7 +923,7 @@ bail: /* {{{ ftp_put */ int -ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos) +ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; zend_long size; @@ -927,8 +943,12 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, z ftp->data = data; if (startpos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -936,7 +956,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, z } } - if (!ftp_putcmd(ftp, "STOR", path)) { + if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -985,7 +1005,7 @@ bail: /* {{{ ftp_size */ zend_long -ftp_size(ftpbuf_t *ftp, const char *path) +ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { return -1; @@ -993,7 +1013,7 @@ ftp_size(ftpbuf_t *ftp, const char *path) if (!ftp_type(ftp, FTPTYPE_IMAGE)) { return -1; } - if (!ftp_putcmd(ftp, "SIZE", path)) { + if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { return -1; } if (!ftp_getresp(ftp) || ftp->resp != 213) { @@ -1006,7 +1026,7 @@ ftp_size(ftpbuf_t *ftp, const char *path) /* {{{ ftp_mdtm */ time_t -ftp_mdtm(ftpbuf_t *ftp, const char *path) +ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) { time_t stamp; struct tm *gmt, tmbuf; @@ -1017,7 +1037,7 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) if (ftp == NULL) { return -1; } - if (!ftp_putcmd(ftp, "MDTM", path)) { + if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { return -1; } if (!ftp_getresp(ftp) || ftp->resp != 213) { @@ -1054,12 +1074,12 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) /* {{{ ftp_delete */ int -ftp_delete(ftpbuf_t *ftp, const char *path) +ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "DELE", path)) { + if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -1073,18 +1093,18 @@ ftp_delete(ftpbuf_t *ftp, const char *path) /* {{{ ftp_rename */ int -ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) +ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "RNFR", src)) { + if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 350) { return 0; } - if (!ftp_putcmd(ftp, "RNTO", dest)) { + if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp != 250) { @@ -1097,12 +1117,12 @@ ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest) /* {{{ ftp_site */ int -ftp_site(ftpbuf_t *ftp, const char *cmd) +ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { return 0; } - if (!ftp_putcmd(ftp, "SITE", cmd)) { + if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { return 0; } if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { @@ -1118,7 +1138,7 @@ ftp_site(ftpbuf_t *ftp, const char *cmd) /* {{{ ftp_putcmd */ int -ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) +ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t args_len) { int size; char *data; @@ -1129,7 +1149,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) /* build the output buffer */ if (args && args[0]) { /* "cmd args\r\n\0" */ - if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE) { + if (cmd_len + args_len + 4 > FTP_BUFSIZE) { return 0; } if (strpbrk(args, "\r\n")) { @@ -1138,7 +1158,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); } else { /* "cmd\r\n\0" */ - if (strlen(cmd) + 3 > FTP_BUFSIZE) { + if (cmd_len + 3 > FTP_BUFSIZE) { return 0; } size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); @@ -1500,7 +1520,7 @@ my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrl databuf_t* ftp_getdata(ftpbuf_t *ftp) { - int fd = -1; + int fd = -1; databuf_t *data; php_sockaddr_storage addr; struct sockaddr *sa; @@ -1508,6 +1528,7 @@ ftp_getdata(ftpbuf_t *ftp) union ipbox ipbox; char arg[sizeof("255, 255, 255, 255, 255, 255")]; struct timeval tv; + int arg_len; /* ask for a passive connection if we need one */ @@ -1577,10 +1598,15 @@ ftp_getdata(ftpbuf_t *ftp) /* need to use EPRT */ char eprtarg[INET6_ADDRSTRLEN + sizeof("|x||xxxxx|")]; char out[INET6_ADDRSTRLEN]; + int eprtarg_len; inet_ntop(AF_INET6, &((struct sockaddr_in6*) sa)->sin6_addr, out, sizeof(out)); - snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port)); + eprtarg_len = snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port)); - if (!ftp_putcmd(ftp, "EPRT", eprtarg)) { + if (eprtarg_len < 0) { + goto bail; + } + + if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { goto bail; } @@ -1596,9 +1622,12 @@ ftp_getdata(ftpbuf_t *ftp) /* send the PORT */ ipbox.ia[0] = ((struct sockaddr_in*) sa)->sin_addr; ipbox.s[2] = ((struct sockaddr_in*) &addr)->sin_port; - snprintf(arg, sizeof(arg), "%u,%u,%u,%u,%u,%u", ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3], ipbox.c[4], ipbox.c[5]); + arg_len = snprintf(arg, sizeof(arg), "%u,%u,%u,%u,%u,%u", ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3], ipbox.c[4], ipbox.c[5]); - if (!ftp_putcmd(ftp, "PORT", arg)) { + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || ftp->resp != 200) { @@ -1771,7 +1800,7 @@ data_close(ftpbuf_t *ftp, databuf_t *data) /* {{{ ftp_genlist */ char** -ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path) +ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len) { php_stream *tmpstream = NULL; databuf_t *data = NULL; @@ -1798,7 +1827,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path) } ftp->data = data; - if (!ftp_putcmd(ftp, cmd, path)) { + if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { @@ -1876,7 +1905,7 @@ bail: /* {{{ ftp_nb_get */ int -ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos) +ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { databuf_t *data = NULL; char arg[11]; @@ -1894,8 +1923,12 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t typ } if (resumepos>0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, resumepos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -1903,7 +1936,7 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t typ } } - if (!ftp_putcmd(ftp, "RETR", path)) { + if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { @@ -1993,7 +2026,7 @@ bail: /* {{{ ftp_nb_put */ int -ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos) +ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; char arg[11]; @@ -2008,8 +2041,12 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type goto bail; } if (startpos > 0) { - snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); - if (!ftp_putcmd(ftp, "REST", arg)) { + int arg_len = snprintf(arg, sizeof(arg), ZEND_LONG_FMT, startpos); + + if (arg_len < 0) { + goto bail; + } + if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 350)) { @@ -2017,7 +2054,7 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type } } - if (!ftp_putcmd(ftp, "STOR", path)) { + if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { goto bail; } if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index d355242..acd1ed6 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -109,7 +109,7 @@ void ftp_gc(ftpbuf_t *ftp); ftpbuf_t* ftp_close(ftpbuf_t *ftp); /* logs into the FTP server, returns true on success, false on error */ -int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass); +int ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len); /* reinitializes the connection, returns true on success, false on error */ int ftp_reinit(ftpbuf_t *ftp); @@ -121,13 +121,13 @@ const char* ftp_syst(ftpbuf_t *ftp); const char* ftp_pwd(ftpbuf_t *ftp); /* exec a command [special features], return true on success, false on error */ -int ftp_exec(ftpbuf_t *ftp, const char *cmd); +int ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* send a raw ftp command, return response as a hashtable, NULL on error */ -void ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value); +void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value); /* changes directories, return true on success, false on error */ -int ftp_chdir(ftpbuf_t *ftp, const char *dir); +int ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* changes to parent directory, return true on success, false on error */ int ftp_cdup(ftpbuf_t *ftp); @@ -138,7 +138,7 @@ int ftp_cdup(ftpbuf_t *ftp); zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* removes a directory, return true on success, false on error */ -int ftp_rmdir(ftpbuf_t *ftp, const char *dir); +int ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* Set permissions on a file */ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len); @@ -154,14 +154,14 @@ int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response); * or NULL on error. the return array must be freed (but don't * free the array elements) */ -char** ftp_nlist(ftpbuf_t *ftp, const char *path); +char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns a NULL-terminated array of lines returned by the ftp * LIST command for the given path or NULL on error. the return * array must be freed (but don't * free the array elements) */ -char** ftp_list(ftpbuf_t *ftp, const char *path, int recursive); +char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive); /* switches passive mode on or off * returns true on success, false on error @@ -171,37 +171,37 @@ int ftp_pasv(ftpbuf_t *ftp, int pasv); /* retrieves a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos); +int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos); +int ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* returns the size of the given file, or -1 on error */ -zend_long ftp_size(ftpbuf_t *ftp, const char *path); +zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns the last modified time of the given file, or -1 on error */ -time_t ftp_mdtm(ftpbuf_t *ftp, const char *path); +time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len); /* renames a file on the server */ -int ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest); +int ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len); /* deletes the file from the server */ -int ftp_delete(ftpbuf_t *ftp, const char *path); +int ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len); /* sends a SITE command to the server */ -int ftp_site(ftpbuf_t *ftp, const char *cmd); +int ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* retrieves part of a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, zend_long resumepos); +int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, zend_long startpos); +int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* continues a previous nb_(f)get command */ diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index b0b4c4b..914a8c7 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -440,7 +440,7 @@ PHP_FUNCTION(ftp_login) } /* log in */ - if (!ftp_login(ftp, user, pass)) { + if (!ftp_login(ftp, user, user_len, pass, pass_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -516,7 +516,7 @@ PHP_FUNCTION(ftp_chdir) } /* change directories */ - if (!ftp_chdir(ftp, dir)) { + if (!ftp_chdir(ftp, dir, dir_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -543,7 +543,7 @@ PHP_FUNCTION(ftp_exec) } /* execute serverside command */ - if (!ftp_exec(ftp, cmd)) { + if (!ftp_exec(ftp, cmd, cmd_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -570,7 +570,7 @@ PHP_FUNCTION(ftp_raw) } /* execute arbitrary ftp command */ - ftp_raw(ftp, cmd, return_value); + ftp_raw(ftp, cmd, cmd_len, return_value); } /* }}} */ @@ -620,7 +620,7 @@ PHP_FUNCTION(ftp_rmdir) } /* remove directorie */ - if (!ftp_rmdir(ftp, dir)) { + if (!ftp_rmdir(ftp, dir, dir_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -705,7 +705,7 @@ PHP_FUNCTION(ftp_nlist) } /* get list of files */ - if (NULL == (nlist = ftp_nlist(ftp, dir))) { + if (NULL == (nlist = ftp_nlist(ftp, dir, dir_len))) { RETURN_FALSE; } @@ -736,7 +736,7 @@ PHP_FUNCTION(ftp_rawlist) } /* get raw directory listing */ - if (NULL == (llist = ftp_list(ftp, dir, recursive))) { + if (NULL == (llist = ftp_list(ftp, dir, dir_len, recursive))) { RETURN_FALSE; } @@ -810,7 +810,7 @@ PHP_FUNCTION(ftp_fget) } } - if (!ftp_get(ftp, stream, file, xtype, resumepos)) { + if (!ftp_get(ftp, stream, file, file_len, xtype, resumepos)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -860,7 +860,7 @@ PHP_FUNCTION(ftp_nb_fget) ftp->direction = 0; /* recv */ ftp->closestream = 0; /* do not close */ - if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos)) == PHP_FTP_FAILED) { + if ((ret = ftp_nb_get(ftp, stream, file, file_len, xtype, resumepos)) == PHP_FTP_FAILED) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_LONG(ret); } @@ -946,7 +946,7 @@ PHP_FUNCTION(ftp_get) RETURN_FALSE; } - if (!ftp_get(ftp, outstream, remote, xtype, resumepos)) { + if (!ftp_get(ftp, outstream, remote, remote_len, xtype, resumepos)) { php_stream_close(outstream); VCWD_UNLINK(local); php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -1014,7 +1014,7 @@ PHP_FUNCTION(ftp_nb_get) ftp->direction = 0; /* recv */ ftp->closestream = 1; /* do close */ - if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos)) == PHP_FTP_FAILED) { + if ((ret = ftp_nb_get(ftp, outstream, remote, remote_len, xtype, resumepos)) == PHP_FTP_FAILED) { php_stream_close(outstream); ftp->stream = NULL; VCWD_UNLINK(local); @@ -1101,7 +1101,7 @@ PHP_FUNCTION(ftp_fput) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1111,7 +1111,7 @@ PHP_FUNCTION(ftp_fput) } } - if (!ftp_put(ftp, remote, stream, xtype, startpos)) { + if (!ftp_put(ftp, remote, remote_len, stream, xtype, startpos)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1151,7 +1151,7 @@ PHP_FUNCTION(ftp_nb_fput) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1165,7 +1165,7 @@ PHP_FUNCTION(ftp_nb_fput) ftp->direction = 1; /* send */ ftp->closestream = 0; /* do not close */ - if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos)) == PHP_FTP_FAILED)) { + if (((ret = ftp_nb_put(ftp, remote, remote_len, stream, xtype, startpos)) == PHP_FTP_FAILED)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_LONG(ret); } @@ -1208,7 +1208,7 @@ PHP_FUNCTION(ftp_put) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1218,7 +1218,7 @@ PHP_FUNCTION(ftp_put) } } - if (!ftp_put(ftp, remote, instream, xtype, startpos)) { + if (!ftp_put(ftp, remote, remote_len, instream, xtype, startpos)) { php_stream_close(instream); php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; @@ -1263,7 +1263,7 @@ PHP_FUNCTION(ftp_nb_put) if (ftp->autoseek && startpos) { /* if autoresume is wanted ask for remote size */ if (startpos == PHP_FTP_AUTORESUME) { - startpos = ftp_size(ftp, remote); + startpos = ftp_size(ftp, remote, remote_len); if (startpos < 0) { startpos = 0; } @@ -1277,7 +1277,7 @@ PHP_FUNCTION(ftp_nb_put) ftp->direction = 1; /* send */ ftp->closestream = 1; /* do close */ - ret = ftp_nb_put(ftp, remote, instream, xtype, startpos); + ret = ftp_nb_put(ftp, remote, remote_len, instream, xtype, startpos); if (ret != PHP_FTP_MOREDATA) { php_stream_close(instream); @@ -1310,7 +1310,7 @@ PHP_FUNCTION(ftp_size) } /* get file size */ - RETURN_LONG(ftp_size(ftp, file)); + RETURN_LONG(ftp_size(ftp, file, file_len)); } /* }}} */ @@ -1332,7 +1332,7 @@ PHP_FUNCTION(ftp_mdtm) } /* get file mod time */ - RETURN_LONG(ftp_mdtm(ftp, file)); + RETURN_LONG(ftp_mdtm(ftp, file, file_len)); } /* }}} */ @@ -1354,7 +1354,7 @@ PHP_FUNCTION(ftp_rename) } /* rename the file */ - if (!ftp_rename(ftp, src, dest)) { + if (!ftp_rename(ftp, src, src_len, dest, dest_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1381,7 +1381,7 @@ PHP_FUNCTION(ftp_delete) } /* delete the file */ - if (!ftp_delete(ftp, file)) { + if (!ftp_delete(ftp, file, file_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; } @@ -1408,7 +1408,7 @@ PHP_FUNCTION(ftp_site) } /* send the site command */ - if (!ftp_site(ftp, cmd)) { + if (!ftp_site(ftp, cmd, cmd_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); RETURN_FALSE; }