diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-06-28 20:08:14 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-06-28 20:08:14 +0200 |
commit | 3a74272a201cdfa3fd3992200d43f8f5ef34974a (patch) | |
tree | 72347531416db2251e43fca48c8d8672509ac658 /dns.c | |
parent | some changes I made on another laptop (diff) | |
download | ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar.gz ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar.bz2 ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar.lz ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar.xz ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.tar.zst ircxmpp-3a74272a201cdfa3fd3992200d43f8f5ef34974a.zip |
Diffstat (limited to 'dns.c')
-rw-r--r-- | dns.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -110,6 +110,10 @@ struct dns * dns_init (void) { return NULL; dns->fd = -1; dns->domain = strdup(" call dns_set_domain to set the domain"); + if (!dns->domain) { + free(dns); + return NULL; + } dns->domain[0] = strlen(dns->domain)-1; dns->log_handler = dns_default_log_handler; dns->sockaddr.sin_family = AF_INET; @@ -117,12 +121,23 @@ struct dns * dns_init (void) { dns->sockaddr.sin_addr.s_addr = INADDR_ANY; return dns; } -static void dns_set_domain (struct dns * dns, const char * domain) { // static functions are - int required = domain2name_len(domain, strlen(domain)); // visible inside the same - if (required <= 0) // translation unit - they - return; // are visible across - free(dns->domain); // included files - domain2name((dns->domain = malloc(required)), domain, strlen(domain)); +static void dns_set_domain (struct dns * dns, const char * domain) { + char buf[64]; + int required = domain2name_len(domain, strlen(domain)); + if (required <= 0) { + sprintf(buf, "domain2name_len failed with %d", required); + dns->log_handler(dns->log_userdata, DNS_ERROR, "dns", buf); + return; + } + char * new = malloc(required); + if (!new) { + sprintf(buf, "malloc of size %d failed", required); + dns->log_handler(dns->log_userdata, DNS_ERROR, "dns", buf); + return; + } + free(dns->domain); + dns->domain = new; + domain2name(dns->domain, domain, strlen(domain)); } static void dns_set_log_handler (struct dns * dns, dns_log_handler log_handler) { if (!log_handler) |