Page MenuHomeFreeBSD

D57905.id180816.diff
No OneTemporary

D57905.id180816.diff

diff --git a/contrib/unbound/util/configlexer.lex b/contrib/unbound/util/configlexer.lex
--- a/contrib/unbound/util/configlexer.lex
+++ b/contrib/unbound/util/configlexer.lex
@@ -626,10 +626,13 @@
LEXOUT(("QE "));
if(--num_args == 0) { BEGIN(INITIAL); }
else { BEGIN(val); }
- ub_c_text[ub_c_leng - 1] = '\0';
- ub_c_lval.str = strdup(ub_c_text);
+ /* deliberately allocate one extra byte so there is room to add a
+ * trailing dot if necessary */
+ ub_c_lval.str = malloc(ub_c_leng + 1);
if(!ub_c_lval.str)
ub_c_error("out of memory");
+ memcpy(ub_c_lval.str, ub_c_text, ub_c_leng - 1);
+ ub_c_lval.str[ub_c_leng - 1] = ub_c_lval.str[ub_c_leng] = '\0';
return STRING_ARG;
}
@@ -647,10 +650,13 @@
LEXOUT(("SQE "));
if(--num_args == 0) { BEGIN(INITIAL); }
else { BEGIN(val); }
- ub_c_text[ub_c_leng - 1] = '\0';
- ub_c_lval.str = strdup(ub_c_text);
+ /* deliberately allocate one extra byte so there is room to add a
+ * trailing dot if necessary */
+ ub_c_lval.str = malloc(ub_c_leng + 1);
if(!ub_c_lval.str)
ub_c_error("out of memory");
+ memcpy(ub_c_lval.str, ub_c_text, ub_c_leng - 1);
+ ub_c_lval.str[ub_c_leng - 1] = ub_c_lval.str[ub_c_leng] = '\0';
return STRING_ARG;
}
@@ -730,9 +736,18 @@
return (VAR_FORCE_TOPLEVEL);
}
-<val>{UNQUOTEDLETTER}* { LEXOUT(("unquotedstr(%s) ", ub_c_text));
- if(--num_args == 0) { BEGIN(INITIAL); }
- ub_c_lval.str = strdup(ub_c_text); return STRING_ARG; }
+<val>{UNQUOTEDLETTER}* {
+ LEXOUT(("unquotedstr(%s) ", ub_c_text));
+ if(--num_args == 0) { BEGIN(INITIAL); }
+ /* deliberately allocate one extra byte so there is room to add a
+ * trailing dot if necessary */
+ ub_c_lval.str = malloc(ub_c_leng + 2);
+ if(!ub_c_lval.str)
+ ub_c_error("out of memory");
+ memcpy(ub_c_lval.str, ub_c_text, ub_c_leng);
+ ub_c_lval.str[ub_c_leng] = ub_c_lval.str[ub_c_leng + 1] = '\0';
+ return STRING_ARG;
+}
{UNQUOTEDLETTER_NOCOLON}* {
ub_c_error_msg("unknown keyword '%s'", ub_c_text);
diff --git a/contrib/unbound/util/configparser.y b/contrib/unbound/util/configparser.y
--- a/contrib/unbound/util/configparser.y
+++ b/contrib/unbound/util/configparser.y
@@ -39,6 +39,7 @@
#include "config.h"
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -54,6 +55,7 @@
static void validate_respip_action(const char* action);
static void validate_acl_action(const char* action);
+static void normalize_domain_name(char *name, bool abs);
/* these need to be global, otherwise they cannot be used inside yacc */
extern struct config_parser_state* cfg_parser;
@@ -1500,6 +1502,7 @@
;
server_domain_insecure: VAR_DOMAIN_INSECURE STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(server_domain_insecure:%s)\n", $2));
if(!cfg_strlist_insert(&cfg_parser->cfg->domain_insecure, $2))
yyerror("out of memory");
@@ -1966,6 +1969,7 @@
;
server_private_domain: VAR_PRIVATE_DOMAIN STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(server_private_domain:%s)\n", $2));
if(!cfg_strlist_insert(&cfg_parser->cfg->private_domain, $2))
yyerror("out of memory");
@@ -2413,16 +2417,6 @@
free($3);
#ifdef USE_IPSET
} else if(strcmp($3, "ipset")==0) {
- size_t len = strlen($2);
- /* Make sure to add the trailing dot.
- * These are str compared to domain names. */
- if($2[len-1] != '.') {
- if(!($2 = realloc($2, len+2))) {
- fatal_exit("out of memory adding local-zone");
- }
- $2[len] = '.';
- $2[len+1] = 0;
- }
if(!cfg_strlist_insert(&cfg_parser->cfg->
local_zones_ipset, $2))
fatal_exit("out of memory adding local-zone");
@@ -3120,6 +3114,7 @@
;
stub_name: VAR_NAME STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(name:%s)\n", $2));
if(cfg_parser->cfg->stubs->name)
yyerror("stub name override, there must be one name "
@@ -3192,6 +3187,7 @@
;
forward_name: VAR_NAME STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(name:%s)\n", $2));
if(cfg_parser->cfg->forwards->name)
yyerror("forward name override, there must be one "
@@ -3254,6 +3250,7 @@
;
auth_name: VAR_NAME STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(name:%s)\n", $2));
if(cfg_parser->cfg->auths->name)
yyerror("auth name override, there must be one name "
@@ -3353,6 +3350,7 @@
;
view_local_zone: VAR_LOCAL_ZONE STRING_ARG STRING_ARG
{
+ normalize_domain_name($2, true);
OUTYY(("P(view_local_zone:%s %s)\n", $2, $3));
if(strcmp($3, "static")!=0 && strcmp($3, "deny")!=0 &&
strcmp($3, "refuse")!=0 && strcmp($3, "redirect")!=0 &&
@@ -3384,16 +3382,6 @@
free($3);
#ifdef USE_IPSET
} else if(strcmp($3, "ipset")==0) {
- size_t len = strlen($2);
- /* Make sure to add the trailing dot.
- * These are str compared to domain names. */
- if($2[len-1] != '.') {
- if(!($2 = realloc($2, len+2))) {
- fatal_exit("out of memory adding local-zone");
- }
- $2[len] = '.';
- $2[len+1] = 0;
- }
if(!cfg_strlist_insert(&cfg_parser->cfg->views->
local_zones_ipset, $2))
fatal_exit("out of memory adding local-zone");
@@ -4361,3 +4349,33 @@
"allow_snoop or allow_cookie as access control action");
}
}
+
+static void
+normalize_domain_name(char *name, bool abs)
+{
+ char *src, *dst;
+
+ /* skip leading dot(s) */
+ for (src = dst = name; *src == '.'; src++)
+ /* nothing */;
+ /* copy to the end */
+ while (*src != '\0') {
+ if ((*dst++ = *src++) == '.') {
+ /* deduplicate dots */
+ while (*src == '.')
+ src++;
+ }
+ }
+ /* If the caller did not ask for an absolute name, strip any
+ * trailing dot(s). */
+ while (!abs && dst > name && dst[-1] == '.')
+ dst--;
+ /* If the result is empty, or the caller asked for an absolute
+ * name and there is no trailing dot, add a dot. The lexer always
+ * allocates one extra byte, so there is room to add a dot even if
+ * we didn't skip anything while copying. */
+ if (dst == name || (abs && dst[-1] != '.'))
+ *dst++ = '.';
+ /* terminate the result */
+ *dst = '\0';
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Jul 6, 6:08 AM (16 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34739175
Default Alt Text
D57905.id180816.diff (5 KB)

Event Timeline