diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-04-28 11:23:26 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-04-28 12:59:00 +0200 |
commit | bb91cd49ae8d4a471b9c4c0c8ab86bb3940f7d69 (patch) | |
tree | 71673c44782ff85e01ab783a59a5764abe803858 /src/internal.h | |
parent | 3448b27ad573982c4e0e7ab2cc3b34edac3eea82 (diff) |
src: fix broken output handling
In 948fa3b ("Extend accounting capabilities to support quotas"), the
error handling of snprintf is incorrect since this function may
return -1 on error. Add a new SNPRINTF_CHECK() macro to offload the
complicated handling of snprintf.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/internal.h')
-rw-r--r-- | src/internal.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/internal.h b/src/internal.h index 2106401..f0cc2e1 100644 --- a/src/internal.h +++ b/src/internal.h @@ -21,4 +21,15 @@ # endif #endif +#define SNPRINTF_CHECK(ret, rem, offset, len) \ +do { \ + if (ret < 0) \ + return ret; \ + len += ret; \ + if (ret > rem) \ + ret = rem; \ + offset += ret; \ + rem -= ret; \ +} while (0) + #endif |