Skip to content

Commit 139a9c4

Browse files
committed
cli: Validate hex color length
1 parent 8619d77 commit 139a9c4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

cli.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,17 @@ bool ParseColors(std::string colors_string, DeviceOptions *options)
270270
/* swy: (B) no luck, try interpreting it as an hexadecimal number instead */
271271
if (!parsed)
272272
{
273-
const char *colorptr = color.c_str(); char *endptr = NULL;
273+
if (color.length() == 6)
274+
{
275+
const char *colorptr = color.c_str(); char *endptr = NULL;
274276

275-
rgb = strtoul(colorptr, &endptr, 16);
277+
rgb = strtoul(colorptr, &endptr, 16);
276278

277-
/* swy: check that strtoul() has advanced the read pointer until the end (NULL terminator);
278-
that means it has read the whole thing */
279-
if (colorptr != endptr && endptr && *endptr == '\0')
280-
parsed = true;
279+
/* swy: check that strtoul() has advanced the read pointer until the end (NULL terminator);
280+
that means it has read the whole thing */
281+
if (colorptr != endptr && endptr && *endptr == '\0')
282+
parsed = true;
283+
}
281284
}
282285

283286
/* swy: we got it, save the 32-bit integer as a tuple of three RGB bytes */

0 commit comments

Comments
 (0)