diff options
-rw-r--r-- | crypto/asymmetric_keys/asymmetric_type.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index 718e779a010e..f0f2111d2c66 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c | |||
@@ -90,15 +90,12 @@ EXPORT_SYMBOL_GPL(asymmetric_match_key_ids); | |||
90 | struct asymmetric_key_id *asymmetric_key_hex_to_key_id(const char *id) | 90 | struct asymmetric_key_id *asymmetric_key_hex_to_key_id(const char *id) |
91 | { | 91 | { |
92 | struct asymmetric_key_id *match_id; | 92 | struct asymmetric_key_id *match_id; |
93 | const char *p; | 93 | size_t hexlen; |
94 | ptrdiff_t hexlen; | 94 | int ret; |
95 | 95 | ||
96 | if (!*id) | 96 | if (!*id) |
97 | return ERR_PTR(-EINVAL); | 97 | return ERR_PTR(-EINVAL); |
98 | for (p = id; *p; p++) | 98 | hexlen = strlen(id); |
99 | if (!isxdigit(*p)) | ||
100 | return ERR_PTR(-EINVAL); | ||
101 | hexlen = p - id; | ||
102 | if (hexlen & 1) | 99 | if (hexlen & 1) |
103 | return ERR_PTR(-EINVAL); | 100 | return ERR_PTR(-EINVAL); |
104 | 101 | ||
@@ -107,7 +104,11 @@ struct asymmetric_key_id *asymmetric_key_hex_to_key_id(const char *id) | |||
107 | if (!match_id) | 104 | if (!match_id) |
108 | return ERR_PTR(-ENOMEM); | 105 | return ERR_PTR(-ENOMEM); |
109 | match_id->len = hexlen / 2; | 106 | match_id->len = hexlen / 2; |
110 | (void)hex2bin(match_id->data, id, hexlen / 2); | 107 | ret = hex2bin(match_id->data, id, hexlen / 2); |
108 | if (ret < 0) { | ||
109 | kfree(match_id); | ||
110 | return ERR_PTR(-EINVAL); | ||
111 | } | ||
111 | return match_id; | 112 | return match_id; |
112 | } | 113 | } |
113 | 114 | ||