diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2017-02-19 18:12:03 +0100 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-02-21 20:13:58 +0100 |
commit | 9ad52c562a93c9a57ae3024e54c575430753244c (patch) | |
tree | 0876289c798ee32c2c5cb272bc0ee761a1a054af /crypto/txt_db | |
parent | Provided support for the -nameopt flag in s_client, s_server and s_time (diff) | |
download | openssl-9ad52c562a93c9a57ae3024e54c575430753244c.tar.xz openssl-9ad52c562a93c9a57ae3024e54c575430753244c.zip |
Fix a few memleaks in TXT_DB.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2684)
Diffstat (limited to 'crypto/txt_db')
-rw-r--r-- | crypto/txt_db/txt_db.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/crypto/txt_db/txt_db.c b/crypto/txt_db/txt_db.c index 14322309a7..cf932a52aa 100644 --- a/crypto/txt_db/txt_db.c +++ b/crypto/txt_db/txt_db.c @@ -104,12 +104,15 @@ TXT_DB *TXT_DB_read(BIO *in, int num) } *(p++) = '\0'; if ((n != num) || (*f != '\0')) { + OPENSSL_free(pp); ret->error = DB_ERROR_WRONG_NUM_FIELDS; goto err; } pp[n] = p; - if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) + if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) { + OPENSSL_free(pp); goto err; + } } BUF_MEM_free(buf); return ret; @@ -148,7 +151,7 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC cmp) { LHASH_OF(OPENSSL_STRING) *idx; - OPENSSL_STRING *r; + OPENSSL_STRING *r, *k; int i, n; if (field >= db->num_fields) { @@ -165,13 +168,18 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), r = sk_OPENSSL_PSTRING_value(db->data, i); if ((qual != NULL) && (qual(r) == 0)) continue; - if ((r = lh_OPENSSL_STRING_insert(idx, r)) != NULL) { + if ((k = lh_OPENSSL_STRING_insert(idx, r)) != NULL) { db->error = DB_ERROR_INDEX_CLASH; - db->arg1 = sk_OPENSSL_PSTRING_find(db->data, r); + db->arg1 = sk_OPENSSL_PSTRING_find(db->data, k); db->arg2 = i; lh_OPENSSL_STRING_free(idx); return (0); } + if (lh_OPENSSL_STRING_retrieve(idx, r) == NULL) { + db->error = DB_ERROR_MALLOC; + lh_OPENSSL_STRING_free(idx); + return (0); + } } lh_OPENSSL_STRING_free(db->index[field]); db->index[field] = idx; @@ -244,20 +252,29 @@ int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row) } } } - /* We have passed the index checks, now just append and insert */ - if (!sk_OPENSSL_PSTRING_push(db->data, row)) { - db->error = DB_ERROR_MALLOC; - goto err; - } for (i = 0; i < db->num_fields; i++) { if (db->index[i] != NULL) { if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0)) continue; (void)lh_OPENSSL_STRING_insert(db->index[i], row); + if (lh_OPENSSL_STRING_retrieve(db->index[i], row) == NULL) + goto err1; } } + if (!sk_OPENSSL_PSTRING_push(db->data, row)) + goto err1; return (1); + + err1: + db->error = DB_ERROR_MALLOC; + while (i-- > 0) { + if (db->index[i] != NULL) { + if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0)) + continue; + (void)lh_OPENSSL_STRING_delete(db->index[i], row); + } + } err: return (0); } |