2

When having excessively long MANPATH env-vars I end up in a problem with this error:

$> man <any command>
man: manpath list too long

To figure out when the manpath list is too long I created this small script:

#!/bin/bash
export MANPATH=
for i in $(seq 50 10000)
do
    export MANPATH=/usr:$MANPATH
    man -k gcc > /dev/null
    [ $? -ne 0 ] && echo "$i ${#MANPATH}" && exit 0
done

and it seems like it breaks at ${#MANPATH} close to 500.

Also man -d does not give me any information I can use... :(

I have never heard (nor found) a limitation to the number of entries in env-vars (besides the maximum length of the environment variables, from which I am far from).

Are there any fixes for this? Preferably a non-root fix ;)

I am running Debian 9.6.

EDIT: This was reported upstream and fixed!

nickpapior
  • 752
  • 1
  • 8
  • 14

1 Answers1

2

Based on manp.c starting at line 786:

        else if (sscanf (bp, "MANDATORY_MANPATH %511s", key) == 1)
            add_mandatory (key);    
        else if (sscanf (bp, "MANPATH_MAP %511s %511s",
             key, cont) == 2) 
            add_manpath_map (key, cont);
        else if ((c = sscanf (bp, "MANDB_MAP %511s %511s",
                      key, cont)) > 0) 
            add_mandb_map (key, cont, c, user);
        else if ((c = sscanf (bp, "DEFINE %511s %511[^\n]",
                      key, cont)) > 0) 
            add_def (key, cont, c, user);
        else if (sscanf (bp, "SECTION %511[^\n]", cont) == 1)
            add_sections (cont, user);
        else if (sscanf (bp, "SECTIONS %511[^\n]", cont) == 1)
            /* Since I keep getting it wrong ... */
...

I'd say the threshold is 511 characters. Interestingly there's a comment in the stating this should be fixed.

        /* TODO: would like a (limited) replacement for sscanf()
         * here that allocates its own memory. At that point check
         * everything that sprintf()s manpath et al!
         */ 

References

tk421
  • 5,775
  • 6
  • 23
  • 34
  • Thanks a lot! However, that code seems only to apply to the user-config files, and not env-vars. However, I can see that this file parses and places directories in a global array (of size `MAXDIRS` which is 128...)... So the number of paths is hard-coded....! I'll try and create a bug-report! Thanks! – nickpapior Jan 11 '19 at 14:09
  • 1
    The latest `man-db` (as of today) has the fix in-place. I.e. MAXDIRS is now variable and thus there is no limit to the size of the man-dirs! – nickpapior Jan 28 '19 at 08:59