Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-libs/ftplib/files: ftplib-4.0-crash.patch
Date: Mon, 31 Mar 2014 04:27:31
Message-Id: 20140331042725.9CE442005E@flycatcher.gentoo.org
1 vapier 14/03/31 04:27:25
2
3 Added: ftplib-4.0-crash.patch
4 Log:
5 Fix crash in FtpClose and other issues. Convert to multilib-minimal.
6
7 (Portage version: 2.2.10/cvs/Linux x86_64, signed Manifest commit with key D2E96200)
8
9 Revision Changes Path
10 1.1 net-libs/ftplib/files/ftplib-4.0-crash.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/ftplib/files/ftplib-4.0-crash.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/ftplib/files/ftplib-4.0-crash.patch?rev=1.1&content-type=text/plain
14
15 Index: ftplib-4.0-crash.patch
16 ===================================================================
17 include sys/select.h for the select() prototype on unix systems.
18
19 fix warning about using chars as subscripts in arrays. on many systems, isdigit
20 turns into an index of an array, so the pnum char needs to be casted to an int.
21 the spec says these funcs take an int, not a char.
22
23 fix warnings about the rv return value being uninitialized in FtpAcceptConnection.
24
25 fix a crasher in FtpClose where it derefs the ctrl pointer before checking
26 if it's NULL.
27
28 fix the FtpQuit API to return 0/1 as it's documented so the caller can detect.
29
30 patch by Mike Frysinger <vapier@g.o>
31
32 --- a/src/ftplib.c
33 +++ b/src/ftplib.c
34 @@ -31,6 +32,7 @@
35 #if defined(__unix__)
36 #include <sys/time.h>
37 #include <sys/types.h>
38 +#include <sys/select.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <netdb.h>
42 @@ -453,7 +456,7 @@ GLOBALDEF int FtpConnect(const char *hos
43 pnum = "ftp";
44 else
45 *pnum++ = '\0';
46 - if (isdigit(*pnum))
47 + if (isdigit((int)*pnum))
48 sin.sin_port = htons(atoi(pnum));
49 else
50 {
51 @@ -841,7 +862,7 @@ static int FtpAcceptConnection(netbuf *n
52 int i;
53 struct timeval tv;
54 fd_set mask;
55 - int rv;
56 + int rv = 0;
57
58 FD_ZERO(&mask);
59 FD_SET(nControl->handle, &mask);
60 @@ -858,14 +879,12 @@ static int FtpAcceptConnection(netbuf *n
61 sizeof(nControl->response));
62 net_close(nData->handle);
63 nData->handle = 0;
64 - rv = 0;
65 }
66 else if (i == 0)
67 {
68 strcpy(nControl->response, "timed out waiting for connection");
69 net_close(nData->handle);
70 nData->handle = 0;
71 - rv = 0;
72 }
73 else
74 {
75 @@ -885,7 +904,6 @@ static int FtpAcceptConnection(netbuf *n
76 strncpy(nControl->response, strerror(i),
77 sizeof(nControl->response));
78 nData->handle = 0;
79 - rv = 0;
80 }
81 }
82 else if (FD_ISSET(nControl->handle, &mask))
83 @@ -893,7 +911,6 @@ static int FtpAcceptConnection(netbuf *n
84 net_close(nData->handle);
85 nData->handle = 0;
86 readresp('2', nControl);
87 - rv = 0;
88 }
89 }
90 return rv;
91 @@ -1054,10 +1054,11 @@ GLOBALDEF int FtpClose(netbuf *nData)
92 net_close(nData->handle);
93 ctrl = nData->ctrl;
94 free(nData);
95 - ctrl->data = NULL;
96 - if (ctrl && ctrl->response[0] != '4' && ctrl->response[0] != 5)
97 + if (ctrl)
98 {
99 - return(readresp('2', ctrl));
100 + ctrl->data = NULL;
101 + if (ctrl->response[0] != '4' && ctrl->response[0] != 5)
102 + return readresp('2', ctrl);
103 }
104 return 1;
105 case FTPLIB_CONTROL:
106 @@ -1442,12 +1443,13 @@ GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
107 *
108 * return 1 if successful, 0 otherwise
109 */
110 -GLOBALDEF void FtpQuit(netbuf *nControl)
111 +GLOBALDEF int FtpQuit(netbuf *nControl)
112 {
113 if (nControl->dir != FTPLIB_CONTROL)
114 - return;
115 + return 0;
116 FtpSendCmd("QUIT",'2',nControl);
117 net_close(nControl->handle);
118 free(nControl->buf);
119 free(nControl);
120 + return 1;
121 }
122 --- a/src/ftplib.h
123 +++ b/src/ftplib.h
124 @@ -111,7 +111,7 @@ GLOBALREF int FtpPut(const char *input, const char *path, char mode,
125 netbuf *nControl);
126 GLOBALREF int FtpRename(const char *src, const char *dst, netbuf *nControl);
127 GLOBALREF int FtpDelete(const char *fnm, netbuf *nControl);
128 -GLOBALREF void FtpQuit(netbuf *nControl);
129 +GLOBALREF int FtpQuit(netbuf *nControl);
130
131 #ifdef __cplusplus
132 };