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 more warnings #795

Merged
merged 15 commits into from
Jul 9, 2021
2 changes: 0 additions & 2 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Build and upload docker images
on:
push:
branches: [ master, openvas-20.08, openvas-21.04 ]
pull_request:
branches: [ master, openvas-20.08, openvas-21.04 ]

jobs:
upload-testing:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
### Fixed

- Fix clang-analyzer warnings. [#791](https://github.com/greenbone/openvas/pull/791)
- Fix clang-analyzer warnings.
[#791](https://github.com/greenbone/openvas/pull/791)
[#795](https://github.com/greenbone/openvas/pull/795)

[Unreleased]: https://github.com/greenbone/openvas-scanner/compare/v20.8.2...HEAD

Expand Down
2 changes: 1 addition & 1 deletion misc/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ v6_routethrough (struct in6_addr *dest, struct in6_addr *source)
int numinterfaces = 0;
static int numroutes = 0;
struct in6_addr mask;
struct in6_addr network;
struct in6_addr network = {0};
struct in6_addr src;
long best_match = -1;

Expand Down
4 changes: 2 additions & 2 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
if (kb == NULL)
return NULL;

if (single && *type != KB_TYPE_INT)
if (single && type != NULL && *type != KB_TYPE_INT)
res = kb_item_get_single (kb, name, KB_TYPE_UNSPEC);
else if (*type == KB_TYPE_INT)
else if (type != NULL && *type == KB_TYPE_INT)
res = kb_item_get_single (kb, name, KB_TYPE_INT);
else
res = kb_item_get_all (kb, name);
Expand Down
2 changes: 1 addition & 1 deletion nasl/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ nasl_exec (lex_ctxt *lexic, tree_cell *st)
}

if (len2 == 0 || len1 < len2
|| (p = memmem (p1, len1, p2, len2)) == NULL)
|| (p1 != NULL && (p = memmem (p1, len1, p2, len2)) == NULL))
{
s3 = g_malloc0 (len1 + 1);
memcpy (s3, p1, len1);
Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl-lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,8 @@ main (int argc, char **argv)
err += process_files (nvt_files, mode, script_infos);

g_print ("%d errors found\n", err);

g_free (script_infos);

return err;
}
5 changes: 4 additions & 1 deletion nasl/nasl_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ tls_prf (const void *secret, size_t secret_len, const void *seed,

Ai = hmac_func (secret, secret_len, lseed, lslen);
if (!Ai)
return NULL;
{
g_free (lseed);
return NULL;
}

result = g_malloc0 (outlen);
while (pos < outlen)
Expand Down
6 changes: 4 additions & 2 deletions nasl/nasl_crypto2.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ delete_cipher_item (int cipher_id)
(GCompareFunc) find_cipher_hd);
hd = (cipher_table_item_t *) hd_item->data;
gcry_cipher_close ((gcry_cipher_hd_t) hd->hd);
g_free (hd_item->data);
cipher_table = g_list_remove (cipher_table, hd_item->data);
g_free (hd_item->data);
}

/**
Expand Down Expand Up @@ -1698,7 +1698,8 @@ encrypt_data (lex_ctxt *lexic, int cipher, int mode)
{
gcry_cipher_hd_t hd;
gcry_error_t error;
void *result, *data, *key, *tmp, *iv;
void *result, *data, *key, *iv;
void *tmp = NULL;
size_t resultlen, datalen, keylen, tmplen, ivlen;
tree_cell *retc;

Expand Down Expand Up @@ -1776,6 +1777,7 @@ encrypt_data (lex_ctxt *lexic, int cipher, int mode)
if ((error = gcry_cipher_setiv (hd, iv, ivlen)))
{
nasl_perror (lexic, "gcry_cipher_setiv: %s", gcry_strerror (error));
g_free (tmp);
return NULL;
}
}
Expand Down
5 changes: 4 additions & 1 deletion nasl/nasl_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ nasl_func_call (lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
nasl_trace (lexic, "NASL> %s)\n", trace_buf);
else
nasl_trace (lexic, "NASL> %s ...)\n", trace_buf);
g_free (trace_buf);
}
/* trace_buf freed here because nasl_trace_fp might get set to NULL during the
* execution of nasl_func_call and therefore not get freed if we only free in
* the previous if block. This is done to make static analyzer happy. */
g_free (trace_buf);

