nbd-server: handle port number string conversion errors
authorTuomas Räsänen <tuomasjjrasanen@tjjr.fi>
Thu, 24 Jan 2013 20:43:22 +0000 (22:43 +0200)
committerWouter Verhelst <w@uter.be>
Sat, 26 Jan 2013 10:01:08 +0000 (11:01 +0100)
g_strdup_printf() tries to allocate a string large enough to hold the
string representation of the passed value and coverts the value to
string. It returns NULL if memory allocation fails, or some other error
occurs. Previously, NULL was interpreted as "modern style socket not
needed for this export" by returning zero to the caller, which was
utterly wrong.

Signed-off-by: Tuomas Räsänen <tuomasjjrasanen@tjjr.fi>
nbd-server.c

index feb0ca6..69ee2a4 100644 (file)
@@ -2408,9 +2408,14 @@ int setup_serve(SERVER *const serve, GError **const gerror) {
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_family = serve->socket_family;
 
-       port = g_strdup_printf ("%d", serve->port);
-       if (port == NULL)
-               return 0;
+       port = g_strdup_printf("%d", serve->port);
+       if (!port) {
+                g_set_error(gerror, NBDS_ERR, NBDS_ERR_SYS,
+                            "failed to open an export socket: "
+                            "failed to convert a port number to a string: %s",
+                            strerror(errno));
+                goto out;
+        }
 
        e = getaddrinfo(serve->listenaddr,port,&hints,&ai);