From 30e3884a75a8f554f2c7bd96fdd23da569774546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sun, 25 Jul 2021 01:47:13 +0200 Subject: [PATCH] pulse-server: add another check for the return value of `snprintf()` In addition to checking if the resulting string would be too long, also check whether or not snprintf failed. --- src/modules/module-protocol-pulse/utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/module-protocol-pulse/utils.c b/src/modules/module-protocol-pulse/utils.c index f8a71db8d..436daff63 100644 --- a/src/modules/module-protocol-pulse/utils.c +++ b/src/modules/module-protocol-pulse/utils.c @@ -68,11 +68,15 @@ int get_runtime_dir(char *buf, size_t buflen, const char *dir) if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) == 0) runtime_dir = result ? result->pw_dir : NULL; } - size = snprintf(buf, buflen, "%s/%s", runtime_dir, dir) + 1; - if (size > (int) buflen) { + + size = snprintf(buf, buflen, "%s/%s", runtime_dir, dir); + if (size < 0) + return -errno; + if ((size_t) size >= buflen) { pw_log_error(NAME": path %s/%s too long", runtime_dir, dir); return -ENAMETOOLONG; } + if (stat(buf, &stat_buf) < 0) { res = -errno; if (res != -ENOENT) {