public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 3/3] log: Match implicit va_start() with va_end() in vlogmsg()
Date: Tue,  7 Nov 2023 13:28:33 +0100	[thread overview]
Message-ID: <20231107122833.1673498-4-sbrivio@redhat.com> (raw)
In-Reply-To: <20231107122833.1673498-1-sbrivio@redhat.com>

According to C99, 7.15.1:

  Each invocation of the va_start and va_copy macros shall be matched
  by a corresponding invocation of the va_end macro in the same
  function

and the same applies to C11. I still have to come across a platform
where va_end() actually does something, but thus spake the standard.
This would be reported by Coverity as "Missing varargs init or
cleanup" (CWE-573).

Fixes: c0426ff10bc9 ("log: Add vlogmsg()")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 log.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/log.c b/log.c
index 95c4fa4..b206f72 100644
--- a/log.c
+++ b/log.c
@@ -67,6 +67,8 @@ void vlogmsg(int pri, const char *format, va_list ap)
 			logfile_write(pri, format, ap2);
 		else if (!(setlogmask(0) & LOG_MASK(LOG_DEBUG)))
 			passt_vsyslog(pri, format, ap2);
+
+		va_end(ap2);
 	}
 
 	if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) ||
-- 
@@ -67,6 +67,8 @@ void vlogmsg(int pri, const char *format, va_list ap)
 			logfile_write(pri, format, ap2);
 		else if (!(setlogmask(0) & LOG_MASK(LOG_DEBUG)))
 			passt_vsyslog(pri, format, ap2);
+
+		va_end(ap2);
 	}
 
 	if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) ||
-- 
2.39.2


  parent reply	other threads:[~2023-11-07 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 12:28 [PATCH 0/3] Minimal fixes for issues reported by static checkers Stefano Brivio
2023-11-07 12:28 ` [PATCH 1/3] netlink: Sequence numbers are actually 32 bits wide Stefano Brivio
2023-11-07 23:32   ` David Gibson
2023-11-07 12:28 ` [PATCH 2/3] port_fwd: Don't try to read bound ports from invalid file handles Stefano Brivio
2023-11-07 12:28 ` Stefano Brivio [this message]
2023-11-07 23:31   ` [PATCH 3/3] log: Match implicit va_start() with va_end() in vlogmsg() David Gibson

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

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

  git send-email \
    --in-reply-to=20231107122833.1673498-4-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).