@@ -54,7 +54,7 @@ static frg::string<MemoryAllocator> read_dns_name(char *buf, char *&it) {
5454 char code = *it++;
5555 if ((code & 0xC0 ) == 0xC0 ) {
5656 // pointer
57- uint8_t offset = ((code & 0x3F ) << 8 ) | *it++;
57+ uint16_t offset = (static_cast < uint8_t > (code & 0x3F ) << 8 ) | static_cast < uint8_t >( *it++) ;
5858 auto offset_it = buf + offset;
5959 return res + read_dns_name (buf, offset_it);
6060 } else if (!(code & 0xC0 )) {
@@ -146,7 +146,7 @@ int lookup_name_dns(struct lookup_result &buf, const char *name,
146146 return -EAI_SYSTEM ;
147147 }
148148
149- char response[256 ];
149+ char response[512 ];
150150 int num_ans = 0 ;
151151 int fds_ready;
152152 struct timespec start_time;
@@ -159,7 +159,7 @@ int lookup_name_dns(struct lookup_result &buf, const char *name,
159159 mlibc::panicLogger () << " mlibc: sys_clock_get() failed with error code: " << e << frg::endlog;
160160
161161 while ((fds_ready = poll (&pollfd, 1 , get_poll_timeout (&start_time))) > 0 ) {
162- ssize_t rlen = recvfrom (fd, response, 256 , 0 , nullptr , nullptr );
162+ ssize_t rlen = recvfrom (fd, response, sizeof (response) , 0 , nullptr , nullptr );
163163 if (rlen < 0 ) {
164164 mlibc::infoLogger () << " lookup_name_dns(): recvfrom() failed" << frg::endlog;
165165 return -EAI_SYSTEM ;
@@ -186,16 +186,18 @@ int lookup_name_dns(struct lookup_result &buf, const char *name,
186186 struct dns_addr_buf buffer;
187187 auto dns_name = read_dns_name (response, it);
188188
189- uint16_t rr_type = (it[0 ] << 8 ) | it[1 ];
190- uint16_t rr_class = (it[2 ] << 8 ) | it[3 ];
191- uint16_t rr_length = (it[8 ] << 8 ) | it[9 ];
189+ uint16_t rr_type = (static_cast < uint8_t >( it[0 ]) << 8 ) | static_cast < uint8_t >( it[1 ]) ;
190+ uint16_t rr_class = (static_cast < uint8_t >( it[2 ]) << 8 ) | static_cast < uint8_t >( it[3 ]) ;
191+ uint16_t rr_length = (static_cast < uint8_t >( it[8 ]) << 8 ) | static_cast < uint8_t >( it[9 ]) ;
192192 it += 10 ;
193193 (void )rr_class;
194194
195195 switch (rr_type) {
196196 case RECORD_A :
197- if (family != AF_UNSPEC && family != AF_INET )
197+ if (family != AF_UNSPEC && family != AF_INET ) {
198+ it += rr_length;
198199 continue ;
200+ }
199201
200202 memcpy (buffer.addr , it, rr_length);
201203 it += rr_length;
@@ -204,8 +206,10 @@ int lookup_name_dns(struct lookup_result &buf, const char *name,
204206 buf.buf .push (std::move (buffer));
205207 break ;
206208 case RECORD_AAAA :
207- if (family != AF_UNSPEC && family != AF_INET6 )
209+ if (family != AF_UNSPEC && family != AF_INET6 ) {
210+ it += rr_length;
208211 continue ;
212+ }
209213
210214 memcpy (buffer.addr , it, rr_length);
211215 it += rr_length;
@@ -220,6 +224,7 @@ int lookup_name_dns(struct lookup_result &buf, const char *name,
220224 default :
221225 mlibc::infoLogger () << " lookup_name_dns: unknown rr type "
222226 << rr_type << frg::endlog;
227+ it += rr_length;
223228 break ;
224229 }
225230 }
@@ -355,12 +360,11 @@ int lookup_addr_dns(frg::span<char> name, frg::array<uint8_t, 16> &addr, int fam
355360 struct dns_addr_buf buffer;
356361 auto dns_name = read_dns_name (response, it);
357362
358- uint16_t rr_type = (it[0 ] << 8 ) | it[1 ];
359- uint16_t rr_class = (it[2 ] << 8 ) | it[3 ];
360- uint16_t rr_length = (it[8 ] << 8 ) | it[9 ];
363+ uint16_t rr_type = (static_cast < uint8_t >( it[0 ]) << 8 ) | static_cast < uint8_t >( it[1 ]) ;
364+ uint16_t rr_class = (static_cast < uint8_t >( it[2 ]) << 8 ) | static_cast < uint8_t >( it[3 ]) ;
365+ uint16_t rr_length = (static_cast < uint8_t >( it[8 ]) << 8 ) | static_cast < uint8_t >( it[9 ]) ;
361366 it += 10 ;
362367 (void )rr_class;
363- (void )rr_length;
364368
365369 (void )dns_name;
366370
@@ -376,6 +380,7 @@ int lookup_addr_dns(frg::span<char> name, frg::array<uint8_t, 16> &addr, int fam
376380 default :
377381 mlibc::infoLogger () << " lookup_addr_dns: unknown rr type "
378382 << rr_type << frg::endlog;
383+ it += rr_length;
379384 break ;
380385 }
381386 num_ans += ntohs (response_header->no_ans );
0 commit comments