abduco

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

commit 0a94807d605b8fa84eb8ef3653c37abe66d542bc
parent 3cfa99a0313ef71ee0a7f4f3f7e8f0d556ab7251
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 22 Dec 2014 13:30:15 +0100

Better error message in case session name is too long

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

diff --git a/abduco.c b/abduco.c @@ -249,19 +249,27 @@ 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]) + if (sockaddr->sun_path[maxlen-1]) { + errno = ENAMETOOLONG; return false; + } } else if (name[0] == '.' && (name[1] == '.' || name[1] == '/')) { char buf[maxlen], *cwd = getcwd(buf, sizeof buf); if (!cwd) return false; int len = snprintf(sockaddr->sun_path, maxlen, "%s/%s", cwd, name); - if (len < 0 || (size_t)len >= maxlen) + if (len < 0) + return false; + if ((size_t)len >= maxlen) { + errno = ENAMETOOLONG; return false; + } } else { int dir_len = create_socket_dir(sockaddr); - if (dir_len == -1 || dir_len + strlen(name) + strlen(server.host) >= maxlen) + if (dir_len == -1 || dir_len + strlen(name) + strlen(server.host) >= maxlen) { + errno = ENAMETOOLONG; return false; + } strncat(sockaddr->sun_path, name, maxlen - strlen(sockaddr->sun_path) - 1); strncat(sockaddr->sun_path, server.host, maxlen - strlen(sockaddr->sun_path) - 1); }