From aa7b1a4bd7d5d1c988abc1cad5f4efb6985ffdb5 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 24 Jun 2015 09:51:50 +0200 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- src/erec.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/erec.c') 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: -- cgit v1.2.3