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

add a function to parse a srv reply with ttl #393

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7a26cb6
add a function to parse a srv reply with ttl
kylebevans Jan 25, 2021
4c9f2b6
remove print statements
kylebevans Jan 25, 2021
ab66778
make ares_parse_srv_reply a wrapper for cares_parse_srv_reply
kylebevans Jan 30, 2021
73d8bf5
return const char* from cares_srv_reply_get_host
kylebevans Jan 30, 2021
eb34dbe
use ares_strdup in ares_parse_srv_reply to copy host string
kylebevans Jan 31, 2021
a86be7e
add new structs and parse functions to support TTL for these RRs:
kylebevans Mar 10, 2021
ce230f7
check hostent->h_addr_list[0] before free
kylebevans Mar 10, 2021
7078113
Merge branch 'master' into kylebevans-ttl
kylebevans Mar 10, 2021
3d06d06
fix loop off by one for freeing h_aliases
kylebevans Mar 10, 2021
a6c585c
modify ptr parsing to use the last hostname as h_name
kylebevans Mar 11, 2021
b55ccb9
use ptr_curr instead of ptr_out to get h_name
kylebevans Mar 11, 2021
08de712
fix memory leaks
kylebevans Mar 13, 2021
7eae6d8
remove debug prints and fix unrelated Container test leak
kylebevans Mar 13, 2021
a82fed6
Merge branch 'main' into kylebevans-ttl
kylebevans Nov 7, 2021
3179732
406 - Validate hostnames in DNS responses
kylebevans Nov 7, 2021
1e03b81
fix a missed a conflict in ares.h
kylebevans Nov 7, 2021
d36bec7
add is_hostname parameter back in one spot
kylebevans Nov 7, 2021
2814894
change struct cares_ to just cares_ for declarations
kylebevans Nov 7, 2021
7fcb191
change ttl in ares_uri_reply to be unsigned int
kylebevans Nov 7, 2021
487d072
change ARES_DATATYPE_C prefix to CARES_DATATYPE_ prefix
kylebevans Nov 7, 2021
97143cc
return const from cares_get_next functions
kylebevans Nov 12, 2021
699a9cd
create cares_memdup function as sugar for malloc/memcpy pattern
kylebevans Nov 12, 2021
3286a5d
save progress
kylebevans Dec 29, 2021
aed6a71
save progress
kylebevans Dec 29, 2021
baf30b8
save progress
kylebevans Dec 30, 2021
6983bc3
add free routine for container
kylebevans Dec 30, 2021
39c8e55
add malloc routine for container
kylebevans Dec 31, 2021
385a3fe
change cares_parse_srv_reply to use container
kylebevans Dec 31, 2021
697b9fd
change ares_parse_srv_reply to use container
kylebevans Dec 31, 2021
de092f3
fix errors and warnings
kylebevans Dec 31, 2021
9583762
fix errors and warnings
kylebevans Dec 31, 2021
e22efd5
add debugging
kylebevans Jan 1, 2022
f349105
fix crashes and add debugging
kylebevans Jan 2, 2022
867e3f7
fix crashes
kylebevans Jan 2, 2022
0f5ba50
remove print statements
kylebevans Jan 2, 2022
9268be0
Add build/test instructions for asan
kylebevans Jan 2, 2022
13aec44
update build/test instructions for asan
kylebevans Jan 2, 2022
86daca3
update build/test instructions for asan
kylebevans Jan 2, 2022
9f7b8b9
update build/test instructions for asan
kylebevans Jan 2, 2022
487cb0c
attempt to fix leak
kylebevans Jan 2, 2022
84d87cb
attempt to fix leak
kylebevans Jan 2, 2022
f131cf2
add missing break statement
kylebevans Jan 2, 2022
8bca0fa
free srv_host on error
kylebevans Jan 2, 2022
979f715
add debugging
kylebevans Jan 2, 2022
183a999
fix leak if no srv rr type
kylebevans Jan 3, 2022
e247b6e
add fuzzing loop instrution
kylebevans Jan 3, 2022
e1bb47d
fix typo for cares_free_container.h
kylebevans Jan 3, 2022
73248f7
remove debugging print statements
kylebevans Jan 3, 2022
337db1d
Update instructions for lsan
kylebevans Jan 4, 2022
be37e6a
Update instructions for lsan
kylebevans Jan 4, 2022
e82ff03
change srv to csrv
kylebevans Jan 4, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ CHANGES.dist
c-ares-*.tar.gz.asc
ares_parse_mx_reply.pdf
/[0-9]*.patch
.dirstamp
210 changes: 205 additions & 5 deletions include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,18 @@ struct ares_caa_reply {
size_t length; /* length excludes null termination */
};

struct cares_caa_reply;

typedef struct cares_caa_reply cares_caa_reply;

struct cares_ptr_reply;

typedef struct cares_ptr_reply cares_ptr_reply;

