summaryrefslogtreecommitdiffstats
path: root/lib/utils.c
diff options
context:
space:
mode:
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-09 13:35:36 +0300
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-28 13:19:02 +0300
commit404fcb1c102af07a6760a80fa994d20e9a4de7f7 (patch)
tree2327297df8b87204726d703da74fe49935cdd238 /lib/utils.c
parentd61cc219f6bd3c4ffc96239893a8ded9b5a83b30 (diff)
lib: avoid static buffers, use alloca() more
Signed-off-by: George Kiagiadakis <george.kiagiadakis@collabora.com>
Diffstat (limited to 'lib/utils.c')
-rw-r--r--lib/utils.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/utils.c b/lib/utils.c
index 4d91241..37bcce9 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -91,7 +91,6 @@ int icipc_construct_socket_path(const char *name, char *buf, size_t buf_size) {
bool path_is_absolute;
const char *runtime_dir = NULL;
struct passwd pwd, *result = NULL;
- char buffer[4096];
int name_size;
path_is_absolute = name[0] == '/';
@@ -105,8 +104,12 @@ int icipc_construct_socket_path(const char *name, char *buf, size_t buf_size) {
if (runtime_dir == NULL)
runtime_dir = getenv("USERPROFILE");
if (runtime_dir == NULL) {
+ long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (bufsize == -1)
+ bufsize = 4096;
+ char *buffer = alloca(bufsize);
if (getpwuid_r
- (getuid(), &pwd, buffer, sizeof(buffer),
+ (getuid(), &pwd, buffer, bufsize,
&result) == 0)
runtime_dir = result ? result->pw_dir : NULL;
}