diff options
author | Phil Sutter <phil@nwl.cc> | 2018-06-13 19:18:24 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-06-18 11:13:06 +0200 |
commit | 5ca7ad252366865225d5c59d297e71215b68f027 (patch) | |
tree | bc65b7eabe5487a5021c95c1eb500331b8eac474 | |
parent | 6be5ce8b6d8b43797098d7a0390756f940624a63 (diff) |
libnftables: Fix exit_cookie()
The output and error buffer feature depends on cookie->orig_fp to
indicate the current status of buffering: If it is set, a prior call to
init_cookie() is assumed. Though exit_cookie() missed to reset that
pointer to NULL. causing weird behaviour in applications if they do:
| nft = nft_ctx_new(0);
| nft_ctx_buffer_output(nft);
| nft_ctx_unbuffer_output(nft);
| nft_ctx_buffer_output(nft);
While being at it, apply the same fix to error path in init_cookie() as
well.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/libnftables.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/libnftables.c b/src/libnftables.c index 5bc7ba0d..dda986ca 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -198,6 +198,7 @@ static int init_cookie(struct cookie *cookie) cookie->fp = fopencookie(cookie, "w", cookie_fops); if (!cookie->fp) { cookie->fp = cookie->orig_fp; + cookie->orig_fp = NULL; return 1; } @@ -211,6 +212,7 @@ static int exit_cookie(struct cookie *cookie) fclose(cookie->fp); cookie->fp = cookie->orig_fp; + cookie->orig_fp = NULL; free(cookie->buf); cookie->buf = NULL; cookie->buflen = 0; |