Skip to content

Commit 668dc5c

Browse files
committed
fix(watcher): never hand qsort a NULL array in the SVN observation core
A status document with no content candidates (only clean entries, externals or property changes) left the candidate array NULL, and fingerprint_candidates sorted it anyway. glibc declares qsort's base nonnull even for a zero count, so the trapping UBSan leg aborts there; macOS and recovering UBSan only print or ignore it. Sort only when there are at least two candidates. parse_clean_props_and_externals_are_not_local_changes reaches this path: RED on the Linux arm64 GCC leg built with -fno-sanitize-recover=undefined before the guard, GREEN after. Refs #1127 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 0a5b30b commit 668dc5c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/watcher/svn_state.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,12 @@ static int walk_candidates(svn_walk_t *walk, candidate_list_t *candidates) {
11731173
}
11741174

11751175
static int fingerprint_candidates(parser_t *parser, cbm_svn_observation_t *observation) {
1176-
qsort(parser->candidates.paths, parser->candidates.count, sizeof(*parser->candidates.paths),
1177-
candidate_compare);
1176+
/* With no candidates the array is NULL, and glibc declares qsort's base
1177+
* nonnull even for a zero count. */
1178+
if (parser->candidates.count > 1) {
1179+
qsort(parser->candidates.paths, parser->candidates.count, sizeof(*parser->candidates.paths),
1180+
candidate_compare);
1181+
}
11781182
svn_walk_t walk = {0};
11791183
walk.root = parser->root;
11801184
int result = 0;

‎tests/test_svn_state.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ TEST(parse_rejects_declarations_and_truncated_documents) {
198198
PASS();
199199
}
200200

201+
/* No entry here needs its content read, so the candidate list stays empty:
202+
* this also guards against sorting a NULL array. That guard binds only on the
203+
* trapping UBSan leg (-fno-sanitize-recover=undefined); macOS and recovering
204+
* UBSan pass without it. */
201205
TEST(parse_clean_props_and_externals_are_not_local_changes) {
202206
wc_fixture_t fixture;
203207
ASSERT_TRUE(wc_fixture_init(&fixture, "cbm_svn_clean"));

0 commit comments

Comments
 (0)