summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2023-09-11 13:51:20 -0700
committerAyush Garg <ayush.garg@samsung.com>2024-01-05 19:04:04 +0530
commit017a91f7e97297654122005eb78092a64081a3c9 (patch)
tree602141dbdaa95dabda5da9e5a5ca07e42e8d3086
parent3765d97c64776895bdc5b02f6fd15ca9d73e1a34 (diff)
downloadbluez-017a91f7e97297654122005eb78092a64081a3c9.tar.gz
bluez-017a91f7e97297654122005eb78092a64081a3c9.tar.bz2
bluez-017a91f7e97297654122005eb78092a64081a3c9.zip
main.conf: Fix parsing of uint32_t values
Passing UINT32_MAX as int may overfollow causing errors such as: bluetoothd[2688495]: src/main.c:parse_config_int() General.TemporaryTimeout = 60 is out of range (> -1) Fixes: https://github.com/bluez/bluez/issues/583#issuecomment-1713447461
-rwxr-xr-xsrc/main.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index a523c0c0..a46da213 100755
--- a/src/main.c
+++ b/src/main.c
@@ -445,9 +445,9 @@ static bool parse_config_string(GKeyFile *config, const char *group,
static bool parse_config_int(GKeyFile *config, const char *group,
const char *key, int *val,
- int min, int max)
+ size_t min, size_t max)
{
- int tmp;
+ size_t tmp;
char *str = NULL;
char *endptr = NULL;
@@ -461,12 +461,14 @@ static bool parse_config_int(GKeyFile *config, const char *group,
}
if (tmp < min) {
- warn("%s.%s = %d is out of range (< %d)", group, key, tmp, min);
+ warn("%s.%s = %zu is out of range (< %zu)", group, key, tmp,
+ min);
return false;
}
if (tmp > max) {
- warn("%s.%s = %d is out of range (> %d)", group, key, tmp, max);
+ warn("%s.%s = %zu is out of range (> %zu)", group, key, tmp,
+ max);
return false;
}
@@ -778,7 +780,7 @@ static bool parse_config_u32(GKeyFile *config, const char *group,
{
int tmp;
- if (!parse_config_int(config, group, key, &tmp, 0, UINT32_MAX))
+ if (!parse_config_int(config, group, key, &tmp, min, max))
return false;
if (val)