From bd8dd94f2775b0ddeeca37fb65d8b45abb003079 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Tue, 14 Feb 2017 11:18:02 +0100 Subject: [PATCH] bufdix #617: WKS service and protocol names lcase Thanks Xiali Yan --- Changelog | 2 ++ str2host.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index bb4aaca4..b59d2c5f 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,8 @@ Thanks Oleksandr Natalenko * bugfix #1218: Only chase DS if signer is parent of owner. Thanks Emil Natan + * bugfix #617: Retry WKS service and protocol names lower case. + Thanks Siali Yan 1.7.0 2016-12-20 * Fix lookup of relative names in ldns_resolver_search. diff --git a/str2host.c b/str2host.c index c396f547..b274b17a 100644 --- a/str2host.c +++ b/str2host.c @@ -1088,7 +1088,10 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) ldns_buffer *str_buf; char *proto_str = NULL; + char *lc_proto_str = NULL; char *token; + char *lc_token; + char *c; if(strlen(str) == 0) token = LDNS_XMALLOC(char, 50); else token = LDNS_XMALLOC(char, strlen(str)+2); @@ -1106,7 +1109,13 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) while(ldns_bget_token(str_buf, token, "\t\n ", strlen(str)) > 0) { if (!proto_str) { proto_str = strdup(token); - if (!proto_str) { + lc_proto_str = strdup(token); + for (c = lc_proto_str; *c; c++) { + *c = tolower(*c); + } + if (!proto_str || !lc_proto_str) { + free(proto_str); + free(lc_proto_str); LDNS_FREE(bitmap); LDNS_FREE(token); ldns_buffer_free(str_buf); @@ -1114,6 +1123,19 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) } } else { serv = getservbyname(token, proto_str); + if (!serv) { + serv = getservbyname(token, lc_proto_str); + } + if (!serv && (lc_token = strdup(token))) { + for (c = lc_token; *c; c++) { + *c = tolower(*c); + } + serv = getservbyname(lc_token, proto_str); + if (!serv) { + serv = getservbyname(lc_token, lc_proto_str); + } + free(lc_token); + } if (serv) { serv_port = (int) ntohs((uint16_t) serv->s_port); } else { @@ -1126,6 +1148,7 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) LDNS_FREE(token); ldns_buffer_free(str_buf); free(proto_str); + free(lc_proto_str); return LDNS_STATUS_INVALID_STR; } bitmap = b2; @@ -1143,6 +1166,7 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) LDNS_FREE(token); ldns_buffer_free(str_buf); free(proto_str); + free(lc_proto_str); return LDNS_STATUS_INVALID_STR; } @@ -1152,10 +1176,14 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) ldns_buffer_free(str_buf); LDNS_FREE(bitmap); free(proto_str); + free(lc_proto_str); return LDNS_STATUS_INVALID_STR; } if (proto_str) proto = getprotobyname(proto_str); + if (!proto) { + proto = getprotobyname(lc_proto_str); + } if (proto) { data[0] = (uint8_t) proto->p_proto; } else if (proto_str) { @@ -1170,6 +1198,7 @@ ldns_str2rdf_wks(ldns_rdf **rd, const char *str) ldns_buffer_free(str_buf); LDNS_FREE(bitmap); free(proto_str); + free(lc_proto_str); #ifdef HAVE_ENDSERVENT endservent(); #endif -- 2.47.3