diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-04-21 21:15:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-04-21 21:15:24 -0700 |
commit | 368a4d05039d41eb31120f8624b9cf7037035d2e (patch) | |
tree | 9b064ccd97c5cdc0c0d946ab6efde6a9b48375fe /syslog.c | |
parent | c2374487d235c08b71762d2ceb8645d18481c97f (diff) | |
download | txr-368a4d05039d41eb31120f8624b9cf7037035d2e.tar.gz txr-368a4d05039d41eb31120f8624b9cf7037035d2e.tar.bz2 txr-368a4d05039d41eb31120f8624b9cf7037035d2e.zip |
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.
Diffstat (limited to 'syslog.c')
-rw-r--r-- | syslog.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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; } |