struct cares_ns_reply;

typedef struct cares_ns_reply cares_ns_reply;

struct ares_srv_reply {
struct ares_srv_reply *next;
char *host;
Expand All @@ -545,12 +557,24 @@ struct ares_srv_reply {
unsigned short port;
};

struct cares_srv_reply;

typedef struct cares_srv_reply cares_srv_reply;

struct cares_host_reply;

typedef struct cares_host_reply cares_host_reply;

struct ares_mx_reply {
struct ares_mx_reply *next;
char *host;
unsigned short priority;
};

struct cares_mx_reply;

typedef struct cares_mx_reply cares_mx_reply;

struct ares_txt_reply {
struct ares_txt_reply *next;
unsigned char *txt;
Expand All @@ -568,6 +592,10 @@ struct ares_txt_ext {
unsigned char record_start;
};

struct cares_txt_reply;

typedef struct cares_txt_reply cares_txt_reply;

struct ares_naptr_reply {
struct ares_naptr_reply *next;
unsigned char *flags;
Expand All @@ -578,6 +606,10 @@ struct ares_naptr_reply {
unsigned short preference;
};

struct cares_naptr_reply;

typedef struct cares_naptr_reply cares_naptr_reply;

struct ares_soa_reply {
char *nsname;
char *hostmaster;
Expand All @@ -588,6 +620,10 @@ struct ares_soa_reply {
unsigned int minttl;
};

struct cares_soa_reply;

typedef struct cares_soa_reply cares_soa_reply;

/*
* Similar to addrinfo, but with extra ttl and missing canonname.
*/
Expand Down Expand Up @@ -647,8 +683,33 @@ CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
int *naddrttls);

CARES_EXTERN int ares_parse_caa_reply(const unsigned char* abuf,
int alen,
struct ares_caa_reply** caa_out);
int alen,
struct ares_caa_reply** caa_out);

CARES_EXTERN int cares_parse_caa_reply(const unsigned char* abuf,
int alen,
struct cares_caa_reply** caa_out);

CARES_EXTERN struct cares_caa_reply*
cares_caa_reply_get_next(const cares_caa_reply* caa_reply);

CARES_EXTERN int
cares_caa_reply_get_critical(const cares_caa_reply* caa_reply);

CARES_EXTERN const unsigned char*
cares_caa_reply_get_property(const cares_caa_reply* caa_reply);

CARES_EXTERN size_t
cares_caa_reply_get_plength(const cares_caa_reply* caa_reply);

CARES_EXTERN const unsigned char*
cares_caa_reply_get_value(const cares_caa_reply* caa_reply);

CARES_EXTERN size_t
cares_caa_reply_get_length(const cares_caa_reply* caa_reply);

CARES_EXTERN unsigned int cares_caa_reply_get_ttl(const cares_caa_reply*
caa_reply);

CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
int alen,
Expand All @@ -657,17 +718,81 @@ CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
int family,
struct hostent **host);

CARES_EXTERN int cares_parse_ptr_reply(const unsigned char *abuf,
int alen,
struct cares_ptr_reply **ptr_out);

CARES_EXTERN struct cares_ptr_reply*
cares_ptr_reply_get_next(const cares_ptr_reply* ptr_reply);

CARES_EXTERN const char*
cares_ptr_reply_get_host(const cares_ptr_reply* ptr_reply);

CARES_EXTERN unsigned int cares_ptr_reply_get_ttl(const cares_ptr_reply*
ptr_reply);

CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf,
int alen,
struct hostent **host);

CARES_EXTERN int cares_parse_ns_reply(const unsigned char *abuf,
int alen,
struct cares_ns_reply **ns_out);

CARES_EXTERN struct cares_ns_reply*
cares_ns_reply_get_next(const cares_ns_reply* ns_reply);

CARES_EXTERN const char*
cares_ns_reply_get_host(const cares_ns_reply* ns_reply);

CARES_EXTERN unsigned int cares_ns_reply_get_ttl(const cares_ns_reply*
ns_reply);

CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf,
int alen,
struct ares_srv_reply** srv_out);

CARES_EXTERN int cares_parse_srv_reply(const unsigned char* abuf,
int alen,
struct cares_srv_reply** srv_out);

CARES_EXTERN cares_srv_reply*
cares_srv_reply_get_next(const cares_srv_reply* srv_reply);

CARES_EXTERN const char*
cares_srv_reply_get_host(const cares_srv_reply* srv_reply);

CARES_EXTERN unsigned short
cares_srv_reply_get_priority(const cares_srv_reply* srv_reply);

CARES_EXTERN unsigned short
cares_srv_reply_get_weight(const cares_srv_reply* srv_reply);

CARES_EXTERN unsigned short
cares_srv_reply_get_port(const cares_srv_reply* srv_reply);

CARES_EXTERN unsigned int cares_srv_reply_get_ttl(const cares_srv_reply*
srv_reply);

