commit 73d2eb65efbca32153e38c5f0c5ebcca2fe88614
parent fc306271a2fcaa405644d1b5d1e0129dc6086c8c
Author: afify <hassan@afify.dev>
Date: Sun, 15 Aug 2021 21:54:01 +0300
[fix] realpath() buffer overflow
issue #25
Diffstat:
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sfm.c b/sfm.c
@@ -308,8 +308,7 @@ static void
print_row(Pane *pane, size_t entpos, Cpair col)
{
int x, y;
- char *full_str;
- char rez_pth[MAX_N - 5];
+ char *full_str, *rez_pth;
char lnk_full[MAX_N];
full_str = basename(pane->direntr[entpos].name);
@@ -317,11 +316,12 @@ print_row(Pane *pane, size_t entpos, Cpair col)
y = entpos - pane->firstrow + 1;
if (S_ISLNK(pane->direntr[entpos].mode) != 0) {
+ rez_pth = ecalloc(MAX_P, sizeof(char));
if (realpath(pane->direntr[entpos].name, rez_pth) != NULL) {
- snprintf(
- lnk_full, MAX_N, "%s -> %s", full_str, rez_pth);
+ snprintf(lnk_full, MAX_N, "%s -> %s", full_str, rez_pth);
full_str = lnk_full;
}
+ free(rez_pth);
}
printf_tb(x, y, col, "%*.*s", ~hwidth, hwidth, full_str);