If a key is longer than INT_MAX, it is possible to trigger a signed
integer overflow. Since this overflow only occurs for formatting,
prevent it by checking if key is longer than 15 characters. If it is,
there is no need to add any more spacing anyway.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/184
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
kmod_list_foreach(l, list) {
const char *key = kmod_module_info_get_key(l);
const char *value = kmod_module_info_get_value(l);
- int keylen;
+ size_t keylen;
if (field != NULL) {
if (!streq(field, key))
}
keylen = strlen(key);
- printf("%s:%-*s%s%c", key, 15 - keylen, "", value, separator);
+ if (keylen > 15)
+ keylen = 15;
+ printf("%s:%-*s%s%c", key, 15 - (int)keylen, "", value, separator);
}
if (field != NULL)