Assorted memory leak fixes on the error code paths.

--

These are taken from these commits:

98c52ae * card: Intialize pointer to avoid double free
fc5fac8 * kbx: Avoid uninitialized read
fa0771f * g10: Avoid memory leaks
25aa353 * dirmgr: Avoid double free
33a2362 * agent: Fix memory leaks
e6132bc * sm: Avoid memory leaks and double double-free
2af7bb2 * g10: Fix memory leaks
0d2c1e9 * dirmgr: clean up memory on error code paths

GnuPG-bug-id: 5393
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2021-05-20 14:51:42 +02:00
parent 9d63ba2721
commit b677e2ec98
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 23 additions and 8 deletions

View File

@ -381,7 +381,7 @@ agent_ask_new_passphrase (ctrl_t ctrl, const char *prompt,
if (!pi2) if (!pi2)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
xfree (pi2); xfree (pi);
return err; return err;
} }
pi->max_length = MAX_PASSPHRASE_LEN + 1; pi->max_length = MAX_PASSPHRASE_LEN + 1;

View File

@ -206,7 +206,7 @@ keygripstr_from_pk_file (app_t app, int fid, char *r_gripstr)
newlen = 1 + buflen[i] - offset[i]; newlen = 1 + buflen[i] - offset[i];
newbuf = xtrymalloc (newlen); newbuf = xtrymalloc (newlen);
if (!newlen) if (!newbuf)
{ {
xfree (buffer[0]); xfree (buffer[0]);
xfree (buffer[1]); xfree (buffer[1]);

View File

@ -293,7 +293,6 @@ extract_pss_params (gcry_sexp_t s_sig, int *r_algo, unsigned int *r_saltlen)
if (*r_saltlen < 20) if (*r_saltlen < 20)
{ {
log_error ("length of PSS salt too short\n"); log_error ("length of PSS salt too short\n");
gcry_sexp_release (s_sig);
return gpg_error (GPG_ERR_DIGEST_ALGO); return gpg_error (GPG_ERR_DIGEST_ALGO);
} }
if (!*r_algo) if (!*r_algo)

View File

@ -203,6 +203,7 @@ encrypt_dek (const DEK dek, ksba_cert_t cert, unsigned char **encval)
rc = encode_session_key (dek, &s_data); rc = encode_session_key (dek, &s_data);
if (rc) if (rc)
{ {
gcry_sexp_release (s_pkey);
log_error ("encode_session_key failed: %s\n", gpg_strerror (rc)); log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
return rc; return rc;
} }

View File

@ -724,8 +724,13 @@ cmd_export (assuan_context_t ctx, char *line)
if (opt_secret) if (opt_secret)
{ {
if (!list || !*list->d) if (!list)
return set_error (GPG_ERR_NO_DATA, "No key given"); return set_error (GPG_ERR_NO_DATA, "No key given");
if (!*list->d)
{
free_strlist (list);
return set_error (GPG_ERR_NO_DATA, "No key given");
}
if (list->next) if (list->next)
return set_error (GPG_ERR_TOO_MANY, "Only one key allowed"); return set_error (GPG_ERR_TOO_MANY, "Only one key allowed");
} }
@ -948,17 +953,27 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
int outfd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1); int outfd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
if ( outfd == -1 ) if ( outfd == -1 )
return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); {
free_strlist (list);
return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
}
fp = es_fdopen_nc (outfd, "w"); fp = es_fdopen_nc (outfd, "w");
if (!fp) if (!fp)
return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed"); {
free_strlist (list);
return set_error (gpg_err_code_from_syserror (),
"es_fdopen() failed");
}
} }
else else
{ {
fp = es_fopencookie (ctx, "w", data_line_cookie_functions); fp = es_fopencookie (ctx, "w", data_line_cookie_functions);
if (!fp) if (!fp)
return set_error (GPG_ERR_ASS_GENERAL, {
"error setting up a data stream"); free_strlist (list);
return set_error (GPG_ERR_ASS_GENERAL,
"error setting up a data stream");
}
} }
ctrl->with_colons = 1; ctrl->with_colons = 1;