mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
This commit is contained in:
10
src/types.c
10
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)
|
||||
|
||||
Reference in New Issue
Block a user