nftables/SOURCES/0106-libnftables-skip-useable-checks-for-dev-stdin.patch
2026-08-26 08:03:54 -04:00

64 lines
2.2 KiB
Diff

From 36abb7d32f0f4af37112fb74b31a7235d029e3e3 Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Fri, 17 Jul 2026 11:10:08 +0200
Subject: [PATCH] libnftables: skip useable checks for /dev/stdin
JIRA: https://issues.redhat.com/browse/RHEL-190549
Upstream Status: nftables commit 477fd8218777b75bdfa3a5643f692adae4f002fe
commit 477fd8218777b75bdfa3a5643f692adae4f002fe
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Tue Jul 9 16:59:53 2024 +0200
libnftables: skip useable checks for /dev/stdin
/dev/stdin is a placeholder, read() from STDIN_FILENO is used to fetch
the standard input into a buffer.
Since 5c2b2b0a2ba7 ("src: error reporting with -f and read from stdin")
stdin is stored in a buffer to fix error reporting.
This patch requires: ("parser_json: use stdin buffer if available")
Fixes: 149b1c95d129 ("libnftables: refuse to open onput files other than named pipes or regular files")
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <psutter@redhat.com>
---
src/libnftables.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/libnftables.c b/src/libnftables.c
index 0dee1ba..8f8acd1 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -664,6 +664,7 @@ retry:
/* need to use stat() to, fopen() will block for named fifos and
* libjansson makes no checks before or after open either.
+ * /dev/stdin is *never* used, read() from STDIN_FILENO is used instead.
*/
static struct error_record *filename_is_useable(struct nft_ctx *nft, const char *name)
{
@@ -671,6 +672,9 @@ static struct error_record *filename_is_useable(struct nft_ctx *nft, const char
struct stat sb;
int err;
+ if (!strcmp(name, "/dev/stdin"))
+ return NULL;
+
err = stat(name, &sb);
if (err)
return error(&internal_location, "Could not open file \"%s\": %s\n",
@@ -681,9 +685,6 @@ static struct error_record *filename_is_useable(struct nft_ctx *nft, const char
if (type == S_IFREG || type == S_IFIFO)
return NULL;
- if (type == S_IFCHR && 0 == strcmp(name, "/dev/stdin"))
- return NULL;
-
return error(&internal_location, "Not a regular file: \"%s\"\n", name);
}