summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-03-01 15:00:28 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-03-02 11:46:56 +0100
commit3570b6bc8b4f136d07121b28cd79b6356e8e969b (patch)
tree60e91fd2423286d06e8184906287129ba93b781b
parentf51ed1db70abdbb909e81bc670ffdfa05f421257 (diff)
erec: Avoid passing negative offset to fseek()
If the initial call to ftell() fails, variable orig_offset is set to -1. Avoid passing this to fseek() later on. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/erec.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/erec.c b/src/erec.c
index 80806ffe..8de249de 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -121,7 +121,7 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
char buf[1024] = {};
char *pbuf = NULL;
unsigned int i, end;
- int l, ret;
+ int l;
off_t orig_offset = 0;
FILE *f = octx->output_fp;
@@ -136,12 +136,12 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
break;
case INDESC_FILE:
orig_offset = ftell(indesc->fp);
- fseek(indesc->fp, loc->line_offset, SEEK_SET);
- ret = fread(buf, 1, sizeof(buf) - 1, indesc->fp);
- if (ret > 0)
+ if (orig_offset >= 0 &&
+ !fseek(indesc->fp, loc->line_offset, SEEK_SET) &&
+ fread(buf, 1, sizeof(buf) - 1, indesc->fp) > 0 &&
+ !fseek(indesc->fp, orig_offset, SEEK_SET))
*strchrnul(buf, '\n') = '\0';
line = buf;
- fseek(indesc->fp, orig_offset, SEEK_SET);
break;
case INDESC_INTERNAL:
case INDESC_NETLINK: