From 35cc5c98978812bb7837dafbdd124ce70549c719 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Sat, 31 Aug 2013 03:19:09 +0200 Subject: [PATCH] vfs: Allow non-null-terminated UNIX socket pathnames This patch fix one of the compatibility issues mentioned in #3255. It allows applications to call bind() or connect() passing an sockaddr_un structure with a pathname that is not null-terminated. Some systems did not require pathname in sockaddr_un::sun_path to be null-terminated, instead the end of the string is determined by the size of the structure passed as an argument of bind() or connect(). The standard is a bit vague in this matter but suggest that the path should be null-terminated and the functions bind() and connect() should be given sizeof(sockaddr_un) as a structure size. --- src/system/kernel/fs/socket.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/kernel/fs/socket.cpp b/src/system/kernel/fs/socket.cpp index 2aca98763b..e62ef60bda 100644 --- a/src/system/kernel/fs/socket.cpp +++ b/src/system/kernel/fs/socket.cpp @@ -827,6 +827,7 @@ _user_bind(int socket, const struct sockaddr *userAddress, return B_BAD_VALUE; sockaddr_storage address; + memset(&address, 0, sizeof(address)); if (!IS_USER_ADDRESS(userAddress) || user_memcpy(&address, userAddress, addressLength) != B_OK) { return B_BAD_ADDRESS; @@ -858,6 +859,7 @@ _user_connect(int socket, const struct sockaddr *userAddress, return B_BAD_VALUE; sockaddr_storage address; + memset(&address, 0, sizeof(address)); if (!IS_USER_ADDRESS(userAddress) || user_memcpy(&address, userAddress, addressLength) != B_OK) { return B_BAD_ADDRESS;