| index d0359e3..c3eacb2 100644 | | index d0359e3..c3eacb2 100644 |
| --- a/src/plugin_gitstat.c | | --- a/src/plugin_gitstat.c |
| +++ b/src/plugin_gitstat.c | | +++ b/src/plugin_gitstat.c |
| @@ -584,7 +584,8 @@ static repo_t g_repos[MAX_REPOS]; | | @@ -584,7 +584,8 @@ static repo_t g_repos[MAX_REPOS]; |
| 584 | static int g_repo_count; | 584 | static int g_repo_count; |
| 585 | | 585 | |
| 586 | typedef struct { | 586 | typedef struct { |
| 587 | - char root[768]; | 587 | + char root[768]; /* as configured, for display */ |
| | 588 | + char canon[768]; /* realpath() form, for the prefix check */ |
| 588 | int exists; | 589 | int exists; |
| 589 | int count; | 590 | int count; |
| 590 | int truncated; | 591 | int truncated; |
| @@ -717,6 +718,9 @@ static void walk_dir(const char *dir, const char *root, int depth, | | @@ -717,6 +718,9 @@ static void walk_dir(const char *dir, const char *root, int depth, |
| 717 | } | 718 | } |
| 718 | } | 719 | } |
| 719 | | 720 | |
| | 721 | +static void canon_path(const char *in, char *out, size_t sz); |
| | 722 | +static int path_exists(const char *p); |
| | 723 | + |
| 720 | static void root_add(const char *root, const char *sep_list_used) | 724 | static void root_add(const char *root, const char *sep_list_used) |
| 721 | { | 725 | { |
| 722 | (void)sep_list_used; | 726 | (void)sep_list_used; |
| @@ -728,6 +732,7 @@ static void root_add(const char *root, const char *sep_list_used) | | @@ -728,6 +732,7 @@ static void root_add(const char *root, const char *sep_list_used) |
| 728 | if (strcmp(g_roots[i].root, root) == 0) return; | 732 | if (strcmp(g_roots[i].root, root) == 0) return; |
| 729 | } | 733 | } |
| 730 | str_copy(g_roots[g_root_count].root, sizeof(g_roots[g_root_count].root), root); | 734 | str_copy(g_roots[g_root_count].root, sizeof(g_roots[g_root_count].root), root); |
| | 735 | + canon_path(root, g_roots[g_root_count].canon, sizeof(g_roots[g_root_count].canon)); |
| 731 | g_roots[g_root_count].exists = 0; | 736 | g_roots[g_root_count].exists = 0; |
| 732 | g_roots[g_root_count].count = 0; | 737 | g_roots[g_root_count].count = 0; |
| 733 | g_roots[g_root_count].truncated = 0; | 738 | g_roots[g_root_count].truncated = 0; |
| @@ -1057,9 +1062,13 @@ static int under_root(const char *path) | | @@ -1057,9 +1062,13 @@ static int under_root(const char *path) |
| 1057 | { | 1062 | { |
| 1058 | int i; | 1063 | int i; |
| 1059 | for (i = 0; i < g_root_count; i++) { | 1064 | for (i = 0; i < g_root_count; i++) { |
| 1060 | - size_t n = strlen(g_roots[i].root); | 1065 | + /* Compare against the canonical root, not the configured string: on |
| | 1066 | + * macOS /tmp and /var are symlinks, so realpath("/tmp/x") is |
| | 1067 | + * "/private/tmp/x" and a raw prefix test would refuse every path. */ |
| | 1068 | + const char *r = g_roots[i].canon[0] ? g_roots[i].canon : g_roots[i].root; |
| | 1069 | + size_t n = strlen(r); |
| 1061 | if (n == 0) continue; | 1070 | if (n == 0) continue; |
| 1062 | - if (strncmp(path, g_roots[i].root, n) != 0) continue; | 1071 | + if (strncmp(path, r, n) != 0) continue; |
| 1063 | if (path[n] == '\0' || path[n] == '/' || path[n] == '\\') return 1; | 1072 | if (path[n] == '\0' || path[n] == '/' || path[n] == '\\') return 1; |
| 1064 | } | 1073 | } |
| 1065 | return 0; | 1074 | return 0; |
| 1066 | | 1075 | |