Blame SOURCES/0008-erec-Avoid-passing-negative-offset-to-fseek.patch

a05102
From 76bfabfffc6d10f3b55c896dc7afc24fa3a71fc9 Mon Sep 17 00:00:00 2001
a05102
From: Phil Sutter <psutter@redhat.com>
a05102
Date: Wed, 20 Jun 2018 09:22:47 +0200
a05102
Subject: [PATCH] erec: Avoid passing negative offset to fseek()
a05102
a05102
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1504157
a05102
Upstream Status: nftables commit 3570b6bc8b4f1
a05102
a05102
commit 3570b6bc8b4f136d07121b28cd79b6356e8e969b
a05102
Author: Phil Sutter <phil@nwl.cc>
a05102
Date:   Thu Mar 1 15:00:28 2018 +0100
a05102
a05102
    erec: Avoid passing negative offset to fseek()
a05102
a05102
    If the initial call to ftell() fails, variable orig_offset is set to -1.
a05102
    Avoid passing this to fseek() later on.
a05102
a05102
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a05102
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
a05102
---
a05102
 src/erec.c | 10 +++++-----
a05102
 1 file changed, 5 insertions(+), 5 deletions(-)
a05102
a05102
diff --git a/src/erec.c b/src/erec.c
a05102
index 80806ff..8de249d 100644
a05102
--- a/src/erec.c
a05102
+++ b/src/erec.c
a05102
@@ -121,7 +121,7 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
a05102
 	char buf[1024] = {};
a05102
 	char *pbuf = NULL;
a05102
 	unsigned int i, end;
a05102
-	int l, ret;
a05102
+	int l;
a05102
 	off_t orig_offset = 0;
a05102
 	FILE *f = octx->output_fp;
a05102
 
a05102
@@ -136,12 +136,12 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
a05102
 		break;
a05102
 	case INDESC_FILE:
a05102
 		orig_offset = ftell(indesc->fp);
a05102
-		fseek(indesc->fp, loc->line_offset, SEEK_SET);
a05102
-		ret = fread(buf, 1, sizeof(buf) - 1, indesc->fp);
a05102
-		if (ret > 0)
a05102
+		if (orig_offset >= 0 &&
a05102
+		    !fseek(indesc->fp, loc->line_offset, SEEK_SET) &&
a05102
+		    fread(buf, 1, sizeof(buf) - 1, indesc->fp) > 0 &&
a05102
+		    !fseek(indesc->fp, orig_offset, SEEK_SET))
a05102
 			*strchrnul(buf, '\n') = '\0';
a05102
 		line = buf;
a05102
-		fseek(indesc->fp, orig_offset, SEEK_SET);
a05102
 		break;
a05102
 	case INDESC_INTERNAL:
a05102
 	case INDESC_NETLINK:
a05102
-- 
a05102
1.8.3.1
a05102