5 #define FATAL "tinydns-data: fatal: "
7 +void die_semantic2(const char * s1, const char * s2)
9 + strerr_die3x(111,FATAL,s1,s2) ;
11 +void die_semantic4(const char * s1, const char * s2,const char * s3, const char * s4)
13 + strerr_die5x(111,FATAL,s1,s2,s3,s4) ;
15 void die_datatmp(void)
17 strerr_die2sys(111,FATAL,"unable to create data.cdb.tmp: ");
18 @@ -34,20 +42,39 @@ void nomem(void)
19 strerr_die1sys(111,FATAL);
22 +void ttlparse(stralloc *sa,unsigned long * ttl, unsigned long defttl, const char * ltype)
27 + if (!stralloc_0(sa)) nomem();
28 + ttllen = scan_ulong(sa->s,ttl) ;
29 + if (ttllen + 1 != sa->len)
30 + die_semantic4("unparseable TTL in ",ltype," line: ", sa->s) ;
35 void ttdparse(stralloc *sa,char ttd[8])
41 - for (i = 0;(i < 16) && (i < sa->len);++i) {
42 + for (i = 0;i < sa->len;++i) {
44 + if (!stralloc_0(sa)) nomem() ;
45 + die_semantic2("timestamp is too long: ", sa->s) ;
48 if ((ch >= '0') && (ch <= '9'))
50 else if ((ch >= 'a') && (ch <= 'f'))
55 + if (!stralloc_0(sa)) nomem() ;
56 + die_semantic2("timestamp contains an invalid character: ", sa->s) ;
58 if (!(i & 1)) ch <<= 4;
61 @@ -55,6 +82,10 @@ void ttdparse(stralloc *sa,char ttd[8])
63 void locparse(stralloc *sa,char loc[2])
66 + if (!stralloc_0(sa)) nomem() ;
67 + die_semantic2("location code longer than two characters: ", sa->s) ;
69 loc[0] = (sa->len > 0) ? sa->s[0] : 0;
70 loc[1] = (sa->len > 1) ? sa->s[1] : 0;
72 @@ -187,6 +218,7 @@ int main()
80 @@ -267,8 +299,7 @@ int main()
81 if (!scan_ulong(f[7].s,&u)) uint32_unpack_big(defaultsoa + 16,&u);
82 uint32_pack_big(soa + 16,u);
84 - if (!stralloc_0(&f[8])) nomem();
85 - if (!scan_ulong(f[8].s,&ttl)) ttl = TTL_NEGATIVE;
86 + ttlparse(&f[8],&ttl,TTL_NEGATIVE,"Z");
90 @@ -283,8 +314,7 @@ int main()
93 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
94 - if (!stralloc_0(&f[3])) nomem();
95 - if (!scan_ulong(f[3].s,&ttl)) ttl = TTL_NS;
96 + ttlparse(&f[3],&ttl,TTL_NS,". or &");
100 @@ -309,24 +339,26 @@ int main()
104 - if (ip4_scan(f[1].s,ip)) {
105 + iplen = ip4_scan(f[1].s,ip) ;
106 + if (iplen != 0 && iplen + 1 == f[1].len) {
107 rr_start(DNS_T_A,ttl,ttd,loc);
111 + } else if (f[1].len > 1)
112 + die_semantic4("unparseable IP address in ","& or ."," line: ", f[1].s) ;
117 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
118 - if (!stralloc_0(&f[2])) nomem();
119 - if (!scan_ulong(f[2].s,&ttl)) ttl = TTL_POSITIVE;
120 + ttlparse(&f[2],&ttl,TTL_POSITIVE,"+ or =");
124 if (!stralloc_0(&f[1])) nomem();
126 - if (ip4_scan(f[1].s,ip)) {
127 + iplen = ip4_scan(f[1].s,ip) ;
128 + if (iplen != 0 && iplen + 1 == f[1].len) {
129 rr_start(DNS_T_A,ttl,ttd,loc);
132 @@ -337,13 +369,15 @@ int main()
137 + } else if (f[1].len > 1)
138 + die_semantic4("unparseable IP address in ","+ or ="," line: ", f[1].s) ;
140 + die_semantic4("missing IP address in ","+ or ="," line: ", f[1].s) ;
144 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
145 - if (!stralloc_0(&f[4])) nomem();
146 - if (!scan_ulong(f[4].s,&ttl)) ttl = TTL_POSITIVE;
147 + ttlparse(&f[4],&ttl,TTL_POSITIVE,"@");
151 @@ -401,18 +435,19 @@ int main()
155 - if (ip4_scan(f[1].s,ip)) {
156 + iplen = ip4_scan(f[1].s,ip) ;
157 + if (iplen != 0 && iplen + 1 == f[1].len) {
158 rr_start(DNS_T_A,ttl,ttd,loc);
162 + } else if (f[1].len > 1)
163 + die_semantic4("unparseable IP address in ","@"," line: ", f[1].s) ;
167 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
168 if (!dns_domain_fromdot(&d2,f[1].s,f[1].len)) nomem();
169 - if (!stralloc_0(&f[2])) nomem();
170 - if (!scan_ulong(f[2].s,&ttl)) ttl = TTL_POSITIVE;
171 + ttlparse(&f[2],&ttl,TTL_POSITIVE,"^ or C");
175 @@ -426,8 +461,7 @@ int main()
178 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
179 - if (!stralloc_0(&f[2])) nomem();
180 - if (!scan_ulong(f[2].s,&ttl)) ttl = TTL_POSITIVE;
181 + ttlparse(&f[2],&ttl,TTL_POSITIVE,"\'");
185 @@ -449,8 +483,7 @@ int main()
188 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
189 - if (!stralloc_0(&f[3])) nomem();
190 - if (!scan_ulong(f[3].s,&ttl)) ttl = TTL_POSITIVE;
191 + ttlparse(&f[3],&ttl,TTL_POSITIVE,":");