summaryrefslogtreecommitdiff
blob: c984e2d81b19c9d9d4b1ac7ee5b6341eb2b2f4c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
include sys/select.h for the select() prototype on unix systems.

fix warning about using chars as subscripts in arrays.  on many systems, isdigit
turns into an index of an array, so the pnum char needs to be casted to an int.
the spec says these funcs take an int, not a char.

fix warnings about the rv return value being uninitialized in FtpAcceptConnection.

fix a crasher in FtpClose where it derefs the ctrl pointer before checking
if it's NULL.

fix the FtpQuit API to return 0/1 as it's documented so the caller can detect.

patch by Mike Frysinger <vapier@gentoo.org>

--- a/src/ftplib.c
+++ b/src/ftplib.c
@@ -31,6 +32,7 @@
 #if defined(__unix__)
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
@@ -453,7 +456,7 @@ GLOBALDEF int FtpConnect(const char *hos
 	pnum = "ftp";
     else
 	*pnum++ = '\0';
-    if (isdigit(*pnum))
+    if (isdigit((int)*pnum))
 	sin.sin_port = htons(atoi(pnum));
     else
     {
@@ -841,7 +862,7 @@ static int FtpAcceptConnection(netbuf *n
     int i;
     struct timeval tv;
     fd_set mask;
-    int rv;
+    int rv = 0;
 
     FD_ZERO(&mask);
     FD_SET(nControl->handle, &mask);
@@ -858,14 +879,12 @@ static int FtpAcceptConnection(netbuf *n
                 sizeof(nControl->response));
         net_close(nData->handle);
         nData->handle = 0;
-        rv = 0;
     }
     else if (i == 0)
     {
 	strcpy(nControl->response, "timed out waiting for connection");
 	net_close(nData->handle);
 	nData->handle = 0;
-	rv = 0;
     }
     else
     {
@@ -885,7 +904,6 @@ static int FtpAcceptConnection(netbuf *n
 		strncpy(nControl->response, strerror(i),
                         sizeof(nControl->response));
 		nData->handle = 0;
-		rv = 0;
 	    }
 	}
 	else if (FD_ISSET(nControl->handle, &mask))
@@ -893,7 +911,6 @@ static int FtpAcceptConnection(netbuf *n
 	    net_close(nData->handle);
 	    nData->handle = 0;
 	    readresp('2', nControl);
-	    rv = 0;
 	}
     }
     return rv;	
@@ -1054,10 +1054,11 @@ GLOBALDEF int FtpClose(netbuf *nData)
 	net_close(nData->handle);
 	ctrl = nData->ctrl;
 	free(nData);
-	ctrl->data = NULL;
-	if (ctrl && ctrl->response[0] != '4' && ctrl->response[0] != 5)
+	if (ctrl)
 	{
-	    return(readresp('2', ctrl));
+	    ctrl->data = NULL;
+	    if (ctrl->response[0] != '4' && ctrl->response[0] != 5)
+		return readresp('2', ctrl);
 	}
 	return 1;
       case FTPLIB_CONTROL:
@@ -1442,12 +1443,13 @@ GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
  *
  * return 1 if successful, 0 otherwise
  */
-GLOBALDEF void FtpQuit(netbuf *nControl)
+GLOBALDEF int FtpQuit(netbuf *nControl)
 {
     if (nControl->dir != FTPLIB_CONTROL)
-	return;
+	return 0;
     FtpSendCmd("QUIT",'2',nControl);
     net_close(nControl->handle);
     free(nControl->buf);
     free(nControl);
+    return 1;
 }
--- a/src/ftplib.h
+++ b/src/ftplib.h
@@ -111,7 +111,7 @@ GLOBALREF int FtpPut(const char *input, const char *path, char mode,
 	netbuf *nControl);
 GLOBALREF int FtpRename(const char *src, const char *dst, netbuf *nControl);
 GLOBALREF int FtpDelete(const char *fnm, netbuf *nControl);
-GLOBALREF void FtpQuit(netbuf *nControl);
+GLOBALREF int FtpQuit(netbuf *nControl);
 
 #ifdef __cplusplus
 };