]> git.ipfire.org Git - thirdparty/nftables.git/commit
erec: Review erec_print()
authorPhil Sutter <phil@nwl.cc>
Fri, 13 Apr 2018 14:52:24 +0000 (16:52 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 14 Apr 2018 11:53:02 +0000 (13:53 +0200)
commit2f86dd5a43baf22a6d27fd74f38da37aa28bbaf8
treea78f5fd309f01572c381eed48d19d18911d580a5
parent3e4d73cf00d919422e31037c967371e2563801bc
erec: Review erec_print()

A new requirement to erec for the upcoming JSON support is printing
records with file input descriptors without open stream. The approach is
to treat 'name' field as file name, open it, extract the offending line
and close it again.

Further changes to libnftables input parsing routines though have shown
that the whole concept of file pointer reuse in erec is tedious and not
worth keeping:

* Closed files are to be supported as well, so there needs to be
  fallback code for opening the file anyway.

* When input descriptor is duplicated from parser state into an error
  record, the file pointer is copied as well. Therefore care has to be
  taken to not free the parser state before any error records have been
  printed. This is the only point where old and duplicated input
  descriptors are connected.

Therefore drop struct input_descriptor's 'fp' field and just always open
the file by name. This way also the old stream offset doesn't have to be
restored after reading.

While being at it, this patch fixes two other (potential) problems:

* If the offending line from input contains tabs, add them at the right
  position in the marker buffer as well to avoid misalignment.

* The input file may not be seekable (/dev/stdin for instance), so skip
  printing of offending line and markers if it couldn't be read
  properly.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/nftables.h
src/erec.c
src/scanner.l