man: fix bug with relative file names
authorSimon 'corecode' Schubert <corecode@fs.ei.tum.de>
Wed, 30 Sep 2009 14:35:32 +0000 (16:35 +0200)
committerSimon 'corecode' Schubert <corecode@fs.ei.tum.de>
Wed, 30 Sep 2009 14:35:32 +0000 (16:35 +0200)
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

index fb7c009..9a311db 100644 (file)
@@ -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)
     {