CARES_EXTERN int ares_parse_mx_reply(const unsigned char* abuf,
int alen,
struct ares_mx_reply** mx_out);

CARES_EXTERN int cares_parse_mx_reply(const unsigned char* abuf,
int alen,
struct ares_mx_reply** mx_out);
struct cares_mx_reply** mx_out);

CARES_EXTERN struct cares_mx_reply*
cares_mx_reply_get_next(const cares_mx_reply* mx_reply);

CARES_EXTERN const char*
cares_mx_reply_get_host(const cares_mx_reply* mx_reply);

CARES_EXTERN unsigned short
cares_mx_reply_get_priority(const cares_mx_reply* mx_reply);

CARES_EXTERN unsigned int cares_mx_reply_get_ttl(const cares_mx_reply*
mx_reply);

CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
int alen,
Expand All @@ -677,13 +802,88 @@ CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf,
int alen,
struct ares_txt_ext** txt_out);

CARES_EXTERN int cares_parse_txt_reply(const unsigned char* abuf,
int alen,
struct cares_txt_reply** txt_out);

CARES_EXTERN struct cares_txt_reply*
cares_txt_reply_get_next(const cares_txt_reply* txt_reply);

CARES_EXTERN const unsigned char*
cares_txt_reply_get_txt(const cares_txt_reply* txt_reply);

CARES_EXTERN size_t
cares_txt_reply_get_length(const cares_txt_reply* txt_reply);

CARES_EXTERN unsigned char
cares_txt_reply_get_record_start(const cares_txt_reply* txt_reply);

CARES_EXTERN unsigned int cares_txt_reply_get_ttl(const cares_txt_reply*
txt_reply);

CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
int alen,
struct ares_naptr_reply** naptr_out);

CARES_EXTERN int cares_parse_naptr_reply(const unsigned char* abuf,
int alen,
struct cares_naptr_reply** naptr_out);

CARES_EXTERN struct cares_naptr_reply*
cares_naptr_reply_get_next(const cares_naptr_reply* naptr_reply);

CARES_EXTERN const unsigned char*
cares_naptr_reply_get_flags(const cares_naptr_reply* naptr_reply);

CARES_EXTERN const unsigned char*
cares_naptr_reply_get_service(const cares_naptr_reply* naptr_reply);

CARES_EXTERN const unsigned char*
cares_naptr_reply_get_regexp(const cares_naptr_reply* naptr_reply);

CARES_EXTERN const char*
cares_naptr_reply_get_replacement(const cares_naptr_reply* naptr_reply);

CARES_EXTERN unsigned short
cares_naptr_reply_get_order(const cares_naptr_reply* naptr_reply);

CARES_EXTERN unsigned short
cares_naptr_reply_get_preference(const cares_naptr_reply* naptr_reply);

CARES_EXTERN unsigned int cares_naptr_reply_get_ttl(const cares_naptr_reply*
naptr_reply);

CARES_EXTERN int ares_parse_soa_reply(const unsigned char* abuf,
int alen,
struct ares_soa_reply** soa_out);
int alen,
struct ares_soa_reply** soa_out);

CARES_EXTERN int cares_parse_soa_reply(const unsigned char* abuf,
int alen,
struct cares_soa_reply** soa_out);

CARES_EXTERN const char*
cares_soa_reply_get_nsname(const cares_soa_reply* soa_reply);

CARES_EXTERN const char*
cares_soa_reply_get_hostmaster(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int
cares_soa_reply_get_serial(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int
cares_soa_reply_get_refresh(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int
cares_soa_reply_get_retry(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int
cares_soa_reply_get_expire(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int
cares_soa_reply_get_minttl(const cares_soa_reply* soa_reply);

CARES_EXTERN unsigned int cares_soa_reply_get_ttl(const cares_soa_reply*
soa_reply);

CARES_EXTERN void ares_free_string(void *str);

Expand Down
9 changes: 9 additions & 0 deletions src/lib/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@ CSOURCES = ares__close_sockets.c \
ares_parse_a_reply.c \
ares_parse_aaaa_reply.c \
ares_parse_caa_reply.c \
cares_parse_caa_reply.c \
ares_parse_mx_reply.c \
cares_parse_mx_reply.c \
ares_parse_naptr_reply.c \
cares_parse_naptr_reply.c \
ares_parse_ns_reply.c \
cares_parse_ns_reply.c \
ares_parse_ptr_reply.c \
cares_parse_ptr_reply.c \
ares_parse_soa_reply.c \
cares_parse_soa_reply.c \
ares_parse_srv_reply.c \
cares_parse_srv_reply.c \
ares_parse_txt_reply.c \
cares_parse_txt_reply.c \
ares_platform.c \
ares_process.c \
ares_query.c \
cares_reply.c \
ares_search.c \
ares_send.c \
ares_strcasecmp.c \
Expand Down
Loading