Blob Blame History Raw
From 206036a852e3d9c598e3fe82d84fd2ac54bbaa55 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sun, 02 Aug 2009 17:50:30 +0100
Subject: Skip leading # signs for the color, fix input validation

---
diff --git i3lock-1.0.orig/i3lock.c i3lock-1.0/i3lock.c
index eca32e9..64d2301 100644
--- i3lock-1.0.orig/i3lock.c
+++ i3lock-1.0/i3lock.c
@@ -45,7 +45,6 @@ static void die(const char *errstr, ...) {
         exit(EXIT_FAILURE);
 }
 
-
 /*
  * Returns the colorpixel to use for the given hex color (think of HTML).
  *
@@ -197,13 +196,17 @@ int main(int argc, char *argv[]) {
                                 xpm_image = true;
                                 break;
                         case 'c':
-                                strncpy(color, optarg, 6);
-                                color[6] = 0;
+                        {
+                                char *arg = optarg;
+                                /* Skip # if present */
+                                if (arg[0] == '#')
+                                        arg++;
+
+                                if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1)
+                                        die("color is invalid, color must be given in 6-byte format: rrggbb\n");
 
-                                char parsed_color[7];
-                                if (strlen(color) != 6 || sscanf(color, "%06[0-9a-fA-F]", parsed_color) != 1)
-                                    die("color is invalid, color must be given in 6-byte format: rrggbb\n");
                                 break;
+                        }
                         default:
                                 die("i3lock: Unknown option. Syntax: i3lock [-v] [-n] [-b] [-d] [-i image.xpm] [-c color]\n");
                 }
--
cgit v0.8.3