[polyml] 01/05: Remove all use of MAXHOSTNAMELEN

James Clarke jrtc27-guest at moszumanska.debian.org
Mon Mar 14 20:04:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

jrtc27-guest pushed a commit to branch master
in repository polyml.

commit 77f9d9b90cd83663da9919ef4a9fa31c2d786a95
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Mon Mar 14 19:32:47 2016 +0000

    Remove all use of MAXHOSTNAMELEN
---
 debian/changelog                   |   7 +++
 debian/patches/maxhostnamelen.diff | 119 +++++++++++++++++++++++++++++++++++++
 debian/patches/series              |   1 +
 3 files changed, 127 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 3b5967e..78df146 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+polyml (5.6-4) UNRELEASED; urgency=low
+
+  * New patches:
+    - maxhostnamelen.diff: Remove all use of MAXHOSTNAMELEN
+
+ -- James Clarke <jrtc27 at jrtc27.com>  Mon, 14 Mar 2016 18:39:58 +0000
+
 polyml (5.6-3) unstable; urgency=low
 
   * Support for the Hurd
diff --git a/debian/patches/maxhostnamelen.diff b/debian/patches/maxhostnamelen.diff
new file mode 100644
index 0000000..f864f0e
--- /dev/null
+++ b/debian/patches/maxhostnamelen.diff
@@ -0,0 +1,119 @@
+Description: Remove all use of MAXHOSTNAMELEN
+Author: James Clarke <jrtc27 at jrtc27.com>
+Forwarded: https://github.com/polyml/polyml/pull/42
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/libpolyml/network.cpp
++++ b/libpolyml/network.cpp
+@@ -29,6 +29,10 @@
+ #include <stdio.h>
+ #endif
+ 
++#ifdef HAVE_STDLIB_H
++#include <stdlib.h>
++#endif
++
+ #ifdef HAVE_ERRNO_H
+ #include <errno.h>
+ #endif
+@@ -123,10 +127,6 @@
+ #include "machine_dep.h"
+ #include "errors.h"
+ 
+-#ifndef MAXHOSTNAMELEN
+-#define MAXHOSTNAMELEN 256
+-#endif
+-
+ #define STREAMID(x) (DEREFSTREAMHANDLE(x)->streamNo)
+ #define SAVE(x) taskData->saveVec.push(x)
+ #define ALLOC(n) alloc_and_save(taskData, n)
+@@ -412,19 +412,29 @@
+     {
+     case 0:
+         { /* Get the current host name. */
+-            char hostName[MAXHOSTNAMELEN];
+-            if (gethostname(hostName, MAXHOSTNAMELEN) != 0)
++            size_t size = 4096;
++            TempCString hostName((char *)malloc(size));
++            if (hostName == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++            int err;
++            while ((err = gethostname(hostName, size)) != 0 && GETERROR == ENAMETOOLONG)
++            {
++                if (size > SIZE_MAX / 2) raise_fail(taskData, "gethostname needs too large a buffer");
++                size *= 2;
++                char *new_buf = (char *)realloc(hostName, size);
++                if (new_buf == NULL) raise_syscall(taskData, "Insufficient memory", ENOMEM);
++                hostName = new_buf;
++            }
++
++            if (err != 0)
+                 raise_syscall(taskData, "gethostname failed", GETERROR);
++
+             return (SAVE(C_string_to_Poly(taskData, hostName)));
+         }
+ 
+     case 1:
+         {
+             /* Look up a host name. */
+-            char hostName[MAXHOSTNAMELEN];
+-            POLYUNSIGNED length = Poly_string_to_C(DEREFWORD(args), hostName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Host name too long", ENAMETOOLONG);
++            TempCString hostName(Poly_string_to_C_alloc(DEREFWORD(args)));
+             struct hostent *host = gethostbyname(hostName);
+             if (host == NULL)
+                 raise_syscall(taskData, "gethostbyname failed", GETERROR);
+@@ -447,10 +457,7 @@
+     case 3:
+         {
+             /* Look up protocol entry. */
+-            char protoName[MAXHOSTNAMELEN];
+-            POLYUNSIGNED length = Poly_string_to_C(DEREFWORD(args), protoName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Protocol name too long", ENAMETOOLONG);
++            TempCString protoName(Poly_string_to_C_alloc(DEREFWORD(args)));
+             struct protoent *proto = getprotobyname(protoName);
+             if (proto == NULL)
+                 raise_syscall(taskData, "getprotobyname failed", GETERROR);
+@@ -471,10 +478,7 @@
+     case 5:
+         {
+             /* Get service given service name only. */
+-            char servName[MAXHOSTNAMELEN];
+-            POLYUNSIGNED length = Poly_string_to_C(DEREFWORD(args), servName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Service name too long", ENAMETOOLONG);
++            TempCString servName(Poly_string_to_C_alloc(DEREFWORD(args)));
+             struct servent *serv = getservbyname (servName, NULL);
+             if (serv == NULL)
+                 raise_syscall(taskData, "getservbyname failed", GETERROR);
+@@ -484,13 +488,8 @@
+     case 6:
+         {
+             /* Get service given service name and protocol name. */
+-            char servName[MAXHOSTNAMELEN], protoName[MAXHOSTNAMELEN];
+-            POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(0), servName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Service name too long", ENAMETOOLONG);
+-            length = Poly_string_to_C(args->WordP()->Get(1), protoName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Protocol name too long", ENAMETOOLONG);
++            TempCString servName(Poly_string_to_C_alloc(args->WordP()->Get(0)));
++            TempCString protoName(Poly_string_to_C_alloc(args->WordP()->Get(1)));
+             struct servent *serv = getservbyname (servName, protoName);
+             if (serv == NULL)
+                 raise_syscall(taskData, "getservbyname failed", GETERROR);
+@@ -511,12 +510,9 @@
+     case 8:
+         {
+             /* Get service given port number and protocol name. */
+-            char protoName[MAXHOSTNAMELEN];
+             struct servent *serv;
+             long port = htons(get_C_ushort(taskData, DEREFHANDLE(args)->Get(0)));
+-            POLYUNSIGNED length = Poly_string_to_C(args->WordP()->Get(1), protoName, MAXHOSTNAMELEN);
+-            if (length > MAXHOSTNAMELEN)
+-                raise_syscall(taskData, "Protocol name too long", ENAMETOOLONG);
++            TempCString protoName(Poly_string_to_C_alloc(args->WordP()->Get(1)));
+             serv = getservbyport (port, protoName);
+             if (serv == NULL)
+                 raise_syscall(taskData, "getservbyport failed", GETERROR);
diff --git a/debian/patches/series b/debian/patches/series
index df67ccd..ce71340 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -19,3 +19,4 @@ noexec-stack-gnu.diff
 source-date-epoch.diff
 bss-ioarea.diff
 noflsh-unsigned.diff
+maxhostnamelen.diff

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/polyml.git



More information about the debian-science-commits mailing list