Skip to content

Commit

Permalink
Merge pull request #1769 from N-R-K/fix-helpstr
Browse files Browse the repository at this point in the history
fix buffer overflow on certain platforms
  • Loading branch information
jarun authored Nov 21, 2023
2 parents 744a755 + 60eabb6 commit 485079d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -5160,6 +5160,7 @@ static void show_help(const char *path)
"cT Set time type%110 Lock\n"
"b^L Redraw%18? Help, conf\n"
};
char help_buf[1<<11]; // if editing helpstr, ensure this has enough space to decode it

int fd = create_tmp_file();
if (fd == -1)
Expand All @@ -5170,7 +5171,7 @@ static void show_help(const char *path)
get_output(prog, NULL, NULL, fd, FALSE);

bool hex = true;
char *w = g_buf;
char *w = help_buf;
const char *end = helpstr + (sizeof helpstr - 1);
for (const char *s = helpstr; s < end; ++s) {
if (hex) {
Expand All @@ -5184,7 +5185,8 @@ static void show_help(const char *path)
}
hex = *s == '\n';
}
if (write(fd, g_buf, w - g_buf)) {} // silence warning
ssize_t res = write(fd, help_buf, w - help_buf);
(void)res; // silence warning

dprintf(fd, "\nLOCATIONS\n");
for (uchar_t i = 0; i < CTX_MAX; ++i)
Expand Down

0 comments on commit 485079d

Please sign in to comment.