All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] scanner: don't rely on fseek for input stream repositioning
@ 2019-07-21 10:18 Florian Westphal
  2019-07-30 11:55 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2019-07-21 10:18 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

It doesn't work when reading from a pipe, leading to parser
errors in case of 'cat foo | nft -f -', whereas 'nft -f < foo'
works fine.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1354
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/scanner.l | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/scanner.l b/src/scanner.l
index 4ed5f9241381..c1adcbddbd73 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -36,23 +36,28 @@
  */
 #define YY_INPUT(buf,result,max_size)						\
 {										\
-	long n = 0;								\
+	result = 0;								\
 	errno = 0;								\
-	while ((result = fread(buf, 1, max_size, yyin)) == 0 &&			\
-		ferror(yyin)) {							\
-		if (errno != EINTR) {						\
-			YY_FATAL_ERROR("input in flex scanner failed");		\
-			break;							\
+										\
+	while (result < max_size) {						\
+		int chr = fgetc(yyin);						\
+										\
+		if (chr != EOF) {						\
+			buf[result++] = chr;					\
+			if (chr == '\n' || chr == ' ')				\
+				break;						\
+			continue;						\
 		}								\
-		errno = 0;							\
-		clearerr(yyin);							\
-	}									\
-	if (result > 1 && !feof(yyin)) {					\
-		while (result > 1 && 						\
-		       (buf[result - 1] != '\n' &&  buf[result - 1] != ' '))	\
-			result--, n++;						\
-		result--, n++;							\
-		fseek(yyin, -n, SEEK_CUR);					\
+										\
+		if (ferror(yyin)) {						\
+			if (errno != EINTR) {					\
+				YY_FATAL_ERROR("input in flex scanner failed");	\
+				break;						\
+			}							\
+			errno = 0;						\
+			clearerr(yyin);						\
+		}								\
+		break;								\
 	}									\
 }
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nft] scanner: don't rely on fseek for input stream repositioning
  2019-07-21 10:18 [PATCH nft] scanner: don't rely on fseek for input stream repositioning Florian Westphal
@ 2019-07-30 11:55 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-30 11:55 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Sun, Jul 21, 2019 at 12:18:31PM +0200, Florian Westphal wrote:
> It doesn't work when reading from a pipe, leading to parser
> errors in case of 'cat foo | nft -f -', whereas 'nft -f < foo'
> works fine.
> 
> Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1354
> Signed-off-by: Florian Westphal <fw@strlen.de>

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-30 11:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-21 10:18 [PATCH nft] scanner: don't rely on fseek for input stream repositioning Florian Westphal
2019-07-30 11:55 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.