[PATCH app/xdm] dm: Don't crash if argc == 0

Egbert Eich eich at freedesktop.org
Wed May 27 05:36:30 PDT 2015


From: Egbert Eich <eich at suse.de>

It is not guaranteed that argc > 0. So make sure we don't crash
if no valid command line arguments are given.

Signed-off-by: Egbert Eich <eich at suse.de>
---
 xdm/dm.c | 47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/xdm/dm.c b/xdm/dm.c
index 603cc63..bdc830a 100644
--- a/xdm/dm.c
+++ b/xdm/dm.c
@@ -129,8 +129,13 @@ main (int argc, char **argv)
     if (((oldumask = umask(022)) & 002) == 002)
 	(void) umask (oldumask);
 #ifndef NOXDMTITLE
-    Title = argv[0];
-    TitleLen = (argv[argc - 1] + strlen(argv[argc - 1])) - Title;
+    if (argc > 0) {
+        Title = argv[0];
+        TitleLen = (argv[argc - 1] + strlen(argv[argc - 1])) - Title;
+    } else {
+        Title = NULL;
+        TitleLen = 0;
+    }
 #endif
 
 #ifdef USESECUREWARE
@@ -1074,25 +1079,27 @@ void SetTitle (char *name, ...)
     char	*s;
     va_list	args;
 
-    va_start(args,name);
-    *p++ = '-';
-    --left;
-    s = name;
-    while (s)
-    {
-	while (*s && left > 0)
-	{
-	    *p++ = *s++;
-	    left--;
-	}
-	s = va_arg (args, char *);
-    }
-    while (left > 0)
-    {
-	*p++ = ' ';
-	--left;
+    if (p != NULL && left > 0) {
+        va_start(args,name);
+        *p++ = '-';
+        --left;
+        s = name;
+        while (s)
+        {
+            while (*s && left > 0)
+            {
+                *p++ = *s++;
+                left--;
+            }
+            s = va_arg (args, char *);
+        }
+        while (left > 0)
+        {
+            *p++ = ' ';
+            --left;
+        }
+        va_end(args);
     }
-    va_end(args);
 # endif
 }
 #endif
-- 
1.8.4.5



More information about the xorg-devel mailing list