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

Added malloc return check #581

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
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;

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 ;
EgorWeders marked this conversation as resolved.
Show resolved Hide resolved

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 ;

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