On 05/27/15 05:36 AM, Egbert Eich wrote:
From: Egbert Eich <[email protected]>

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

Hmm, I guess I always assumed it would always be at least 1 for the
program name, but am not sure all the exec*() variants require that
now that you mention it.

Signed-off-by: Egbert Eich <[email protected]>
---
  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


Reviewed-by: Alan Coopersmith <[email protected]>

--
        -Alan Coopersmith-              [email protected]
         Oracle Solaris Engineering - http://blogs.oracle.com/alanc
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to