diff options
author | Daiki Ueno <dueno@redhat.com> | 2018-05-29 16:37:07 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2018-05-30 15:39:26 +0200 |
commit | ccb0c207964189742e97acfd817fb3c6b99e5865 (patch) | |
tree | 6cf97054cd645258f56df5387eaf915fcb29cb73 /common | |
parent | 71b62aa1cdbdec3724c8e451f621309994dc59a0 (diff) |
common: Fix runtime directory detection when given prefix is long
Diffstat (limited to 'common')
-rw-r--r-- | common/runtime.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/common/runtime.c b/common/runtime.c index 316c5be..71fd553 100644 --- a/common/runtime.c +++ b/common/runtime.c @@ -39,6 +39,7 @@ #include "compat.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> #ifdef OS_UNIX @@ -58,7 +59,7 @@ p11_get_runtime_directory (char **directoryp) char *directory; #ifdef OS_UNIX const char * const *bases = _p11_runtime_bases; - char prefix[13 + 1 + 20 + 6 + 1]; + char *prefix; uid_t uid; struct stat sb; struct passwd pwbuf, *pw; @@ -84,15 +85,14 @@ p11_get_runtime_directory (char **directoryp) uid = getuid (); for (i = 0; bases[i] != NULL; i++) { - snprintf (prefix, sizeof prefix, "%s/user/%u", - bases[i], (unsigned int) uid); + if (asprintf (&prefix, "%s/user/%u", + bases[i], (unsigned int) uid) < 0) + return CKR_HOST_MEMORY; if (stat (prefix, &sb) != -1 && S_ISDIR (sb.st_mode)) { - directory = strdup (prefix); - if (!directory) - return CKR_HOST_MEMORY; - *directoryp = directory; + *directoryp = prefix; return CKR_OK; } + free (prefix); } #endif |