summaryrefslogtreecommitdiff
path: root/i3lock.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2009-08-02 19:50:30 +0200
committerMichael Stapelberg <michael@stapelberg.de>2009-08-02 19:50:30 +0200
commit206036a852e3d9c598e3fe82d84fd2ac54bbaa55 (patch)
treea38b33f1c9714cb17c7b486316c8829fab5a4e20 /i3lock.c
parent9c4dee2e8633d4ff2c9787fc3f1b6591338c41f5 (diff)
Skip leading # signs for the color, fix input validation
Diffstat (limited to 'i3lock.c')
-rw-r--r--i3lock.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/i3lock.c b/i3lock.c
index eca32e9..64d2301 100644
--- a/i3lock.c
+++ b/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");
}