case DNS_T_TXT:
case DNS_T_SPF:
if (datalen <= *remain) {
+ if (datalen > UINT16_MAX / 2) {
+ rdns_info ("too large datalen; domain %s", rep->requested_name);
+ return -1;
+ }
elt->content.txt.data = malloc(datalen + 1);
if (elt->content.txt.data == NULL) {
rdns_err ("failed to allocate %d bytes for TXT record; domain %s",
rdns_info ("stripped dns reply while reading TLSA record; domain %s", rep->requested_name);
return -1;
}
+ if (datalen > UINT16_MAX / 2) {
+ rdns_info ("too large datalen; domain %s", rep->requested_name);
+ return -1;
+ }
GET8 (elt->content.tlsa.usage);
GET8 (elt->content.tlsa.selector);
GET8 (elt->content.tlsa.match_type);
hints.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;
snprintf (portbuf, sizeof (portbuf), "%d", (int)port);
- if ((r = getaddrinfo (credits, portbuf, &hints, &res)) == 0) {
+ if (getaddrinfo (credits, portbuf, &hints, &res) == 0) {
r = rdns_make_inet_socket (type, res, psockaddr, psocklen);
if (r != -1 && psockaddr) {
if (cpy == NULL) {
close (r);
+ freeaddrinfo (res);
return -1;
}
{
int fd;
struct stat st;
+ if ((fd = open (filename, O_RDONLY)) == -1) {
+ ucl_create_err (err, "cannot open file %s: %s",
+ filename, strerror (errno));
+ return false;
+ }
- if (stat (filename, &st) == -1) {
+ if (fstat (fd, &st) == -1) {
if (must_exist || errno == EPERM) {
ucl_create_err (err, "cannot stat file %s: %s",
filename, strerror (errno));
}
+ close (fd);
+
return false;
}
if (!S_ISREG (st.st_mode)) {
if (must_exist) {
ucl_create_err (err, "file %s is not a regular file", filename);
}
+ close (fd);
return false;
}
+
if (st.st_size == 0) {
/* Do not map empty files */
*buf = NULL;
*buflen = 0;
}
else {
- if ((fd = open (filename, O_RDONLY)) == -1) {
- ucl_create_err (err, "cannot open file %s: %s",
- filename, strerror (errno));
- return false;
- }
- if ((*buf = ucl_mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
- close (fd);
- ucl_create_err (err, "cannot mmap file %s: %s",
- filename, strerror (errno));
+ if ((*buf = ucl_mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+ close(fd);
+ ucl_create_err(err, "cannot mmap file %s: %s",
+ filename, strerror(errno));
*buf = NULL;
return false;
}
*buflen = st.st_size;
- close (fd);
}
+ close (fd);
+
return true;
}
/* We need to check signature first */
snprintf (filebuf, sizeof (filebuf), "%s.sig", realbuf);
if (!ucl_fetch_file (filebuf, &sigbuf, &siglen, &parser->err, true)) {
+ if (buf) {
+ ucl_munmap (buf, buflen);
+ }
+
return false;
}
if (!ucl_sig_check (buf, buflen, sigbuf, siglen, parser)) {
if (sigbuf) {
ucl_munmap (sigbuf, siglen);
}
+ if (buf) {
+ ucl_munmap (buf, buflen);
+ }
+
return false;
}
+
if (sigbuf) {
ucl_munmap (sigbuf, siglen);
}
ucl_munmap (buf, buflen);
}
+ ucl_object_unref (new_obj);
+
return false;
}
nest_obj->prev = nest_obj;