From 368a4d05039d41eb31120f8624b9cf7037035d2e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 21 Apr 2016 21:15:24 -0700 Subject: Strengthen against resource leaks upon exceptions. * glob.c (glob_wrap): Perform argument conversions that might throw before allocating UTF-8 string. * parser.y (text): In the action for SPACE, the lexeme is not needed so free($1) right away. If regex_compile were to throw an exception, that lexeme will leak. * socket.c (getaddrinfo_wrap): Harden against leakage of node_u8 and service_u8 strings with an unwind block. For instance, the hints structure could contain bad values which cause addrinfo_in to throw. * stream.c (make_string_byte_input_stream): Perform possibly throwing argument conversions before allocating resources. * sysif.c (mkdir_wrap, mknod_wrap, chmod_wrap, symlink_wrap, link_wrap, setenv_wrap, crypt_wrap): Likewise. * syslog.c (openlog_wrap, syslog_wrapv): Likewise. --- syslog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'syslog.c') diff --git a/syslog.c b/syslog.c index d5766f95..e0242729 100644 --- a/syslog.c +++ b/syslog.c @@ -91,13 +91,14 @@ void syslog_init(void) val openlog_wrap(val wident, val optmask, val facility) { static char *ident; + cnum coptmask = c_num(default_arg(optmask, zero)); + cnum cfacility = c_num(default_arg(facility, num_fast(LOG_USER))); char *old_ident = ident; - optmask = default_arg(optmask, zero); - facility = default_arg(facility, num_fast(LOG_USER)); - ident = utf8_dup_to(c_str(wident)); - openlog(ident, c_num(optmask), c_num(facility)); + + openlog(ident, coptmask, cfacility); + free(old_ident); return nil; @@ -111,8 +112,9 @@ val setlogmask_wrap(val mask) val syslog_wrapv(val prio, val fmt, struct args *args) { val text = formatv(nil, fmt, args); + cnum cprio = c_num(prio); char *u8text = utf8_dup_to(c_str(text)); - syslog(c_num(prio), "%s", u8text); + syslog(cprio, "%s", u8text); return nil; } -- cgit v1.2.3