From f8000b355e32d3012007da5ce8fd13f351c7de88 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 19 May 2017 08:54:37 +0000 Subject: [PATCH] - str2wire fp2rr returns line string for $directives. git-svn-id: file:///svn/unbound/trunk@4176 be551aaa-1e26-0410-a405-d3ace91eadb9 --- sldns/str2wire.c | 10 ++++++++++ sldns/str2wire.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/sldns/str2wire.c b/sldns/str2wire.c index 9dbfdf71f..b4f84faf9 100644 --- a/sldns/str2wire.c +++ b/sldns/str2wire.c @@ -869,6 +869,8 @@ int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, /* we can have the situation, where we've read ok, but still got * no bytes to play with, in this case size is 0 */ if(size == 0) { + if(*len > 0) + rr[0] = 0; *len = 0; *dname_len = 0; return LDNS_WIREPARSE_ERR_OK; @@ -876,6 +878,7 @@ int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, if(strncmp(line, "$ORIGIN", 7) == 0 && isspace((unsigned char)line[7])) { int s; + strlcpy((char*)rr, line, *len); *len = 0; *dname_len = 0; if(!parse_state) return LDNS_WIREPARSE_ERR_OK; @@ -886,12 +889,19 @@ int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, return s; } else if(strncmp(line, "$TTL", 4) == 0 && isspace((unsigned char)line[4])) { const char* end = NULL; + strlcpy((char*)rr, line, *len); *len = 0; *dname_len = 0; if(!parse_state) return LDNS_WIREPARSE_ERR_OK; parse_state->default_ttl = sldns_str2period( sldns_strip_ws(line+5), &end); } else if (strncmp(line, "$INCLUDE", 8) == 0) { + strlcpy((char*)rr, line, *len); + *len = 0; + *dname_len = 0; + return LDNS_WIREPARSE_ERR_INCLUDE; + } else if (strncmp(line, "$", 1) == 0) { + strlcpy((char*)rr, line, *len); *len = 0; *dname_len = 0; return LDNS_WIREPARSE_ERR_INCLUDE; diff --git a/sldns/str2wire.h b/sldns/str2wire.h index 9b2b35b37..a0d6f55b0 100644 --- a/sldns/str2wire.h +++ b/sldns/str2wire.h @@ -237,6 +237,8 @@ struct sldns_file_parse_state { * @param rr: this is malloced by the user and the result is stored here, * if an RR is read. If no RR is read this is signalled with the * return len set to 0 (for ORIGIN, TTL directives). + * The read line is available in the rr_buf (zero terminated), for + * $DIRECTIVE style elements. * @param len: on input, the length of the rr buffer. on output the rr len. * Buffer size of 64k should be enough. * @param dname_len: returns the length of the dname initial part of the rr. -- 2.47.3