pam-util: fix pam_syslog_pam_error() format string
authorLennart Poettering <lennart@poettering.net>
Tue, 28 Nov 2023 10:05:52 +0000 (11:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 28 Nov 2023 15:36:51 +0000 (15:36 +0000)
To cut off a string at some position we must set the "precision" not the
field width in format strings.

This led to some assert()s being hit where they really should not be.

src/shared/pam-util.c

index 37945ba..1057104 100644 (file)
@@ -39,7 +39,8 @@ int pam_syslog_pam_error(pam_handle_t *handle, int level, int error, const char
                         pamerr = "n/a";  /* We cannot have any formatting chars */
 
                 char buf[p - format + strlen(pamerr) + 1];
-                xsprintf(buf, "%*s%s", (int)(p - format), format, pamerr);
+                xsprintf(buf, "%.*s%s", (int)(p - format), format, pamerr);
+
                 DISABLE_WARNING_FORMAT_NONLITERAL;
                 pam_vsyslog(handle, level, buf, ap);
                 REENABLE_WARNING;