summaryrefslogtreecommitdiff
path: root/nanoftp.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
committerMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
commitf51dd67f3a3f472af0620391eb588eeca4533689 (patch)
tree9184c396c489196608427d5fa35814e86a1e479f /nanoftp.c
parent9705f1a5e858108d21a0128556f42b25d16833cd (diff)
downloadlibxml2-f51dd67f3a3f472af0620391eb588eeca4533689.tar.gz
Load /tmp/tmp.n9GTkp/libxml2-2.6.16 intoupstream/2.6.16
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'nanoftp.c')
-rw-r--r--nanoftp.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/nanoftp.c b/nanoftp.c
index 16e6242..83a23b0 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -260,12 +260,18 @@ xmlNanoFTPCleanup(void) {
void
xmlNanoFTPProxy(const char *host, int port, const char *user,
const char *passwd, int type) {
- if (proxy != NULL)
+ if (proxy != NULL) {
xmlFree(proxy);
- if (proxyUser != NULL)
+ proxy = NULL;
+ }
+ if (proxyUser != NULL) {
xmlFree(proxyUser);
- if (proxyPasswd != NULL)
+ proxyUser = NULL;
+ }
+ if (proxyPasswd != NULL) {
xmlFree(proxyPasswd);
+ proxyPasswd = NULL;
+ }
if (host)
proxy = xmlMemStrdup(host);
if (user)
@@ -697,11 +703,11 @@ xmlNanoFTPNewCtxt(const char *URL) {
ret->controlFd = -1;
unescaped = xmlURIUnescapeString(URL, 0, NULL);
- if (unescaped != NULL)
+ if (unescaped != NULL) {
xmlNanoFTPScanURL(ret, unescaped);
- else if (URL != NULL)
+ xmlFree(unescaped);
+ } else if (URL != NULL)
xmlNanoFTPScanURL(ret, URL);
- xmlFree(unescaped);
return(ret);
}
@@ -777,6 +783,8 @@ xmlNanoFTPGetMore(void *ctx) {
int len;
int size;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
if ((ctxt->controlBufIndex < 0) || (ctxt->controlBufIndex > FTP_BUF_SIZE)) {
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext,
@@ -856,6 +864,8 @@ xmlNanoFTPReadResponse(void *ctx) {
int len;
int res = -1, cur = -1;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
get_more:
/*
* Assumes everything up to controlBuf[controlBufIndex] has been read
@@ -943,6 +953,7 @@ xmlNanoFTPCheckResponse(void *ctx) {
fd_set rfd;
struct timeval tv;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&rfd);
@@ -1031,6 +1042,8 @@ xmlNanoFTPQuit(void *ctx) {
char buf[200];
int len, res;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
snprintf(buf, sizeof(buf), "QUIT\r\n");
len = strlen(buf);
#ifdef DEBUG_FTP
@@ -1442,6 +1455,8 @@ xmlNanoFTPConnectTo(const char *server, int port) {
xmlNanoFTPInit();
if (server == NULL)
return(NULL);
+ if (port <= 0)
+ return(NULL);
ctxt = (xmlNanoFTPCtxtPtr) xmlNanoFTPNewCtxt(NULL);
ctxt->hostname = xmlMemStrdup(server);
if (port != 0)
@@ -1465,12 +1480,14 @@ xmlNanoFTPConnectTo(const char *server, int port) {
*/
int
-xmlNanoFTPCwd(void *ctx, char *directory) {
+xmlNanoFTPCwd(void *ctx, const char *directory) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[400];
int len;
int res;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
/*
* Expected response code for CWD:
*
@@ -1511,12 +1528,14 @@ xmlNanoFTPCwd(void *ctx, char *directory) {
*/
int
-xmlNanoFTPDele(void *ctx, char *file) {
+xmlNanoFTPDele(void *ctx, const char *file) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[400];
int len;
int res;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0) || (file == NULL)) return(-1);
+
/*
* Expected response code for DELE:
*
@@ -1572,6 +1591,8 @@ xmlNanoFTPGetConnection(void *ctx) {
#endif
SOCKLEN_T dataAddrLen;
+ if (ctxt == NULL) return(-1);
+
memset (&dataAddr, 0, sizeof(dataAddr));
#ifdef SUPPORT_IP6
if ((ctxt->ftpAddr).ss_family == AF_INET6) {
@@ -1735,6 +1756,8 @@ xmlNanoFTPCloseConnection(void *ctx) {
fd_set rfd, efd;
struct timeval tv;
+ if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
tv.tv_sec = 15;
tv.tv_usec = 0;
@@ -1907,7 +1930,7 @@ xmlNanoFTPParseList(const char *list, ftpListCallback callback, void *userData)
int
xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
- char *filename) {
+ const char *filename) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[4096 + 1];
int len, res;
@@ -2019,6 +2042,8 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[300];
int res, len;
+ if (ctx == NULL)
+ return(-1);
if ((filename == NULL) && (ctxt->path == NULL))
return(-1);
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);