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