Ticket #3255: 0001-vfs-Allow-non-null-terminated-UNIX-socket-pathnames.patch

File 0001-vfs-Allow-non-null-terminated-UNIX-socket-pathnames.patch, 1.7 KB (added by pdziepak, 7 years ago)
  • src/system/kernel/fs/socket.cpp

    From 5a8ba8febbc2c62459965d4a5c91b051a9279f58 Mon Sep 17 00:00:00 2001
    From: Pawel Dziepak <pdziepak@quarnos.org>
    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 2aca987..e62ef60 100644
    a b _user_bind(int socket, const struct sockaddr *userAddress,  
    827827        return B_BAD_VALUE;
    829829    sockaddr_storage address;
     830    memset(&address, 0, sizeof(address));
    830831    if (!IS_USER_ADDRESS(userAddress)
    831832            || user_memcpy(&address, userAddress, addressLength) != B_OK) {
    832833        return B_BAD_ADDRESS;
    _user_connect(int socket, const struct sockaddr *userAddress,  
    858859        return B_BAD_VALUE;
    860861    sockaddr_storage address;
     862    memset(&address, 0, sizeof(address));
    861863    if (!IS_USER_ADDRESS(userAddress)
    862864            || user_memcpy(&address, userAddress, addressLength) != B_OK) {
    863865        return B_BAD_ADDRESS;