man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH] Add fallback pager if the compile time default is


From: nsajko
Subject: [Man-db-devel] [PATCH] Add fallback pager if the compile time default is not executable
Date: Fri, 15 Dec 2017 22:48:58 -0800 (PST)

diff --git a/src/man.c b/src/man.c
index 6bc9642c..a3b72b96 100644
--- a/src/man.c
+++ b/src/man.c
@@ -4020,6 +4020,22 @@ static const char **get_section_list (void)
        }
 }

+static int configuredPagerIsExecutable(void)
+{
+       // The sh script to check PAGER executability.
+       //
+       // We are being quite paranoid with the unalias and unset. They guard
+       // from an sh implementation which allows exporting or initializing
+       // aliased names or functions, and the unlikely possibility of 'command'
+       // being spoofed by such an exported aliased name or function.
+       char command[] =
+               "\\unset -f unalias command less more cat\n"
+               "\\unalias -a\n"
+               "\\command -v " PAGER " 1>/dev/null 2>/dev/null\n";
+
+       return system (command) == 0;
+}
+
 int main (int argc, char *argv[])
 {
        int argc_env, exit_status = OK;
@@ -4119,8 +4135,16 @@ int main (int argc, char *argv[])
                pager = getenv ("MANPAGER");
                if (pager == NULL) {
                        pager = getenv ("PAGER");
-                       if (pager == NULL)
-                               pager = get_def_user ("pager", PAGER);
+                       if (pager == NULL) {
+                               pager = get_def_user ("pager", NULL);
+                               if (pager == NULL) {
+                                       if (configuredPagerIsExecutable ()) {
+                                               pager = PAGER;
+                                       } else {
+                                               pager = "";
+                                       }
+                               }
+                       }
                }
        }
        if (*pager == '\0')

reply via email to

[Prev in Thread] Current Thread [Next in Thread]