ts: fix double free on error path.
authorPauli <pauli@openssl.org>
Sun, 18 Apr 2021 22:55:37 +0000 (08:55 +1000)
committerPauli <pauli@openssl.org>
Tue, 20 Apr 2021 23:20:54 +0000 (09:20 +1000)
commita3dea76f742896b7d75a0c0529c0af1e628bd853
tree6cab2f04240ca7672d00c99b30e0819e9e66d9ea
parent7f424d16c5358a2c5c652cd23b841e44550d1027
ts: fix double free on error path.

In function int_ts_RESP_verify_token, if (flags & TS_VFY_DATA) is true, function ts_compute_imprint() will be called at line 299.
In the implementation of ts_compute_imprint, it allocates md_alg at line 406.
But after the allocation, if the execution goto err, then md_alg will be freed in the first time by X509_ALGOR_free at line 439.

After that, ts_compute_imprint returns 0 and the execution goto err branch of int_ts_RESP_verify_token.
In the err branch, md_alg will be freed in the second time at line 320.

Bug reported by @Yunlongs

Fixes #14914

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14921)

(cherry picked from commit db78c84eb2fa9c41124690bcc2ea50e05f5fc7b7)
crypto/ts/ts_rsp_verify.c