/* 4. Chain new context to old (lexic) */
lexic2->up_ctxt = lexic;
Expand Down
5 changes: 4 additions & 1 deletion nasl/nasl_misc_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ nasl_sort_array (lex_ctxt *lexic)
if (retc != NULL)
{
a = retc->x.ref_val;
qsort (a->num_elt, a->max_idx, sizeof (a->num_elt[0]), var_cmp);
if (a->num_elt != NULL)
{
qsort (a->num_elt, a->max_idx, sizeof (a->num_elt[0]), var_cmp);
}
}
mylexic = NULL;
return retc;
Expand Down
26 changes: 21 additions & 5 deletions nasl/nasl_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,24 +1436,40 @@ nasl_socket_cert_verify (lex_ctxt *lexic)
for (i = 0; i < cert_n; i++)
{
if (gnutls_x509_crt_init (&cert[i]) != GNUTLS_E_SUCCESS)
return NULL;
{
g_free (cert);
return NULL;
}
if (gnutls_x509_crt_import (cert[i], &certs[i], GNUTLS_X509_FMT_DER)
!= GNUTLS_E_SUCCESS)
return NULL;
{
g_free (cert);
return NULL;
}
}

/* Init ca_list and load system CA trust list */
if ((ret = gnutls_x509_trust_list_init (&ca_list, ca_list_size)) < 0)
return NULL;
{
g_free (cert);
return NULL;
}
ret = gnutls_x509_trust_list_add_system_trust (ca_list, 0, 0);
if (ret < 0)
return NULL;
{
g_free (cert);
return NULL;
}

/* Certificate verification against a trust list*/
if (gnutls_x509_trust_list_verify_crt (ca_list, cert, cert_n, 0, &voutput,
NULL)
!= GNUTLS_E_SUCCESS)
return NULL;
{
g_free (cert);
return NULL;
}
g_free (cert);

ret = voutput;

Expand Down
4 changes: 2 additions & 2 deletions nasl/nasl_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,8 @@ nasl_ssh_request_exec (lex_ctxt *lexic)
int verbose;
char *cmd;
int rc;
GString *response, *compat_buf;
GString *response;
GString *compat_buf = NULL;
size_t len = 0;
tree_cell *retc;
char *p;
Expand Down Expand Up @@ -1380,7 +1381,6 @@ nasl_ssh_request_exec (lex_ctxt *lexic)
if (to_stderr < 0)
to_stderr = 0;

memset (&compat_buf, '\0', sizeof (compat_buf));
/* Allocate some space in advance. Most commands won't output too
much and thus 512 bytes (6 standard terminal lines) should often
be sufficient. */
Expand Down
2 changes: 2 additions & 0 deletions nasl/nasl_text_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ _regreplace (const char *pattern, const char *replace, const char *string,

if (err && err != REG_NOMATCH)
{
g_free (buf);
return (NULL);
}
if (!err)
Expand Down Expand Up @@ -725,6 +726,7 @@ nasl_egrep (lex_ctxt *lexic)
{
nasl_perror (
lexic, "egrep() : regcomp() failed for pattern '%s'.\n", pattern);
g_free (rets);
return NULL;
}

Expand Down
2 changes: 2 additions & 0 deletions nasl/smb_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ NTLMv2_generate_response_ntlmssp (const uchar ntlm_v2_hash[16],
memcpy (nt_response, ntlmv2_response, sizeof (ntlmv2_response));
memcpy (nt_response + sizeof (ntlmv2_response), ntlmv2_client_data,
client_data_len);

g_free (ntlmv2_client_data);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ store_file (struct scan_globals *globals, const char *file,

size_t bytes = 0;

if (!file_hash && *file_hash == '\0')
if (!file_hash || *file_hash == '\0')
return -1;

origname = g_strdup (file_hash);
Expand Down