aboutsummaryrefslogtreecommitdiffstats
path: root/main/ncftp/remove-alloca-use.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/ncftp/remove-alloca-use.patch')
-rw-r--r--main/ncftp/remove-alloca-use.patch130
1 files changed, 130 insertions, 0 deletions
diff --git a/main/ncftp/remove-alloca-use.patch b/main/ncftp/remove-alloca-use.patch
new file mode 100644
index 0000000000..0ed63e436f
--- /dev/null
+++ b/main/ncftp/remove-alloca-use.patch
@@ -0,0 +1,130 @@
+The alloca() use in sio is incorrect. gethostby*_r will make the hostent
+contain pointers to the submitted area, but when the function returns the
+alloca() allocated area is freed. Always use the supplied buffer.
+
+diff -ru ncftp-3.2.5.orig/sio/DNSUtil.c ncftp-3.2.5/sio/DNSUtil.c
+--- ncftp-3.2.5.orig/sio/DNSUtil.c 2009-10-24 02:31:23.000000000 +0300
++++ ncftp-3.2.5/sio/DNSUtil.c 2016-03-22 16:17:36.809816988 +0200
+@@ -50,6 +50,13 @@
+ errno = ENOENT;
+ break;
+ }
++#elif defined(HAVE_GETHOSTBYNAME_R) && defined(LINUX)
++ struct hostent *h;
++ int h_errno_unused = 0, r;
++ memset(hpbuf, 0, hpbufsize);
++ r = gethostbyname_r(name, hp, hpbuf, hpbufsize, &h, &h_errno_unused);
++ if (r == 0 && h != NULL)
++ return (0);
+ #elif defined(HAVE_GETHOSTBYNAME_R) && (defined(SOLARIS) || defined(IRIX) || defined(BSDOS))
+ struct hostent *h;
+ int h_errno_unused = 0;
+@@ -57,60 +64,6 @@
+ h = gethostbyname_r(name, hp, hpbuf, hpbufsize, &h_errno_unused);
+ if (h != NULL)
+ return (0);
+-#elif defined(HAVE_GETHOSTBYNAME2_R) && defined(LINUX) && defined(HAVE_ALLOCA)
+- char *usehpbuf;
+- struct hostent *h;
+- int my_h_errno, rc;
+-
+- usehpbuf = hpbuf;
+- forever {
+- errno = 0;
+- my_h_errno = 0;
+- h = NULL;
+- memset(usehpbuf, 0, hpbufsize);
+- rc = gethostbyname2_r(name, AF_INET, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
+- if ((rc == 0) && (h != NULL))
+- return (0);
+- if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
+- hpbufsize *= 2;
+- usehpbuf = alloca(hpbufsize);
+- if (usehpbuf == NULL) {
+- errno = ENOMEM;
+- return (-1);
+- }
+- continue;
+- }
+- if ((rc == 0) && (my_h_errno != 0))
+- errno = ENOENT;
+- break;
+- }
+-#elif defined(HAVE_GETHOSTBYNAME_R) && defined(LINUX) && defined(HAVE_ALLOCA)
+- char *usehpbuf;
+- struct hostent *h;
+- int my_h_errno, rc;
+-
+- usehpbuf = hpbuf;
+- forever {
+- errno = 0;
+- my_h_errno = 0;
+- h = NULL;
+- memset(usehpbuf, 0, hpbufsize);
+- rc = gethostbyname_r(name, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
+- if ((rc == 0) && (h != NULL))
+- return (0);
+- if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
+- hpbufsize *= 2;
+- usehpbuf = alloca(hpbufsize);
+- if (usehpbuf == NULL) {
+- errno = ENOMEM;
+- return (-1);
+- }
+- continue;
+- }
+- if ((rc == 0) && (my_h_errno != 0))
+- errno = ENOENT;
+- break;
+- }
+ #elif defined(HAVE_GETHOSTBYNAME_R) && defined(AIX)
+ struct hostent_data hed;
+ memset(hpbuf, 0, hpbufsize);
+@@ -152,6 +105,13 @@
+ return (-2);
+ return (0);
+ }
++#elif defined(HAVE_GETHOSTBYADDR_R) && defined(LINUX)
++ struct hostent *h;
++ int h_errno_unused = 0, r;
++ memset(hpbuf, 0, hpbufsize);
++ r = gethostbyaddr_r((const void *) addr, asize, atype, hp, hpbuf, hpbufsize, &h, &h_errno_unused);
++ if (r == 0 && h != NULL)
++ return (0);
+ #elif defined(HAVE_GETHOSTBYADDR_R) && (defined(SOLARIS) || defined(IRIX) || defined(BSDOS))
+ struct hostent *h;
+ int h_errno_unused = 0;
+@@ -159,33 +119,6 @@
+ h = gethostbyaddr_r((gethost_addrptr_t) addr, asize, atype, hp, hpbuf, hpbufsize, &h_errno_unused);
+ if (h != NULL)
+ return (0);
+-#elif defined(HAVE_GETHOSTBYADDR_R) && defined(LINUX) && defined(HAVE_ALLOCA)
+- char *usehpbuf;
+- struct hostent *h;
+- int my_h_errno, rc;
+-
+- usehpbuf = hpbuf;
+- forever {
+- errno = 0;
+- my_h_errno = 0;
+- h = NULL;
+- memset(usehpbuf, 0, hpbufsize);
+- rc = gethostbyaddr_r((gethost_addrptr_t) addr, asize, atype, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
+- if ((rc == 0) && (h != NULL))
+- return (0);
+- if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
+- hpbufsize *= 2;
+- usehpbuf = alloca(hpbufsize);
+- if (usehpbuf == NULL) {
+- errno = ENOMEM;
+- return (-1);
+- }
+- continue;
+- }
+- if ((rc == 0) && (my_h_errno != 0))
+- errno = ENOENT;
+- break;
+- }
+ #elif defined(HAVE_GETHOSTBYADDR_R) && defined(AIX)
+ struct hostent_data hed;
+ memset(hpbuf, 0, hpbufsize);