1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-24 19:37:48 +03:00

Use calloc instead of zeroizing structure after malloc

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2025-08-01 11:55:50 +02:00
parent 737f9ecc3c
commit d1bf9068a9
5 changed files with 9 additions and 13 deletions

View File

@@ -136,11 +136,10 @@ ssh_agent ssh_agent_new(struct ssh_session_struct *session)
{
ssh_agent agent = NULL;
agent = malloc(sizeof(struct ssh_agent_struct));
agent = calloc(1, sizeof(struct ssh_agent_struct));
if (agent == NULL) {
return NULL;
}
ZERO_STRUCTP(agent);
agent->count = 0;
agent->sock = ssh_socket_new(session);

View File

@@ -1027,12 +1027,11 @@ int ssh_userauth_agent(ssh_session session, const char *username)
}
if (!session->agent_state) {
session->agent_state = malloc(sizeof(struct ssh_agent_state_struct));
session->agent_state = calloc(1, sizeof(struct ssh_agent_state_struct));
if (!session->agent_state) {
ssh_set_error_oom(session);
return SSH_AUTH_ERROR;
}
ZERO_STRUCTP(session->agent_state);
session->agent_state->state = SSH_AGENT_STATE_NONE;
}

View File

@@ -126,11 +126,10 @@ ssh_pcap_file ssh_pcap_file_new(void)
{
struct ssh_pcap_file_struct *pcap = NULL;
pcap = malloc(sizeof(struct ssh_pcap_file_struct));
pcap = calloc(1, sizeof(struct ssh_pcap_file_struct));
if (pcap == NULL) {
return NULL;
}
ZERO_STRUCTP(pcap);
return pcap;
}
@@ -296,12 +295,13 @@ void ssh_pcap_file_free(ssh_pcap_file pcap)
*/
ssh_pcap_context ssh_pcap_context_new(ssh_session session)
{
ssh_pcap_context ctx = (struct ssh_pcap_context_struct *)malloc(sizeof(struct ssh_pcap_context_struct));
ssh_pcap_context ctx = NULL;
ctx = calloc(1, sizeof(struct ssh_pcap_context_struct));
if (ctx == NULL) {
ssh_set_error_oom(session);
return NULL;
}
ZERO_STRUCTP(ctx);
ctx->session = session;
return ctx;
}

View File

@@ -833,11 +833,10 @@ ssh_signature ssh_signature_new(void)
{
struct ssh_signature_struct *sig = NULL;
sig = malloc(sizeof(struct ssh_signature_struct));
sig = calloc(1, sizeof(struct ssh_signature_struct));
if (sig == NULL) {
return NULL;
}
ZERO_STRUCTP(sig);
return sig;
}

View File

@@ -21,11 +21,10 @@ static int myauthcallback (const char *prompt, char *buf, size_t len,
static int setup(void **state)
{
struct ssh_callbacks_struct *cb;
struct ssh_callbacks_struct *cb = NULL;
cb = malloc(sizeof(struct ssh_callbacks_struct));
cb = calloc(1, sizeof(struct ssh_callbacks_struct));
assert_non_null(cb);
ZERO_STRUCTP(cb);
cb->userdata = (void *) 0x0badc0de;
cb->auth_function = myauthcallback;