mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-12-30 05:42:12 +01:00
It's incorrect and can cause issues. This half of the fix for the ncftp bugs, the other part is musl issue. ref #5282
131 lines
3.8 KiB
Diff
131 lines
3.8 KiB
Diff
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);
|