err_set_debug(): Prevent possible recursion on malloc failure
Fixes
* https://www.openssl.org/source/license.html
*/
+#include <string.h>
#include <openssl/err.h>
#include <openssl/e_os2.h>
@@ -56,8 +57,11 @@ static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
OPENSSL_free(es->err_file[i]);
if (file == NULL || file[0] == '\0')
es->err_file[i] = NULL;
- else
- es->err_file[i] = OPENSSL_strdup(file);
+ else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
+ NULL, 0)) != NULL)
+ /* We cannot use OPENSSL_strdup due to possible recursion */
+ strcpy(es->err_file[i], file);
+
es->err_line[i] = line;
OPENSSL_free(es->err_func[i]);
if (fn == NULL || fn[0] == '\0')
