summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Leblond <eric@regit.org>2015-06-24 09:51:50 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2015-06-30 01:32:00 +0200
commitaa7b1a4bd7d5d1c988abc1cad5f4efb6985ffdb5 (patch)
treeac991463567d296678c395828f073979bc37f200
parent1f3b7755dd27c8a58868cfac8cdbe7690160f9f3 (diff)
erec: fix logic when reading from file
In case we are reading the rules from a file we need to reset the file descriptor to the original position when calling erec_print. This was not the case in previous code and was leading to valid file to be seen as invalid when treated in debug mode. Signed-off-by: Eric Leblond <eric@regit.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/erec.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/erec.c b/src/erec.c
index 8abed4d9..d5142307 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -86,6 +86,7 @@ void erec_print(FILE *f, const struct error_record *erec)
char *pbuf = NULL;
unsigned int i, end;
int l, ret;
+ off_t orig_offset = 0;
switch (indesc->type) {
case INDESC_BUFFER:
@@ -94,11 +95,13 @@ void erec_print(FILE *f, const struct error_record *erec)
break;
case INDESC_FILE:
memset(buf, 0, sizeof(buf));
+ orig_offset = lseek(indesc->fd, 0, SEEK_CUR);
lseek(indesc->fd, loc->line_offset, SEEK_SET);
ret = read(indesc->fd, buf, sizeof(buf) - 1);
if (ret > 0)
*strchrnul(buf, '\n') = '\0';
line = buf;
+ lseek(indesc->fd, orig_offset, SEEK_SET);
break;
case INDESC_INTERNAL:
case INDESC_NETLINK: