cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit 327b543010dcfe399af2199dd5f231b7c33677cc
parent 68c0c815592e004b9e898a6767bb0e18321d5a07
Author: Wim Dupont <wim@wimdupont.com>
Date:   Mon, 27 Jul 2026 12:42:18 +0200

fixes

Diffstat:
Mcex.c | 35++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/cex.c b/cex.c @@ -146,6 +146,8 @@ main(int argc, char **argv) while ((opt = getopt(argc, argv, "f:")) != -1) { switch (opt) { case 'f': + if (strlen(optarg) >= sizeof(filename)) + fatal("Output path is too long.\n"); cpstr(filename, optarg); writepath = TRUE; break; @@ -481,6 +483,9 @@ set_win_files(DirWin *dirwin) || strcmp(ent->d_name, "..") == 0 || (hide && ent->d_name[0] == '.')) continue; + if (strnlen(ent->d_name, sizeof(dirwin->winfiles[0].d_name)) + == sizeof(dirwin->winfiles[0].d_name)) + continue; if (count == cap) { cap *= 2; if ((dirwin->winfiles = (WinFile*) realloc(dirwin->winfiles, cap * sizeof(WinFile))) == NULL) @@ -549,8 +554,7 @@ remove_selected(const char *sel) if (--(selc) == 0) { free(selected); selected = NULL; - } else if ((selected = (char**) realloc(selected, selc * sizeof(char *))) == NULL) - fatal("Fatal: failed to realloc.\n"); + } return res; } @@ -707,11 +711,10 @@ print_top_title(void) move(0, 0); clrtoeol(); - if (curwin.filecount == 0) { - cpstr(path, curwin.path); - if (strcmp(path, "/") != 0) - strcat(path, "/"); - } else + if (curwin.filecount == 0) + snprintf(path, sizeof(path), "%s%s", curwin.path, + strcmp(curwin.path, "/") == 0 ? "" : "/"); + else get_fullpath(path, &curwin, curwin.highlight); attron(COLOR_PAIR(TOP_TITLE_COLOR)); #if GIT_INFO @@ -1473,7 +1476,7 @@ read_command(char *buf, size_t bufsize, const char *cmd) return 2; } - buf[strlen(buf)-1] = '\0'; + buf[strcspn(buf, "\n")] = '\0'; pclose(file); @@ -1753,9 +1756,6 @@ exe_selection(SelAction action, const char *askn) void select_file(const char *path) { - if (selc == 0 && ((selected = (char**) malloc(sizeof(char *)))) == NULL) - fatal("Fatal: failed to malloc selected.\n"); - if (remove_selected(path)) return; @@ -1769,8 +1769,9 @@ select_file(const char *path) void clear_selected(void) { - for (size_t i = 0; i < selc; i++) - free(selected[i]); + if (selected != NULL) + for (size_t i = 0; i < selc; i++) + free(selected[i]); free(selected); selected = NULL; @@ -1827,10 +1828,10 @@ replace_home(char *buf, const char *path) { char *envv = "$HOME"; - if ((strstr(path, envv) != NULL)) { - cpstr(buf, userhome); - strcat(buf, path + strlen(envv)); - } + if (strncmp(path, envv, strlen(envv)) == 0 + && snprintf(buf, PATH_MAX, "%s%s", userhome, + path + strlen(envv)) >= PATH_MAX) + buf[0] = '\0'; return buf; }