Blame SOURCES/0033-libnftables-Fix-exit_cookie.patch

bacbc8
From 742f52eeb2bf587abb89dbd81ea0f6f58a9d7309 Mon Sep 17 00:00:00 2001
bacbc8
From: Phil Sutter <phil@nwl.cc>
bacbc8
Date: Wed, 13 Jun 2018 19:18:24 +0200
bacbc8
Subject: [PATCH] libnftables: Fix exit_cookie()
bacbc8
bacbc8
The output and error buffer feature depends on cookie->orig_fp to
bacbc8
indicate the current status of buffering: If it is set, a prior call to
bacbc8
init_cookie() is assumed. Though exit_cookie() missed to reset that
bacbc8
pointer to NULL. causing weird behaviour in applications if they do:
bacbc8
bacbc8
| nft = nft_ctx_new(0);
bacbc8
| nft_ctx_buffer_output(nft);
bacbc8
| nft_ctx_unbuffer_output(nft);
bacbc8
| nft_ctx_buffer_output(nft);
bacbc8
bacbc8
While being at it, apply the same fix to error path in init_cookie() as
bacbc8
well.
bacbc8
bacbc8
Signed-off-by: Phil Sutter <phil@nwl.cc>
bacbc8
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
bacbc8
(cherry picked from commit 5ca7ad252366865225d5c59d297e71215b68f027)
bacbc8
Signed-off-by: Phil Sutter <psutter@redhat.com>
bacbc8
---
bacbc8
 src/libnftables.c | 2 ++
bacbc8
 1 file changed, 2 insertions(+)
bacbc8
bacbc8
diff --git a/src/libnftables.c b/src/libnftables.c
bacbc8
index 848c9cba65657..640693df93755 100644
bacbc8
--- a/src/libnftables.c
bacbc8
+++ b/src/libnftables.c
bacbc8
@@ -195,6 +195,7 @@ static int init_cookie(struct cookie *cookie)
bacbc8
 	cookie->fp = fopencookie(cookie, "w", cookie_fops);
bacbc8
 	if (!cookie->fp) {
bacbc8
 		cookie->fp = cookie->orig_fp;
bacbc8
+		cookie->orig_fp = NULL;
bacbc8
 		return 1;
bacbc8
 	}
bacbc8
 
bacbc8
@@ -208,6 +209,7 @@ static int exit_cookie(struct cookie *cookie)
bacbc8
 
bacbc8
 	fclose(cookie->fp);
bacbc8
 	cookie->fp = cookie->orig_fp;
bacbc8
+	cookie->orig_fp = NULL;
bacbc8
 	free(cookie->buf);
bacbc8
 	cookie->buf = NULL;
bacbc8
 	cookie->buflen = 0;
bacbc8
-- 
bacbc8
2.21.0
bacbc8