]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam_systemd: do no allocate the path of fixed length
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Jan 2019 08:53:34 +0000 (09:53 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Jan 2019 13:24:10 +0000 (14:24 +0100)
src/login/pam_systemd.c

index d466e509690b7ce1c164bc648d42272086441a38..a33d8f05c50fee73960af5dbed0680a15daa97f7 100644 (file)
@@ -28,6 +28,7 @@
 #include "path-util.h"
 #include "process-util.h"
 #include "socket-util.h"
+#include "stdio-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "util.h"
@@ -414,11 +415,9 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
         pam_get_item(handle, PAM_SERVICE, (const void**) &service);
         if (streq_ptr(service, "systemd-user")) {
-                _cleanup_free_ char *rt = NULL;
-
-                if (asprintf(&rt, "/run/user/"UID_FMT, pw->pw_uid) < 0)
-                        return PAM_BUF_ERR;
+                char rt[STRLEN("/run/user/") + DECIMAL_STR_MAX(uid_t)];
 
+                xsprintf(rt, "/run/user/"UID_FMT, pw->pw_uid);
                 if (validate_runtime_directory(handle, rt, pw->pw_uid)) {
                         r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0);
                         if (r != PAM_SUCCESS) {