diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2007-05-28 12:46:38 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2007-05-28 12:46:38 +0000 |
commit | ad922a36f5c5f92568055062b88d569928a27834 (patch) | |
tree | 172597ad35bc45f5b5d82244c70e6aeea69ddfcf /ulogd/extensions/ulogd_BASE.c | |
parent | a04029553ce3bfbae039becebaef04a0ea0ae1ab (diff) |
Patches from Marius Tomaschewski <mt@suse.de>:
- Fixed sigterm_handler to close logfile and then call output_plugin->fini. The output_plugin->fini function may still use the logger (e.g. sqlite3 does), what causes a SEGV (really happens in case of sqlite3 db init error - as far as I remember)
- Changed sighup_handler_print to not to call exit(2) on reopen failure, but try to reopen and fallback to continue using old descriptor on failure.
- Fixed mac output in ulogd_BASE.c
- Added explicit termination of the hostname buffer: "[...] if namelen is an insufficient length to hold the host name, then the returned name is truncated and it is unspecified whether the returned name is null-terminated. [...]" as SUSv2 specifies.
- Added to print "\n" after ULOGD_RET_NONE type as well after an unspecified type. See example above at extensions/ulogd_BASE.c.
- Fixed to set the '\0' at the end and not behind the buffer.
Diffstat (limited to 'ulogd/extensions/ulogd_BASE.c')
-rw-r--r-- | ulogd/extensions/ulogd_BASE.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ulogd/extensions/ulogd_BASE.c b/ulogd/extensions/ulogd_BASE.c index f8abd70..0fd921c 100644 --- a/ulogd/extensions/ulogd_BASE.c +++ b/ulogd/extensions/ulogd_BASE.c @@ -32,6 +32,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/socket.h> #include <netinet/ip.h> #include <netinet/in.h> @@ -62,12 +63,14 @@ static ulog_iret_t *_interp_raw(ulog_interpreter_t *ip, ulog_packet_msg_t *pkt) { unsigned char *p; - int i; - char *buf, *oldbuf = NULL; + int i, tmp, len = 0; + char *buf, *ptr = NULL; ulog_iret_t *ret = ip->result; + size_t siz; if (pkt->mac_len) { - buf = (char *) malloc(3 * pkt->mac_len + 1); + siz = 3 * pkt->mac_len + 1; + buf = (char *) malloc(siz); if (!buf) { ulogd_log(ULOGD_ERROR, "OOM!!!\n"); return NULL; @@ -75,9 +78,14 @@ static ulog_iret_t *_interp_raw(ulog_interpreter_t *ip, *buf = '\0'; p = pkt->mac; - oldbuf = buf; - for (i = 0; i < pkt->mac_len; i++, p++) - sprintf(buf, "%s%02x%c", oldbuf, *p, i==pkt->mac_len-1 ? ' ':':'); + ptr = buf; + for (i = 0; i < pkt->mac_len; i++, p++) { + tmp = snprintf(ptr+len, siz-len, "%02x%s", + *p, i==pkt->mac_len-1 ? "":":"); + if (tmp == -1) + break; + len += tmp; + } ret[0].value.ptr = buf; ret[0].flags |= ULOGD_RETF_VALID; } |