Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static code analysis warnings #428

Merged
merged 7 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ gvm_log_func (const char *log_domain, GLogLevelFlags log_level,
log_domain_entry = entry;

/* Get the struct contents. */
prepend_format = log_domain_entry->prepend_string;
if (log_domain_entry->prepend_string)
prepend_format = log_domain_entry->prepend_string;
time_format = log_domain_entry->prepend_time_format;
log_file = log_domain_entry->log_file;
if (log_domain_entry->default_level)
Expand Down
4 changes: 3 additions & 1 deletion base/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,10 @@ ip_islocalhost (struct sockaddr_storage *storage)
if (ifa->ifa_addr->sa_family == AF_INET6)
{
sin6 = (struct sockaddr_in6 *) (ifa->ifa_addr);

/* Check if same address as local interface. */
if (IN6_ARE_ADDR_EQUAL (&(sin6->sin6_addr), addr6_p))
if (family == AF_INET6
&& IN6_ARE_ADDR_EQUAL (&(sin6->sin6_addr), addr6_p))
return TRUE;
}
}
Expand Down
3 changes: 2 additions & 1 deletion boreas/boreas_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ get_host_from_queue (kb_t alive_hosts_kb, gboolean *alive_deteciton_finished)
else
{
host = gvm_host_from_str (host_str);
g_free (host_str);

if (!host)
{
g_warning ("%s: Could not transform IP string \"%s\" into "
"internal representation.",
__func__, host_str);
g_free (host_str);
return NULL;
}
else
{
g_free (host_str);
return host;
}
}
Expand Down
6 changes: 5 additions & 1 deletion osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ osp_connection_new (const char *host, int port, const char *cacert,
connection = g_malloc0 (sizeof (*connection));
connection->socket = socket (AF_UNIX, SOCK_STREAM, 0);
if (connection->socket == -1)
return NULL;
{
g_free (connection);
return NULL;
}

addr.sun_family = AF_UNIX;
strncpy (addr.sun_path, host, sizeof (addr.sun_path) - 1);
len = strlen (addr.sun_path) + sizeof (addr.sun_family);
if (connect (connection->socket, (struct sockaddr *) &addr, len) == -1)
{
close (connection->socket);
g_free (connection);
return NULL;
}
}
Expand Down
1 change: 1 addition & 0 deletions util/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ redis_direct_conn (const char *kb_path, const int kb_index)
freeReplyObject (rep);
redisFree (kbr->rctx);
kbr->rctx = NULL;
g_free (kbr);
return NULL;
}
freeReplyObject (rep);
Expand Down
11 changes: 10 additions & 1 deletion util/serverutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,23 @@ set_gnutls_dhparams (gnutls_certificate_credentials_t creds,

if (load_gnutls_file (dhparams_file, &data))
return -1;

/* Disable false positive warning about potential leak of memory */
#ifndef __clang_analyzer__

gnutls_dh_params_t params = g_malloc0 (sizeof (gnutls_dh_params_t));
ret = gnutls_dh_params_import_pkcs3 (params, &data, GNUTLS_X509_FMT_PEM);
unload_gnutls_file (&data);
if (ret)
return -1;
{
g_free (params);
return -1;
}
else
gnutls_certificate_set_dh_params (creds, params);
return 0;

#endif
}

/**
Expand Down