bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The patch of glibc which allows the user to override the pfinet serv


From: zhengda
Subject: Re: The patch of glibc which allows the user to override the pfinet server
Date: Fri, 15 Aug 2008 18:27:00 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080707)

olafBuddenhagen@gmx.net wrote:
+      char *name = NULL;
No need to initialize this -- the asprintf() will overwrite it anyways.
But isn't it always right to initialize a local variable to reduce the possibility of getting bugs?

It won't avoid bugs; only either cover them up, or (less likely) expose
them more clearly -- depending on context...
Right, it cannot avoid bugs, but I believe it is more likely expose the bugs in the program.
Anyway, I guess it's not a big deal here:-)

I guess the patch now is:

Needed for glibc-2_7-branch

2008-06-30 Zheng Da <zhengda1936@gmail.com>

   * hurd/hurdsocks.c (_hurd_socket_server): Searches environment variables
   for the socket server insteading of using the default one.
   (SOCK_SERV_%d, SOCK_SERV): The environment variables that contains
   the path of the socket server.

diff -u glibc-2.7-old/hurd/hurdsock.c glibc-2.7/hurd/hurdsock.c
--- glibc-2.7-old/hurd/hurdsock.c    2008-06-21 01:38:30.000000000 +0200
+++ glibc-2.7/hurd/hurdsock.c    2008-08-15 17:14:09.000000000 +0200
@@ -45,7 +45,7 @@
socket_t
_hurd_socket_server (int domain, int dead)
{
-  socket_t server;
+  socket_t server = MACH_PORT_NULL;

  HURD_CRITICAL_BEGIN;
  __mutex_lock (&lock);
@@ -76,16 +76,34 @@

  if (domain > max_domain || servers[domain] == MACH_PORT_NULL)
    {
-      char name[sizeof (_SERVERS_SOCKET) + 100];
-      char *np = &name[sizeof (name)];
-      *--np = '\0';
-      np = _itoa (domain, np, 10, 0);
-      *--np = '/';
-      np -= sizeof (_SERVERS_SOCKET) - 1;
-      memcpy (np, _SERVERS_SOCKET, sizeof (_SERVERS_SOCKET) - 1);
+      char *name;
+      char *np = NULL;
+
+      if (__asprintf (&name, "SOCK_SERV_%d", domain) < 0)
+    __libc_fatal ("hurd: Can't get the socket server path\n");
+
+      np = getenv (name);
+      __free (name);
+      name = NULL;
+
+      if (np == NULL)
+    {
+      char *sock_servs = NULL;
+
+      sock_servs = getenv ("SOCK_SERV");
+      if (sock_servs == NULL)
+        sock_servs = _SERVERS_SOCKET;
+      if (__asprintf (&name, "%s/%d", sock_servs, domain) < 0)
+          __libc_fatal ("hurd: Can't get the socket server path\n");
+
+      np = name;
+    }
+
      server = __file_name_lookup (np, 0, 0);
      if (domain <= max_domain)
-      servers[domain] = server;
+    servers[domain] = server;
+
+      __free (name);
    }
  else
    server = servers[domain];





reply via email to

[Prev in Thread] Current Thread [Next in Thread]