From 3cce196045a0e5e12d61d50d0c9a5f72c7277904 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Wed, 26 Aug 2026 15:16:33 +0200 Subject: [PATCH] Stop RecordObjectCompare from dereferencing a NULL target RecordObjectWrite leaves target NULL for every entry that is not a symlink, while RecordObjectUnpack always produces a string, empty in that case. RecordObjectCompare handed both straight to strcmp. Nothing reaches it today because diff only compares records parsed from files, but comparing a record built from the live filesystem against the one stored for the same path is exactly what verify() will do, and it crashes as soon as the earlier fields match: Segmentation fault (core dumped) Treat NULL and "" as the same value for both path and target. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx --- src/types.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/types.c b/src/types.c index 2cfe8a3..1780581 100644 --- a/src/types.c +++ b/src/types.c @@ -187,6 +187,12 @@ static int cmp_intmax(intmax_t a, intmax_t b) { return (a < b) ? -1 : (a > b) ? 1 : 0; } +/* A record built by RecordObjectWrite leaves target NULL for anything that is + not a symlink, while one built by RecordObjectUnpack always holds a string, + empty in that case. Treat the two as the same value instead of handing NULL + to strcmp. */ +static const char *or_empty(const char *s) { return (s != NULL) ? s : ""; } + static char file_type(mode_t mode) { if (S_ISREG(mode)) return 'F'; @@ -383,13 +389,13 @@ int RecordObjectCompare(const struct RecordObject *self, if (err) *err = FINGERPRINT; } else { - int retp = strcmp(self->path, other->path); + int retp = strcmp(or_empty(self->path), or_empty(other->path)); if (retp != 0) { exit_code = retp; if (err) *err = PATH; } else { - int rett = strcmp(self->target, other->target); + int rett = strcmp(or_empty(self->target), or_empty(other->target)); if (rett != 0) { exit_code = rett; if (err)