[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 8/8] tools/oxenstored/syslog: Avoid potential NULL dereference


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 22 Nov 2022 15:20:43 +0000
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>
  • Delivery-date: Tue, 22 Nov 2022 15:21:12 +0000
  • Ironport-data: A9a23:C1j3r6iJJLRle6uVytR2BSxrX161MhAKZh0ujC45NGQN5FlHY01je htvC2nXOauOMWTxLox2OtmzpElTuJfWmoA2SFQ+qyBgRiIb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmUpH1QMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWs0N8klgZmP6oS5QWEzyV94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tQgCjFTMCqswNuq2ZzicLh2qsB+Hcb0adZ3VnFIlVk1DN4jSJHHBa7L+cVZzHE7gcUm8fT2P pRDL2A1NVKZPkMJagx/5JEWxY9EglHWdTFCpU3Tjq0w+2XJlyR60aT3McqTcduPLSlQthbF/ Tyeojmjav0cHO6t5Aja016OuuzgmjLed8FMDpG6/9c/1TV/wURMUUZLBDNXu8KRhkegVvpFJ kcT+y5oqrI9nGS7Q9+4UxCmrXqsuh8HR8EWA+A88BuKyKff/0CeHGdsc9JaQIV47olsH2Vsj wLX2YOybdByjFGLYUq/9+nKlxz1ADQMAzY4NDUoSVY07Ma29enfkSnzosZf/L+d14OrSGmgm Gnb/UDSlJ1I05dVivzTEUTvxmv1+8OXFlNdChD/BDrN0+9vWGKyi2VEA3D/5O0IEouWR0LpU JMsy5nHt7Bm4X1geUWwrAQx8FKBvazt3MX02wIHInXY323FFr7KVdk4DMtCDEloKN0YXjTif VXevwhcjLcKYiX7NfIqPd3rVZp1pUQFKTgCfqmEBuein7ArLFPXlM2QTRP4M5/RfLgEzvhkZ MbznTeEBncGE6V3pAdatM9EuYLGB0kWmwvueHwM5076jerFPSfPEd/o8jKmN4gE0U9Nmy2Nm /43CidA40w3vDHWCsUPzbMuEA==
  • Ironport-hdrordr: A9a23:MGh4ja6DI60Kw1nAhgPXwM7XdLJyesId70hD6qhwISY7TiX+rb HJoB17726StN9/YhAdcLy7VZVoBEmsl6KdgrNhWYtKPjOHhILAFugLhuHfKn/bakjDH4ZmpN 5dmsNFZuEYY2IXsS+D2njaL+od
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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

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@xxxxxxxxxx>
Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
---
CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
CC: David Scott <dave@xxxxxxxxxx>
CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>
---
 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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.