Skip to content

Commit

Permalink
Added malloc return check
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorWeders committed Aug 20, 2024
1 parent 83af8cc commit 82bd41a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/blackwhitelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ static int add_hostname(const char *host) {
return FALSE;

blackwhitelist_record_t *tmp_record = malloc(sizeof(blackwhitelist_record_t));

if (!tmp_record)
return FALSE;

char *host_c = NULL;

if (!check_get_hostname(host)) {
Expand All @@ -55,6 +59,10 @@ static int add_hostname(const char *host) {

int blackwhitelist_load_list(const char *filename) {
char *line = malloc(HOST_MAXLEN + 1);

if (!line)
return FALSE;

size_t linelen = HOST_MAXLEN + 1;
int cnt = 0;
ssize_t read;
Expand Down
4 changes: 4 additions & 0 deletions src/dnsredir.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ static int add_udp_conntrack(const uint32_t srcip[4], const uint16_t srcport,
return FALSE;

udp_connrecord_t *tmp_connrecord = malloc(sizeof(udp_connrecord_t));

if (!tmp_connrecord)
return FALSE;

construct_key(srcip, srcport, tmp_connrecord->key, is_ipv6);

if (!check_get_udp_conntrack_key(tmp_connrecord->key, NULL)) {
Expand Down
9 changes: 9 additions & 0 deletions src/goodbyedpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ static void add_filter_str(int proto, int port) {
(proto == IPPROTO_UDP ? strlen(udp) : strlen(tcp)) + 16;
char *new_filter = malloc(new_filter_size);

if (!new_filter)
return FALSE;

strcpy(new_filter, current_filter);
if (proto == IPPROTO_UDP)
sprintf(new_filter + strlen(new_filter), udp, port, port);
Expand All @@ -221,6 +224,9 @@ static void add_ip_id_str(int id) {
const char *ipid = " or ip.Id == %d";
char *addfilter = malloc(strlen(ipid) + 16);

if (!addfilter)
return FALSE;

sprintf(addfilter, ipid, id);

newstr = repl_str(filter_string, IPID_TEMPLATE, addfilter);
Expand All @@ -241,6 +247,9 @@ static void add_maxpayloadsize_str(unsigned short maxpayload) {
"or (tcp.Payload[0] == 0x16 and tcp.Payload[1] == 0x03 and tcp.Payload[2] <= 0x03): true)";
char *addfilter = malloc(strlen(maxpayloadsize_str) + 16);

if (!addfilter)
return FALSE;

sprintf(addfilter, maxpayloadsize_str, maxpayload);

newstr = repl_str(filter_string, MAXPAYLOADSIZE_TEMPLATE, addfilter);
Expand Down
4 changes: 4 additions & 0 deletions src/ttltrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ static int add_tcp_conntrack(const uint32_t srcip[4], const uint32_t dstip[4],
return FALSE;

tcp_connrecord_t *tmp_connrecord = malloc(sizeof(tcp_connrecord_t));

if (!tmp_connrecord)
return FALSE;

construct_key(srcip, dstip, srcport, dstport, tmp_connrecord->key, is_ipv6);

if (!check_get_tcp_conntrack_key(tmp_connrecord->key, NULL)) {
Expand Down

0 comments on commit 82bd41a

Please sign in to comment.