xserver: Branch 'master' - 3 commits

Adam Jackson ajax at kemper.freedesktop.org
Wed May 4 19:43:30 UTC 2016


 hw/xfree86/common/xf86Init.c |   66 ++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 41 deletions(-)

New commits:
commit 66fdeb880aac0966be9aa41219047ade0148c35f
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Mon May 2 23:47:22 2016 +0100

    xfree86: drop unneeded strdup for modulepath/logfile
    
    The destination variable is never freed, thus we even plug some memory
    leaks.
    
    v2: Rebase against updated xf86CheckPrivs() helper.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 1f7615d..202e9cc 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1121,26 +1121,16 @@ ddxProcessArgument(int argc, char **argv, int i)
 
     /* First the options that are not allowed with elevated privileges */
     if (!strcmp(argv[i], "-modulepath")) {
-        char *mp;
-
         CHECK_FOR_REQUIRED_ARGUMENT();
         xf86CheckPrivs(argv[i], argv[i + 1]);
-        mp = strdup(argv[i + 1]);
-        if (!mp)
-            FatalError("Can't allocate memory for ModulePath\n");
-        xf86ModulePath = mp;
+        xf86ModulePath = argv[i + 1];
         xf86ModPathFrom = X_CMDLINE;
         return 2;
     }
     if (!strcmp(argv[i], "-logfile")) {
-        char *lf;
-
         CHECK_FOR_REQUIRED_ARGUMENT();
         xf86CheckPrivs(argv[i], argv[i + 1]);
-        lf = strdup(argv[i + 1]);
-        if (!lf)
-            FatalError("Can't allocate memory for LogFile\n");
-        xf86LogFile = lf;
+        xf86LogFile = argv[i + 1];
         xf86LogFileFrom = X_CMDLINE;
         return 2;
     }
commit 032b1d79b7d04d47814a5b3a9fdd162249fea74c
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Mon May 2 23:47:21 2016 +0100

    xfree86: use the xf86CheckPrivs() helper for modulepath/logfile
    
    v2: Rebase against updated xf86CheckPrivs() helper.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index e19b6f4..1f7615d 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1120,33 +1120,29 @@ ddxProcessArgument(int argc, char **argv, int i)
     }
 
     /* First the options that are not allowed with elevated privileges */
-    if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) {
-        if (xf86PrivsElevated()) {
-            FatalError("The '%s' option cannot be used with "
-                       "elevated privileges.\n", argv[i]);
-        }
-        else if (!strcmp(argv[i], "-modulepath")) {
-            char *mp;
-
-            CHECK_FOR_REQUIRED_ARGUMENT();
-            mp = strdup(argv[i + 1]);
-            if (!mp)
-                FatalError("Can't allocate memory for ModulePath\n");
-            xf86ModulePath = mp;
-            xf86ModPathFrom = X_CMDLINE;
-            return 2;
-        }
-        else if (!strcmp(argv[i], "-logfile")) {
-            char *lf;
-
-            CHECK_FOR_REQUIRED_ARGUMENT();
-            lf = strdup(argv[i + 1]);
-            if (!lf)
-                FatalError("Can't allocate memory for LogFile\n");
-            xf86LogFile = lf;
-            xf86LogFileFrom = X_CMDLINE;
-            return 2;
-        }
+    if (!strcmp(argv[i], "-modulepath")) {
+        char *mp;
+
+        CHECK_FOR_REQUIRED_ARGUMENT();
+        xf86CheckPrivs(argv[i], argv[i + 1]);
+        mp = strdup(argv[i + 1]);
+        if (!mp)
+            FatalError("Can't allocate memory for ModulePath\n");
+        xf86ModulePath = mp;
+        xf86ModPathFrom = X_CMDLINE;
+        return 2;
+    }
+    if (!strcmp(argv[i], "-logfile")) {
+        char *lf;
+
+        CHECK_FOR_REQUIRED_ARGUMENT();
+        xf86CheckPrivs(argv[i], argv[i + 1]);
+        lf = strdup(argv[i + 1]);
+        if (!lf)
+            FatalError("Can't allocate memory for LogFile\n");
+        xf86LogFile = lf;
+        xf86LogFileFrom = X_CMDLINE;
+        return 2;
     }
     if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) {
         CHECK_FOR_REQUIRED_ARGUMENT();
commit 0fdd47560468e7b6147c666cc6b9eebcecb68572
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Mon May 2 23:47:20 2016 +0100

    xfree86: factor out the check priviliges and print a big warning
    
    Current message was quite off "file specified must be a relative path"
    and alike. Just factor it out and use "path/file" as needed.
    
    v2: Rework error message, drop "Using default", print actual arg value.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 46976c1..e19b6f4 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1090,6 +1090,16 @@ xf86PrintDefaultLibraryPath(void)
     ErrorF("%s\n", DEFAULT_LIBRARY_PATH);
 }
 
+static void
+xf86CheckPrivs(const char *option, const char *arg)
+{
+    if (xf86PrivsElevated() && !xf86PathIsSafe(arg)) {
+        FatalError("\nInvalid argument for %s - \"%s\"\n"
+                    "\tWith elevated privileges %s must specify a relative path\n"
+                    "\twithout any \"..\" elements.\n\n", option, arg, option);
+    }
+}
+
 /*
  * ddxProcessArgument --
  *	Process device-dependent command line args. Returns 0 if argument is
@@ -1140,25 +1150,13 @@ ddxProcessArgument(int argc, char **argv, int i)
     }
     if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) {
         CHECK_FOR_REQUIRED_ARGUMENT();
-        if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) {
-            FatalError("\nInvalid argument for %s\n"
-                       "\tWith elevated privileges, the file specified with %s must be\n"
-                       "\ta relative path and must not contain any \"..\" elements.\n"
-                       "\tUsing default " __XCONFIGFILE__ " search path.\n\n",
-                       argv[i], argv[i]);
-        }
+        xf86CheckPrivs(argv[i], argv[i + 1]);
         xf86ConfigFile = argv[i + 1];
         return 2;
     }
     if (!strcmp(argv[i], "-configdir")) {
         CHECK_FOR_REQUIRED_ARGUMENT();
-        if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) {
-            FatalError("\nInvalid argument for %s\n"
-                       "\tWith elevated privileges, the file specified with %s must be\n"
-                       "\ta relative path and must not contain any \"..\" elements.\n"
-                       "\tUsing default " __XCONFIGDIR__ " search path.\n\n",
-                       argv[i], argv[i]);
-        }
+        xf86CheckPrivs(argv[i], argv[i + 1]);
         xf86ConfigDir = argv[i + 1];
         return 2;
     }


More information about the xorg-commit mailing list