On 11/13/26 12:21, Aditya Merchant wrote:
In pasta_netns_quit_inotify_handler(), we compare the name of each event we read with the base name of the namespace, but we don't make sure that the buffer we read events into is zero-terminated. Events without a name, such as the IN_IGNORED we get once the watch is removed, also have no name to compare: for those, ev->name points past the end of the event.
Terminate the buffer, as wait_for_socket() in passt-repair does, and skip events without a name.
Suggested-by: Stefano Brivio
Signed-off-by: Aditya Merchant
Reviewed-by: Laurent Vivier
--- pasta.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/pasta.c b/pasta.c index 4cd58fd..5ef678d 100644 --- a/pasta.c +++ b/pasta.c @@ -537,10 +537,13 @@ void pasta_netns_quit_inotify_handler(const struct ctx *c, int inotify_fd) if ((n = read(inotify_fd, buf, sizeof(buf))) < (ssize_t)sizeof(*ev)) return;
+ /* cppcheck-suppress [negativeIndex, unmatchedSuppression] */ + buf[n - 1] = '\0'; for (p = buf; p < buf + n; p += sizeof(*ev) + ev->len) { ev = (const struct inotify_event *)p;
- if (!strncmp(ev->name, c->netns_base, sizeof(c->netns_base))) { + if (ev->len && + !strncmp(ev->name, c->netns_base, sizeof(c->netns_base))) { info("Namespace %s is gone, exiting", c->netns_base); passt_exit(EXIT_SUCCESS); }