Skip to content

Commit

Permalink
- Fix for WKS call to getservbyname that creates allocation on exit
Browse files Browse the repository at this point in the history
  in unit test by testing numbers first and testing from the services
  list later.
  • Loading branch information
wcawijngaards committed Aug 30, 2023
1 parent ba1183b commit d4c4537
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
30 August 2023: Wouter
- Fix for WKS call to getservbyname that creates allocation on exit
in unit test by testing numbers first and testing from the services
list later.

28 August 2023: Wouter
- Fix for version generation race condition that ignored changes.

Expand Down
21 changes: 11 additions & 10 deletions sldns/str2wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,12 +2459,13 @@ int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len)
(void)strlcpy(proto_str, token, sizeof(proto_str));
} else {
int serv_port;
struct servent *serv = getservbyname(token, proto_str);
if(serv) serv_port=(int)ntohs((uint16_t)serv->s_port);
if(atoi(token) != 0) serv_port=atoi(token);
else if(strcmp(token, "0") == 0) serv_port=0;
else if(strcasecmp(token, "domain")==0) serv_port=53;
else {
serv_port = atoi(token);
if(serv_port == 0 && strcmp(token, "0") != 0) {
struct servent *serv = getservbyname(token, proto_str);
if(serv) serv_port=(int)ntohs((uint16_t)serv->s_port);
else {
#ifdef HAVE_ENDSERVENT
endservent();
#endif
Expand All @@ -2474,16 +2475,16 @@ int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len)
return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
sldns_buffer_position(&strbuf));
}
if(serv_port < 0 || serv_port > 65535) {
}
if(serv_port < 0 || serv_port > 65535) {
#ifdef HAVE_ENDSERVENT
endservent();
endservent();
#endif
#ifdef HAVE_ENDPROTOENT
endprotoent();
endprotoent();
#endif
return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
sldns_buffer_position(&strbuf));
}
return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
sldns_buffer_position(&strbuf));
}
if(rd_len < 1+serv_port/8+1) {
/* bitmap is larger, init new bytes at 0 */
Expand Down

0 comments on commit d4c4537

Please sign in to comment.