If MANPATH isn't set a provisional default path of /usr/man is placed
in man_path_list.  This is only used if a configuration file doesn't
contain an alternative path.

If a configuration file lists the default path first:

   MANPATH /usr/man:/usr/share/man

add_MANPATH() sees that the default entry is already present and skips
it.  As a result man_path_list only contains the second and subsequent
components of the configured MANPATH.

In such cases the count needs to be incremented to prevent the default
path from being overwritten.

function                                             old     new   delta
add_MANPATH                                          170     183     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <[email protected]>
---
 miscutils/man.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/miscutils/man.c b/miscutils/man.c
index 01155c8f0..8680d4e78 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -209,12 +209,17 @@ static char **add_MANPATH(char **man_path_list, int 
*count_mp, char *path)
                /* Do we already have path? */
                path_element = man_path_list;
                if (path_element) while (*path_element) {
-                       if (strcmp(*path_element, path) == 0)
+                       if (strcmp(*path_element, path) == 0) {
+                               /* Have path but haven't counted it, must be 
default */
+                               if (*count_mp == 0)
+                                       goto count;
                                goto skip;
+                       }
                        path_element++;
                }
                man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);
                man_path_list[*count_mp] = xstrdup(path);
+ count:
                (*count_mp)++;
                /* man_path_list is NULL terminated */
                /* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */
-- 
2.20.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to