bug-coreutils@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, 65617-done@debbugs.gnu.org
Cc: Thorsten Kukuk <kukuk@suse.com>, Paul Eggert <eggert@cs.ucla.edu>
Subject: bug#65617: coreutils 9.4: seg.fault in readutmp with systemd
Date: Thu, 31 Aug 2023 11:37:05 +0200	[thread overview]
Message-ID: <2519178.4XsnlVU6TS@nimes> (raw)
In-Reply-To: <474722d1-d314-09b1-9302-2c920a8bed12@cs.ucla.edu>

Paul Eggert wrote:
> I installed the attached patch into Gnulib 
> and this should appear in the next coreutils release.

Unfortunately, this patch introduces a memory leak: If
num_sessions == 0 and sessions != NULL (which can happen, according
to the man page), we need to call free (sessions).

This patch fixes it.


2023-08-31  Bruno Haible  <bruno@clisp.org>

	readutmp: Fix memory leak introduced by last commit.
	* lib/readutmp.c (read_utmp_from_systemd): If num_sessions == 0 and
	sessions != NULL, do call free (sessions).

diff --git a/lib/readutmp.c b/lib/readutmp.c
index e99158677c..ec09feb59b 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -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 && sessions != NULL)
         {
           char **session_ptr;
           for (session_ptr = sessions; *session_ptr != NULL; session_ptr++)







      reply	other threads:[~2023-08-31  9:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 11:21 bug#65617: coreutils 9.4: seg.fault in readutmp with systemd Thorsten Kukuk via GNU coreutils Bug Reports
2023-08-31  1:29 ` Paul Eggert
2023-08-31  9:37   ` Bruno Haible [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-coreutils

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2519178.4XsnlVU6TS@nimes \
    --to=bruno@clisp.org \
    --cc=65617-done@debbugs.gnu.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=kukuk@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).