Skip to content

Commit 02e36f9

Browse files
pks-tgitster
authored andcommitted
builtin/help: fix dangling reference to html_path
In `get_html_page_path()` we may end up assigning the return value of `system_path()` to the global `html_path` variable. But as we also assign the returned value to `to_free`, we will deallocate its memory upon returning from the function. Consequently, `html_path` will now point to deallocated memory. Fix this issue by instead assigning the value to a separate local variable. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2b7f03 commit 02e36f9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

builtin/help.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,24 @@ static void show_info_page(const char *page)
513513
static void get_html_page_path(struct strbuf *page_path, const char *page)
514514
{
515515
struct stat st;
516+
const char *path = html_path;
516517
char *to_free = NULL;
517518

518-
if (!html_path)
519-
html_path = to_free = system_path(GIT_HTML_PATH);
519+
if (!path)
520+
path = to_free = system_path(GIT_HTML_PATH);
520521

521522
/*
522523
* Check that the page we're looking for exists.
523524
*/
524-
if (!strstr(html_path, "://")) {
525-
if (stat(mkpath("%s/%s.html", html_path, page), &st)
525+
if (!strstr(path, "://")) {
526+
if (stat(mkpath("%s/%s.html", path, page), &st)
526527
|| !S_ISREG(st.st_mode))
527528
die("'%s/%s.html': documentation file not found.",
528-
html_path, page);
529+
path, page);
529530
}
530531

531532
strbuf_init(page_path, 0);
532-
strbuf_addf(page_path, "%s/%s.html", html_path, page);
533+
strbuf_addf(page_path, "%s/%s.html", path, page);
533534
free(to_free);
534535
}
535536

0 commit comments

Comments
 (0)