diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-09-02 12:21:55 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-09-06 22:02:16 -0700 |
commit | 0efc4f3ee111d28cf22060a22ad591427dc7eb7f (patch) | |
tree | 57d1af3c399effad787e63ac8bdbbdcf4b780a1d /host | |
parent | 470b24816681dc1781e1b280980d9448d2c1af96 (diff) | |
download | vboot-0efc4f3ee111d28cf22060a22ad591427dc7eb7f.tar.gz |
futility: Fix lookup of invalid algorithm names
If given a malformed file with an invalid algorithm, futility could
dereference null when looking up the algorithm names.
BUG=chromium:643769
BRANCH=none
TEST=make runtests
Change-Id: I26d1312b8bf2eec8d806664708676daa9f36fa58
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/380522
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Diffstat (limited to 'host')
-rw-r--r-- | host/lib21/host_key.c | 24 | ||||
-rw-r--r-- | host/lib21/include/host_key2.h | 9 |
2 files changed, 16 insertions, 17 deletions
diff --git a/host/lib21/host_key.c b/host/lib21/host_key.c index c7ded210..4ef18d88 100644 --- a/host/lib21/host_key.c +++ b/host/lib21/host_key.c @@ -18,22 +18,6 @@ #include "host_key2.h" #include "host_misc.h" -struct vb2_text_vs_enum vb2_text_vs_algorithm[] = { - {"RSA1024 SHA1", VB2_ALG_RSA1024_SHA1}, - {"RSA1024 SHA256", VB2_ALG_RSA1024_SHA256}, - {"RSA1024 SHA512", VB2_ALG_RSA1024_SHA512}, - {"RSA2048 SHA1", VB2_ALG_RSA2048_SHA1}, - {"RSA2048 SHA256", VB2_ALG_RSA2048_SHA256}, - {"RSA2048 SHA512", VB2_ALG_RSA2048_SHA512}, - {"RSA4096 SHA1", VB2_ALG_RSA4096_SHA1}, - {"RSA4096 SHA256", VB2_ALG_RSA4096_SHA256}, - {"RSA4096 SHA512", VB2_ALG_RSA4096_SHA512}, - {"RSA8192 SHA1", VB2_ALG_RSA8192_SHA1}, - {"RSA8192 SHA256", VB2_ALG_RSA8192_SHA256}, - {"RSA8192 SHA512", VB2_ALG_RSA8192_SHA512}, - {0, 0} -}; - struct vb2_text_vs_enum vb2_text_vs_sig[] = { {"RSA1024", VB2_SIG_RSA1024}, {"RSA2048", VB2_SIG_RSA2048}, @@ -69,6 +53,14 @@ const struct vb2_text_vs_enum *vb2_lookup_by_name( return 0; } +const char *vb2_get_sig_algorithm_name(enum vb2_signature_algorithm sig_alg) +{ + const struct vb2_text_vs_enum *entry = + vb2_lookup_by_num(vb2_text_vs_sig, sig_alg); + + return entry ? entry->name : VB2_INVALID_ALG_NAME; +} + void vb2_private_key_free(struct vb2_private_key *key) { if (!key) diff --git a/host/lib21/include/host_key2.h b/host/lib21/include/host_key2.h index e109cb19..4681a5f4 100644 --- a/host/lib21/include/host_key2.h +++ b/host/lib21/include/host_key2.h @@ -55,11 +55,18 @@ const struct vb2_text_vs_enum *vb2_lookup_by_name( const struct vb2_text_vs_enum *table, const char *name); -extern struct vb2_text_vs_enum vb2_text_vs_algorithm[]; extern struct vb2_text_vs_enum vb2_text_vs_sig[]; extern struct vb2_text_vs_enum vb2_text_vs_hash[]; /** + * Return the name of a signature algorithm. + * + * @param sig_alg Signature algorithm to look up + * @return The corresponding name, or VB2_INVALID_ALG_NAME if no match. + */ +const char *vb2_get_sig_algorithm_name(enum vb2_signature_algorithm sig_alg); + +/** * Free a private key. * * @param key Key containing internal data to free. |