Skip to content

Commit ca7c7f4

Browse files
committed
fix(test): realpath fortify abort + Windows compile in repo-path guard
glibc _FORTIFY_SOURCE aborts realpath() into a sub-PATH_MAX buffer regardless of the actual path length, and Windows has no realpath at all. Size the buffers at PATH_MAX and skip the guard on Windows (the DeusData#794 canonicalization logic is platform-independent; the four Unix legs carry it). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 97fcae0 commit ca7c7f4

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎tests/test_index_resilience.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222
#include <time.h>
23+
#include <limits.h>
24+
25+
/* glibc's _FORTIFY_SOURCE realpath() aborts unless the output buffer is at
26+
* least PATH_MAX bytes, independent of the actual path length. */
27+
#ifndef PATH_MAX
28+
#define PATH_MAX 4096
29+
#endif
2330

2431
/* Sleep before rewriting a fixture so its mtime_ns strictly increases and the
2532
* incremental change classifier reliably sees the edit (10 ms). */
@@ -661,6 +668,12 @@ TEST(index_not_indexed_by_design_reported) {
661668
* "root"), an absolute stored root_path, and a DB that persists and stays
662669
* queryable after the run. */
663670
TEST(index_relative_repo_path_canonicalized) {
671+
#ifdef _WIN32
672+
/* realpath/chdir are POSIX; the assertions are POSIX-path-shaped. The
673+
* #794 canonicalization logic under guard is platform-independent, so
674+
* the four Unix legs carry this regression guard. */
675+
SKIP_PLATFORM("POSIX-only guard (realpath/chdir); #794 logic is platform-independent");
676+
#else
664677
RProj lp;
665678
memset(&lp, 0, sizeof(lp));
666679
snprintf(lp.tmpdir, sizeof(lp.tmpdir), "/tmp/cbm_resil_XXXXXX");
@@ -672,7 +685,7 @@ TEST(index_relative_repo_path_canonicalized) {
672685

673686
/* Resolve the canonical form of tmpdir (macOS: /tmp -> /private/tmp) so
674687
* the derived-name and stored-root assertions compare like with like. */
675-
char canon[700];
688+
char canon[PATH_MAX];
676689
if (!realpath(lp.tmpdir, canon)) {
677690
snprintf(canon, sizeof(canon), "%s", lp.tmpdir);
678691
}
@@ -697,7 +710,7 @@ TEST(index_relative_repo_path_canonicalized) {
697710
}
698711

699712
/* chdir into the repo and index "." — restore cwd immediately after. */
700-
char oldcwd[700];
713+
char oldcwd[PATH_MAX];
701714
if (!getcwd(oldcwd, sizeof(oldcwd))) {
702715
FAIL("getcwd failed");
703716
}
@@ -745,6 +758,7 @@ TEST(index_relative_repo_path_canonicalized) {
745758

746759
rh_cleanup(&lp, store);
747760
PASS();
761+
#endif /* !_WIN32 */
748762
}
749763

750764
SUITE(index_resilience) {

0 commit comments

Comments
 (0)