From 4b9f426d7f793313964ae0c760aa35633beccc7b Mon Sep 17 00:00:00 2001 From: Simon 'corecode' Schubert Date: Wed, 30 Sep 2009 16:35:32 +0200 Subject: [PATCH] man: fix bug with relative file names Man assembles a command chain which only works properly when the passed file name is absolute or relative without any directory component. --- gnu/usr.bin/man/man/man.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gnu/usr.bin/man/man/man.c b/gnu/usr.bin/man/man/man.c index fb7c009d8d..9a311db50a 100644 --- a/gnu/usr.bin/man/man/man.c +++ b/gnu/usr.bin/man/man/man.c @@ -1611,7 +1611,7 @@ man (name) register char **sp; #ifdef __DragonFly__ int l_found; - char buf[FILENAME_MAX]; + char buf[PATH_MAX]; #endif found = 0; @@ -1624,8 +1624,14 @@ man (name) if (debug) fprintf(stderr, "Trying as file name\n"); - if (stat(name, &st) == 0) - found += format_and_display(dirname(name), name, NULL); + /* + * We need to pass an absolute file name to format_and_display, + * or it will run into problems later. + */ + realpath(name, buf); + + if (stat(buf, &st) == 0) + found += format_and_display(dirname(buf), buf, NULL); } else if (shortsec != NULL) { -- 2.41.0