tsocket_bsd: return -1 and set errno to ENAMETOOLONG if the unix path is too long
authorStefan Metzmacher <metze@samba.org>
Tue, 3 Nov 2009 16:23:07 +0000 (17:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 3 Nov 2009 17:24:44 +0000 (18:24 +0100)
metze

lib/tsocket/tsocket_bsd.c

index 8f1ccbeb432251b048636494cc2e18e4a3ba9305..05f5be19cbed225cf66b7d4011772c043479c6c8 100644 (file)
@@ -444,9 +444,14 @@ int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
                path = "";
        }
 
+       if (strlen(path) > sizeof(un.sun_path)-1) {
+               errno = ENAMETOOLONG;
+               return -1;
+       }
+
        ZERO_STRUCT(un);
        un.sun_family = AF_UNIX;
-       strncpy(un.sun_path, path, sizeof(un.sun_path));
+       strncpy(un.sun_path, path, sizeof(un.sun_path)-1);
 
        ret = _tsocket_address_bsd_from_sockaddr(mem_ctx,
                                                 (struct sockaddr *)p,