Skip to content

Commit 449a658

Browse files
committed
common/common.c: suggest_doc_links(): do not preallocate buf2, ensure use of only basename of a program [#722]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent ecb20b8 commit 449a658

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

common/common.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,13 @@ const char *suggest_doc_links(const char *progname, const char *progconf) {
665665
buf[0] = '\0';
666666

667667
if (progname) {
668-
char *s = NULL, buf2[LARGEBUF];
669-
size_t i, max = sizeof(buf2) - 1;
668+
char *s = NULL, *buf2 = xstrdup(xbasename(progname));
669+
size_t i;
670670

671-
for (i = 0; progname[i] && i < max; i++) {
672-
buf2[i] = tolower(progname[i]);
671+
for (i = 0; buf2[i]; i++) {
672+
buf2[i] = tolower(buf2[i]);
673673
}
674-
buf2[i] = '\0';
674+
675675
if ((s = strstr(buf2, ".exe")) && strcmp(buf2, "nut.exe"))
676676
*s = '\0';
677677

@@ -685,6 +685,8 @@ const char *suggest_doc_links(const char *progname, const char *progconf) {
685685
snprintfcat(buf, sizeof(buf),
686686
"see\n\t%s/docs/man/%s.html\n",
687687
NUT_WEBSITE_BASE, buf2);
688+
689+
free(buf2);
688690
}
689691

690692
if (progconf)

0 commit comments

Comments
 (0)