Skip to content

Commit

Permalink
Change: Instead of using g_memdup2 set deprecation for it as warning
Browse files Browse the repository at this point in the history
Since g_memdup2 will use a 32bit number instead of a 64bit there could
be the case that it will allocate less memory than anticipated could due
to lack of control end up in an overflow scenario.

To prevent that we will leave it as g_memdup but redurce the severity
down to a warning instead of an error.
  • Loading branch information
nichtsfrei authored and y0urself committed Oct 22, 2021
1 parent 1ec2d41 commit 824238a
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 3 deletions.
4 changes: 4 additions & 0 deletions misc/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ socket_negotiate_ssl (int fd, openvas_encaps_t transport,
* @param[out] cert Memory pointer to fill cert pointer.
* @param[out] certlen Size of cert.
*/

void
socket_get_cert (int fd, void **cert, int *certlen)
{
Expand All @@ -763,7 +764,10 @@ socket_get_cert (int fd, void **cert, int *certlen)
if (cert_list_len == 0)
return;
*certlen = cert_list[0].size;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
*cert = g_memdup (cert_list[0].data, *certlen);
#pragma GCC diagnostic pop
}

/*
Expand Down
12 changes: 12 additions & 0 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,21 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
{
if (type != NULL)
*type = KB_TYPE_INT;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
ret = g_memdup (&res->v_int, sizeof (res->v_int));
#pragma GCC diagnostic pop
}
else
{
if (type != NULL)
*type = KB_TYPE_STR;
if (len)
*len = res->len;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
ret = g_memdup (res->v_str, res->len + 1);
#pragma GCC diagnostic pop
}
kb_item_free (res);
return ret;
Expand All @@ -951,15 +957,21 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
{
if (type != NULL)
*type = KB_TYPE_INT;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
ret = g_memdup (&res->v_int, sizeof (res->v_int));
#pragma GCC diagnostic pop
}
else
{
if (type != NULL)
*type = KB_TYPE_STR;
if (len)
*len = res->len;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
ret = g_memdup (res->v_str, res->len + 1);
#pragma GCC diagnostic pop
}
kb_item_free (res_list);
return ret;
Expand Down
6 changes: 6 additions & 0 deletions nasl/nasl_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@ nasl_cert_query (lex_ctxt *lexic)

retc = alloc_typed_cell (CONST_DATA);
retc->size = m.size;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (m.data, m.size);
#pragma GCC diagnostic pop
gnutls_free (m.data);
gnutls_free (e.data);
gnutls_x509_crt_deinit (cert);
Expand All @@ -949,7 +952,10 @@ nasl_cert_query (lex_ctxt *lexic)

retc = alloc_typed_cell (CONST_DATA);
retc->size = e.size;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (e.data, e.size);
#pragma GCC diagnostic pop
gnutls_free (m.data);
gnutls_free (e.data);
gnutls_x509_crt_deinit (cert);
Expand Down
9 changes: 9 additions & 0 deletions nasl/nasl_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ nasl_gcrypt_hash (lex_ctxt *lexic, int algorithm, void *data, size_t datalen,
gcry_md_write (hd, data, datalen);

retc = alloc_typed_cell (CONST_DATA);
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (gcry_md_read (hd, algorithm), dlen + 1);
#pragma GCC diagnostic pop
retc->size = dlen;

gcry_md_close (hd);
Expand Down Expand Up @@ -340,7 +343,10 @@ hmac_sha384 (const void *key, int keylen, const void *buf, int buflen)
}

gcry_md_write (hd, buf, buflen);
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
ret = g_memdup (gcry_md_read (hd, 0), 48);
#pragma GCC diagnostic pop
gcry_md_close (hd);
return ret;
}
Expand Down Expand Up @@ -830,7 +836,10 @@ nasl_lm_owf_gen (lex_ctxt *lexic)

retc = alloc_typed_cell (CONST_DATA);
retc->size = 16;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (p16, 16);
#pragma GCC diagnostic pop
return retc;
}

Expand Down
6 changes: 6 additions & 0 deletions nasl/nasl_crypto2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,10 @@ encrypt_stream_data (lex_ctxt *lexic, int cipher, const char *caller_func)
if (cipher == GCRY_CIPHER_ARCFOUR)
{
resultlen = datalen;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
tmp = g_memdup (data, datalen);
#pragma GCC diagnostic pop
tmplen = datalen;
}
else
Expand Down Expand Up @@ -1732,7 +1735,10 @@ encrypt_data (lex_ctxt *lexic, int cipher, int mode)
if (cipher == GCRY_CIPHER_ARCFOUR)
{
resultlen = datalen;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
tmp = g_memdup (data, datalen);
#pragma GCC diagnostic pop
tmplen = datalen;
}
else if (cipher == GCRY_CIPHER_3DES)
Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl_misc_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ nasl_telnet_init (lex_ctxt *lexic)
n += n2;
retc = alloc_typed_cell (CONST_DATA);
retc->size = n;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (buffer, n + 1);
#pragma GCC diagnostic pop
#undef iac
#undef data
#undef option
Expand Down
9 changes: 7 additions & 2 deletions nasl/nasl_packet_forgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,13 @@ get_icmp_element (lex_ctxt *lexic)
retc->size =
get_var_size_by_name (lexic, "icmp") - (ip->ip_hl * 4) - 8;
if (retc->size > 0)
retc->x.str_val =
g_memdup (&(p[ip->ip_hl * 4 + 8]), retc->size + 1);
{
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val =
g_memdup (&(p[ip->ip_hl * 4 + 8]), retc->size + 1);
#pragma GCC diagnostic pop
}
else
{
retc->x.str_val = NULL;
Expand Down
7 changes: 6 additions & 1 deletion nasl/nasl_packet_forgery_v6.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,12 @@ get_icmp_v6_element (lex_ctxt *lexic)
retc = alloc_typed_cell (CONST_DATA);
retc->size = get_var_size_by_name (lexic, "icmp") - 40 - 8;
if (retc->size > 0)
retc->x.str_val = g_memdup (&(p[40 + 8]), retc->size + 1);
{
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (&(p[40 + 8]), retc->size + 1);
#pragma GCC diagnostic pop
}
else
{
retc->x.str_val = NULL;
Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl_scanner_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,10 @@ security_something (lex_ctxt *lexic, proto_post_something_t proto_post_func,
int len = get_var_size_by_name (lexic, "data");
int i;

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
dup = g_memdup (data, len + 1);
#pragma GCC diagnostic pop
for (i = 0; i < len; i++)
if (dup[i] == 0)
dup[i] = ' ';
Expand Down
12 changes: 12 additions & 0 deletions nasl/nasl_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ add_udp_data (struct script_infos *script_infos, int soc, char *data, int len)
{
GHashTable *udp_data = script_infos->udp_data;
struct udp_record *data_record = g_malloc0 (sizeof (struct udp_record));
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
int *key = g_memdup (&soc, sizeof (int));
#pragma GCC diagnostic pop

data_record->len = len;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
data_record->data = g_memdup ((gconstpointer) data, (guint) len);
#pragma GCC diagnostic pop

if (udp_data == NULL)
{
Expand Down Expand Up @@ -779,7 +785,10 @@ nasl_recv (lex_ctxt *lexic)
if (new_len > 0)
{
tree_cell *retc = alloc_typed_cell (CONST_DATA);
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (data, new_len);
#pragma GCC diagnostic pop
retc->size = new_len;
g_free (data);
return retc;
Expand Down Expand Up @@ -848,7 +857,10 @@ nasl_recv_line (lex_ctxt *lexic)

retc = alloc_typed_cell (CONST_DATA);
retc->size = new_len;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (data, new_len + 1);
#pragma GCC diagnostic pop

g_free (data);

Expand Down
9 changes: 9 additions & 0 deletions nasl/nasl_text_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ nasl_tolower (lex_ctxt *lexic)
if (str == NULL)
return NULL;

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
str = g_memdup (str, str_len + 1);
#pragma GCC diagnostic pop
for (i = 0; i < str_len; i++)
str[i] = tolower (str[i]);

Expand All @@ -427,7 +430,10 @@ nasl_toupper (lex_ctxt *lexic)
if (str == NULL)
return NULL;

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
str = g_memdup (str, str_len + 1);
#pragma GCC diagnostic pop
for (i = 0; i < str_len; i++)
str[i] = toupper (str[i]);

Expand Down Expand Up @@ -1248,7 +1254,10 @@ nasl_strstr (lex_ctxt *lexic)

retc = alloc_typed_cell (CONST_DATA);
retc->size = sz_a - (c - a);
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
retc->x.str_val = g_memdup (c, retc->size + 1);
#pragma GCC diagnostic pop
return retc;
}

Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,11 @@ get_variable_by_name (lex_ctxt *ctxt, const char *name)
break;
case VAR2_STRING:
case VAR2_DATA:
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
v->string_form =
g_memdup ((char *) v->v.v_str.s_val ?: "", v->v.v_str.s_siz + 1);
#pragma GCC diagnostic pop
break;
case VAR2_UNDEF:
break;
Expand Down

0 comments on commit 824238a

Please sign in to comment.