All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Edwin Török" <edvin.torok@citrix.com>,
	"Christian Lindig" <christian.lindig@citrix.com>,
	"David Scott" <dave@recoil.org>, "Rob Hoes" <Rob.Hoes@citrix.com>
Subject: [PATCH 8/8] tools/oxenstored/syslog: Avoid potential NULL dereference
Date: Tue, 22 Nov 2022 15:20:43 +0000	[thread overview]
Message-ID: <20221122152043.8518-9-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20221122152043.8518-1-andrew.cooper3@citrix.com>

From: Edwin Török <edvin.torok@citrix.com>

strdup() may return NULL.  Check for this before passing to syslog().

Drop const from c_msg.  It is bogus, as demonstrated by the need to cast to
void * in order to free the memory.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
---
CC: Christian Lindig <christian.lindig@citrix.com>
CC: David Scott <dave@recoil.org>
CC: Edwin Torok <edvin.torok@citrix.com>
CC: Rob Hoes <Rob.Hoes@citrix.com>
---
 tools/ocaml/xenstored/syslog_stubs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/ocaml/xenstored/syslog_stubs.c b/tools/ocaml/xenstored/syslog_stubs.c
index 875d48ad57eb..e16c3a9491d0 100644
--- a/tools/ocaml/xenstored/syslog_stubs.c
+++ b/tools/ocaml/xenstored/syslog_stubs.c
@@ -14,6 +14,7 @@
 
 #include <syslog.h>
 #include <string.h>
+#include <caml/fail.h>
 #include <caml/mlvalues.h>
 #include <caml/memory.h>
 #include <caml/alloc.h>
@@ -35,14 +36,16 @@ static int __syslog_facility_table[] = {
 value stub_syslog(value facility, value level, value msg)
 {
 	CAMLparam3(facility, level, msg);
-	const char *c_msg = strdup(String_val(msg));
+	char *c_msg = strdup(String_val(msg));
 	int c_facility = __syslog_facility_table[Int_val(facility)]
 	               | __syslog_level_table[Int_val(level)];
 
+	if ( !c_msg )
+		caml_raise_out_of_memory();
 	caml_enter_blocking_section();
 	syslog(c_facility, "%s", c_msg);
 	caml_leave_blocking_section();
 
-	free((void*)c_msg);
+	free(c_msg);
 	CAMLreturn(Val_unit);
 }
-- 
2.11.0



      parent reply	other threads:[~2022-11-22 15:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 15:20 [PATCH 0/8] Oxenstored live update fixes Andrew Cooper
2022-11-22 15:20 ` [PATCH 1/8] tools/oxenstored: Fix incorrect scope after an if statement Andrew Cooper
2022-11-23 14:50   ` Andrew Cooper
2022-11-22 15:20 ` [PATCH 2/8] tools/ocaml/evtchn: OCaml 5 support, fix potential resource leak Andrew Cooper
2022-11-22 15:20 ` [PATCH 3/8] tools/ocaml/evtchn: Add binding for xenevtchn_fdopen() Andrew Cooper
2022-11-22 15:20 ` [PATCH 4/8] tools/ocaml/evtchn: Extend the init() binding with a cloexec flag Andrew Cooper
2022-11-22 15:20 ` [PATCH 5/8] tools/oxenstored: Keep /dev/xen/evtchn open across live update Andrew Cooper
2022-11-23 10:59   ` Christian Lindig
2022-11-22 15:20 ` [PATCH 6/8] tools/oxenstored: Log live update issues at warning level Andrew Cooper
2022-11-22 15:20 ` [PATCH 7/8] tools/oxenstored: Set uncaught exception handler Andrew Cooper
2022-11-22 15:20 ` Andrew Cooper [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

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

  git send-email \
    --in-reply-to=20221122152043.8518-9-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Rob.Hoes@citrix.com \
    --cc=christian.lindig@citrix.com \
    --cc=dave@recoil.org \
    --cc=edvin.torok@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.