From cfee1f0c65240f3972b0b04deb3c4f558cc7fcd3 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 26 Jan 2022 15:09:55 +0200 Subject: [PATCH] wpctl: ensure that the result of strtol() is < G_MAXUINT32 Fixes overflows on 64-bit architectures Closes #173 --- src/tools/wpctl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tools/wpctl.c b/src/tools/wpctl.c index 3fe41d6d..8b0fe0aa 100644 --- a/src/tools/wpctl.c +++ b/src/tools/wpctl.c @@ -384,7 +384,7 @@ inspect_parse_positional (gint argc, gchar ** argv, GError **error) } long id = strtol (argv[2], NULL, 10); - if (id <= 0) { + if (id <= 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid number", argv[2]); return FALSE; @@ -591,7 +591,7 @@ set_default_parse_positional (gint argc, gchar ** argv, GError **error) } long id = strtol (argv[2], NULL, 10); - if (id <= 0) { + if (id <= 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid number", argv[2]); return FALSE; @@ -680,7 +680,7 @@ set_volume_parse_positional (gint argc, gchar ** argv, GError **error) long id = strtol (argv[2], NULL, 10); float volume = strtof (argv[3], NULL); - if (id <= 0) { + if (id <= 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid number", argv[2]); return FALSE; @@ -764,7 +764,7 @@ set_mute_parse_positional (gint argc, gchar ** argv, GError **error) } long id = strtol (argv[2], NULL, 10); - if (id <= 0) { + if (id <= 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid number", argv[2]); return FALSE; @@ -870,7 +870,7 @@ set_profile_parse_positional (gint argc, gchar ** argv, GError **error) long id = strtol (argv[2], NULL, 10); int index = atoi (argv[3]); - if (id < 0) { + if (id < 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid index", argv[2]); return FALSE; @@ -925,7 +925,7 @@ clear_default_parse_positional (gint argc, gchar ** argv, GError **error) if (argc >= 3) { long id = strtol (argv[2], NULL, 10); - if (id < 0) { + if (id < 0 || id >= G_MAXUINT32) { g_set_error (error, wpctl_error_domain_quark(), 0, "'%s' is not a valid number", argv[2]); return FALSE;