diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2016-06-04 22:37:11 -0300 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2016-06-27 08:17:55 -0300 |
commit | dcdb17715e451acc5bd6fef0d18b0c3cef77f2c9 (patch) | |
tree | 50e690234315ec332950ac3db94a7d2b459ea90c | |
parent | 2206d7f763a1c9cf88f77d0ab19e410d17749361 (diff) | |
download | platform_external_kmod-dcdb17715e451acc5bd6fef0d18b0c3cef77f2c9.tar.gz platform_external_kmod-dcdb17715e451acc5bd6fef0d18b0c3cef77f2c9.tar.bz2 platform_external_kmod-dcdb17715e451acc5bd6fef0d18b0c3cef77f2c9.zip |
libkmod-module: do not crash modinfo on 0 key id len
-rw-r--r-- | libkmod/libkmod-module.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 25dcda7..b7b5daa 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -2261,22 +2261,30 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ goto list_error; count++; - /* Display the key id as 01:12:DE:AD:BE:EF:... */ - key_hex = malloc(sig_info.key_id_len * 3); - if (key_hex == NULL) - goto list_error; - for (i = 0; i < (int)sig_info.key_id_len; i++) { - sprintf(key_hex + i * 3, "%02X", - (unsigned char)sig_info.key_id[i]); - if (i < (int)sig_info.key_id_len - 1) - key_hex[i * 3 + 2] = ':'; + if (sig_info.key_id_len) { + /* Display the key id as 01:12:DE:AD:BE:EF:... */ + key_hex = malloc(sig_info.key_id_len * 3); + if (key_hex == NULL) + goto list_error; + for (i = 0; i < (int)sig_info.key_id_len; i++) { + sprintf(key_hex + i * 3, "%02X", + (unsigned char)sig_info.key_id[i]); + if (i < (int)sig_info.key_id_len - 1) + key_hex[i * 3 + 2] = ':'; + } + n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), + key_hex, sig_info.key_id_len * 3 - 1); + free(key_hex); + if (n == NULL) + goto list_error; + count++; + } else { + n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), + NULL, 0); + if (n == NULL) + goto list_error; + count++; } - n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), - key_hex, sig_info.key_id_len * 3 - 1); - free(key_hex); - if (n == NULL) - goto list_error; - count++; n = kmod_module_info_append(list, "sig_hashalgo", strlen("sig_hashalgo"), |