@@ -4373,20 +4373,34 @@ static yyjson_doc *enrich_node_properties(yyjson_mut_doc *doc, yyjson_mut_val *o
43734373 * the search path (attach_result_source) route through it, so a result whose
43744374 * indexed path escapes the project root — via a `..` segment, or a symlink /
43754375 * Windows junction picked up during discovery — is never read back out. */
4376+ /* Canonicalize `path` (resolve symlinks/junctions and `..`) into `out`
4377+ * (>= CBM_SZ_4K bytes); returns true on success. Isolating the per-OS resolver
4378+ * keeps cbm_path_within_root's control flow unconditional: the previous `#ifdef`
4379+ * opened the `if (...) {` brace in one branch and a different one in the other,
4380+ * sharing a single close brace — legal C, but it splits the function's braces
4381+ * across preprocessor branches, which defeats source-level tooling that parses
4382+ * without the preprocessor (and left this function unindexed in the graph). */
4383+ static bool resolve_canonical_path (const char * path , char * out , size_t out_sz ) {
4384+ #ifdef _WIN32
4385+ if (!_fullpath (out , path , out_sz )) {
4386+ return false;
4387+ }
4388+ cbm_normalize_path_sep (out );
4389+ return true;
4390+ #else
4391+ (void )out_sz ;
4392+ return realpath (path , out ) != NULL ;
4393+ #endif
4394+ }
4395+
43764396bool cbm_path_within_root (const char * root_path , const char * abs_path ) {
43774397 if (!root_path || !abs_path ) {
43784398 return false;
43794399 }
43804400 char real_root [CBM_SZ_4K ];
43814401 char real_file [CBM_SZ_4K ];
4382- #ifdef _WIN32
4383- if (_fullpath (real_root , root_path , sizeof (real_root )) &&
4384- _fullpath (real_file , abs_path , sizeof (real_file ))) {
4385- cbm_normalize_path_sep (real_root );
4386- cbm_normalize_path_sep (real_file );
4387- #else
4388- if (realpath (root_path , real_root ) && realpath (abs_path , real_file )) {
4389- #endif
4402+ if (resolve_canonical_path (root_path , real_root , sizeof (real_root )) &&
4403+ resolve_canonical_path (abs_path , real_file , sizeof (real_file ))) {
43904404 size_t root_len = strlen (real_root );
43914405 if (strncmp (real_file , real_root , root_len ) == 0 &&
43924406 (real_file [root_len ] == '/' || real_file [root_len ] == '\0' )) {
0 commit comments