]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: fix core dump if --enable-systemd
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Aug 2023 01:26:52 +0000 (18:26 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Aug 2023 01:27:27 +0000 (18:27 -0700)
Problem reported by Thorsten Kukuk <https://bugs.gnu.org/65617>.
* lib/readutmp.c (read_utmp_from_systemd):
Don’t assume session_ptr != NULL if num_sessions == 0.
In practice it can be null, and the man page OKs this behavior.

ChangeLog
lib/readutmp.c

index d4b2287307c898b6bd30bae43cca9e032633d61d..9c9c89638c0a75aa0c743168d44a132c8adf264f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-08-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+       readutmp: fix core dump if --enable-systemd
+       Problem reported by Thorsten Kukuk <https://bugs.gnu.org/65617>.
+       * lib/readutmp.c (read_utmp_from_systemd):
+       Don’t assume session_ptr != NULL if num_sessions == 0.
+       In practice it can be null, and the man page OKs this behavior.
+
 2023-08-30  Bruno Haible  <bruno@clisp.org>
 
        doc: Mention the module 'wchar-single'.
index 0173b7e0c127766761a03490fbfb439a56f98c78..e99158677c88e3044fee580aafcf744cba939a61 100644 (file)
@@ -795,7 +795,7 @@ read_utmp_from_systemd (idx_t *n_entries, STRUCT_UTMP **utmp_buf, int options)
     {
       char **sessions;
       int num_sessions = sd_get_sessions (&sessions);
-      if (num_sessions >= 0)
+      if (num_sessions > 0)
         {
           char **session_ptr;
           for (session_ptr = sessions; *session_ptr != NULL; session_ptr++)