From d0bf2476b7aa84b36b0f6d5173956b1dd3992566 Mon Sep 17 00:00:00 2001 From: beck <> Date: Sat, 18 Jul 2015 21:21:28 +0000 Subject: Coverity ID 78910 - Yet another stupid API designed to not show failures. do the lease worst alternative and do nothing rather than dereference NULL, but having a function with fundamentally broken API to simply make a list of strings, sort them, and call a function with each string as an argument is really quite silly.... and of course it was exposed API that the ecosystem uses that we can't delete.. yet. ok miod@ doug@ --- src/lib/libcrypto/objects/o_names.c | 14 ++++++++------ src/lib/libssl/src/crypto/objects/o_names.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c index e77e4a1093..81240db204 100644 --- a/src/lib/libcrypto/objects/o_names.c +++ b/src/lib/libcrypto/objects/o_names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: o_names.c,v 1.20 2015/02/10 11:22:21 jsing Exp $ */ +/* $OpenBSD: o_names.c,v 1.21 2015/07/18 21:21:28 beck Exp $ */ #include #include #include @@ -299,14 +299,16 @@ OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg), d.names = reallocarray(NULL, lh_OBJ_NAME_num_items(names_lh), sizeof *d.names); d.n = 0; - OBJ_NAME_do_all(type, do_all_sorted_fn, &d); + if (d.names != NULL) { + OBJ_NAME_do_all(type, do_all_sorted_fn, &d); - qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); + qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); - for (n = 0; n < d.n; ++n) - fn(d.names[n], arg); + for (n = 0; n < d.n; ++n) + fn(d.names[n], arg); - free((void *)d.names); + free(d.names); + } } static int free_type; diff --git a/src/lib/libssl/src/crypto/objects/o_names.c b/src/lib/libssl/src/crypto/objects/o_names.c index e77e4a1093..81240db204 100644 --- a/src/lib/libssl/src/crypto/objects/o_names.c +++ b/src/lib/libssl/src/crypto/objects/o_names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: o_names.c,v 1.20 2015/02/10 11:22:21 jsing Exp $ */ +/* $OpenBSD: o_names.c,v 1.21 2015/07/18 21:21:28 beck Exp $ */ #include #include #include @@ -299,14 +299,16 @@ OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg), d.names = reallocarray(NULL, lh_OBJ_NAME_num_items(names_lh), sizeof *d.names); d.n = 0; - OBJ_NAME_do_all(type, do_all_sorted_fn, &d); + if (d.names != NULL) { + OBJ_NAME_do_all(type, do_all_sorted_fn, &d); - qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); + qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); - for (n = 0; n < d.n; ++n) - fn(d.names[n], arg); + for (n = 0; n < d.n; ++n) + fn(d.names[n], arg); - free((void *)d.names); + free(d.names); + } } static int free_type; -- cgit v1.2.3-55-g6feb