abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 64920e5977659b2a305e72c628bef0d9130578f2
parent 98ac772a974f2bae0825f71439ab142de4a6e589
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 17 Feb 2015 22:46:44 +0100

Simplify maximum socket name length check

Diffstat:
abduco.c | 5++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/abduco.c b/abduco.c @@ -253,12 +253,11 @@ static int create_socket_dir(struct sockaddr_un *sockaddr) { static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) { size_t maxlen = sizeof(sockaddr->sun_path); if (name[0] == '/') { - strncpy(sockaddr->sun_path, name, maxlen); - if (sockaddr->sun_path[maxlen-1]) { - sockaddr->sun_path[maxlen-1] = '\0'; + if (strlen(name) >= maxlen) { errno = ENAMETOOLONG; return false; } + strncpy(sockaddr->sun_path, name, maxlen); } else if (name[0] == '.' && (name[1] == '.' || name[1] == '/')) { char buf[maxlen], *cwd = getcwd(buf, sizeof buf); if (!cwd)