From: DL6ER <[email protected]>

dump_init() creates a missing dump file with a pcap header and sends
the header to a FIFO, but expects an existing regular file to start
with one. An empty file therefore fails the header read at EOF, and
startup aborts with "cannot access <file>: Success".

An empty file is easy to end up with, e.g. from touch or from a tool
that checks the path is writable by opening it for appending. Treat it
like a missing file and write the header, so recording starts instead
of refusing to.

Signed-off-by: DL6ER <[email protected]>
---
 src/dump.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/dump.c b/src/dump.c
index 0c668ba..14441de 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -75,6 +75,13 @@ void dump_init(void)
           !read_write(daemon->dumpfd, (void *)&header, sizeof(header), 
RW_WRITE))
        die(_("cannot open pipe %s: %s"), daemon->dump_file, EC_FILE);
     }
+  else if (S_ISREG(buf.st_mode) && buf.st_size == 0)
+    {
+      /* Existing but empty file, treat as new and add header. */
+      if  ((daemon->dumpfd = open(daemon->dump_file, O_APPEND | O_RDWR)) == -1 
||
+          !read_write(daemon->dumpfd, (void *)&header, sizeof(header), 
RW_WRITE))
+       die(_("cannot access %s: %s"), daemon->dump_file, EC_FILE);
+    }
   else if ((daemon->dumpfd = open(daemon->dump_file, O_APPEND | O_RDWR)) == -1 
||
           !read_write(daemon->dumpfd, (void *)&header, sizeof(header), 
RW_READ))
     die(_("cannot access %s: %s"), daemon->dump_file, EC_FILE);
-- 
2.43.0


_______________________________________________
Dnsmasq-discuss mailing list
[email protected]
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to