Changeset 9d8bd3ac in mainline for uspace/srv/net/dnsres/dns_msg.c
- Timestamp:
- 2013-04-20T09:15:42Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1dcf6d
- Parents:
- 0041cd6d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dnsres/dns_msg.c
r0041cd6d r9d8bd3ac 110 110 } 111 111 112 static int dns_name_decode(uint8_t *buf, size_t size, char **rname,113 size_t * act_size)112 static int dns_name_decode(uint8_t *buf, size_t size, size_t boff, char **rname, 113 size_t *eoff) 114 114 { 115 115 uint8_t *bp; … … 118 118 size_t i; 119 119 120 bp = buf; 121 bsize = min(size, DNS_NAME_MAX_SIZE); 120 if (boff > size) 121 return EINVAL; 122 123 bp = buf + boff; 124 bsize = min(size - boff, DNS_NAME_MAX_SIZE); 122 125 123 126 while (true) { … … 156 159 printf("\n"); 157 160 158 * act_size= bp - buf;161 *eoff = bp - buf; 159 162 return EOK; 160 163 } … … 218 221 } 219 222 220 static int dns_question_decode(uint8_t *buf, size_t buf_size, 221 dns_question_t **rquestion, size_t * act_size)223 static int dns_question_decode(uint8_t *buf, size_t buf_size, size_t boff, 224 dns_question_t **rquestion, size_t *eoff) 222 225 { 223 226 dns_question_t *question; 224 size_t name_ size;227 size_t name_eoff; 225 228 int rc; 226 229 … … 230 233 231 234 printf("decode name..\n"); 232 rc = dns_name_decode(buf, buf_size, &question->qname, &name_size);235 rc = dns_name_decode(buf, buf_size, boff, &question->qname, &name_eoff); 233 236 if (rc != EOK) { 234 237 printf("error decoding name..\n"); … … 238 241 239 242 printf("ok decoding name..\n"); 240 if (name_ size+ 2 * sizeof(uint16_t) > buf_size) {241 printf("name_ size+ 2 * 2 = %d > buf_size = %d\n",242 name_ size+ 2 * sizeof(uint16_t), buf_size);243 if (name_eoff + 2 * sizeof(uint16_t) > buf_size) { 244 printf("name_eoff + 2 * 2 = %d > buf_size = %d\n", 245 name_eoff + 2 * sizeof(uint16_t), buf_size); 243 246 free(question); 244 247 return EINVAL; 245 248 } 246 249 247 question->qtype = dns_uint16_t_decode(buf + name_ size, buf_size - name_size);248 question->qclass = dns_uint16_t_decode(buf + sizeof(uint16_t) + name_ size,249 buf_size - sizeof(uint16_t) - name_ size);250 * act_size = name_size+ 2 * sizeof(uint16_t);250 question->qtype = dns_uint16_t_decode(buf + name_eoff, buf_size - name_eoff); 251 question->qclass = dns_uint16_t_decode(buf + sizeof(uint16_t) + name_eoff, 252 buf_size - sizeof(uint16_t) - name_eoff); 253 *eoff = name_eoff + 2 * sizeof(uint16_t); 251 254 252 255 *rquestion = question; … … 254 257 } 255 258 256 static int dns_rr_decode(uint8_t *buf, size_t buf_size, 257 dns_rr_t **retrr, size_t * act_size)259 static int dns_rr_decode(uint8_t *buf, size_t buf_size, size_t boff, 260 dns_rr_t **retrr, size_t *eoff) 258 261 { 259 262 dns_rr_t *rr; 260 size_t name_ size;263 size_t name_eoff; 261 264 uint8_t *bp; 262 265 size_t bsz; … … 269 272 270 273 printf("decode name..\n"); 271 rc = dns_name_decode(buf, buf_size, &rr->name, &name_size);274 rc = dns_name_decode(buf, buf_size, boff, &rr->name, &name_eoff); 272 275 if (rc != EOK) { 273 276 printf("error decoding name..\n"); … … 277 280 278 281 printf("ok decoding name..\n"); 279 if (name_ size+ 2 * sizeof(uint16_t) > buf_size) {280 printf("name_ size+ 2 * 2 = %d > buf_size = %d\n",281 name_ size+ 2 * sizeof(uint16_t), buf_size);282 if (name_eoff + 2 * sizeof(uint16_t) > buf_size) { 283 printf("name_eoff + 2 * 2 = %d > buf_size = %d\n", 284 name_eoff + 2 * sizeof(uint16_t), buf_size); 282 285 free(rr->name); 283 286 free(rr); … … 285 288 } 286 289 287 bp = buf + name_ size;288 bsz = buf_size - name_ size;290 bp = buf + name_eoff; 291 bsz = buf_size - name_eoff; 289 292 290 293 if (bsz < 3 * sizeof(uint16_t) + sizeof(uint32_t)) { … … 324 327 bsz -= rdlength; 325 328 326 * act_size= bp - buf;329 *eoff = bp - buf; 327 330 *retrr = rr; 328 331 return EOK; … … 393 396 dns_message_t *msg; 394 397 dns_header_t *hdr; 395 uint8_t *dp; 396 size_t dsize; 397 size_t field_size; 398 size_t doff; 399 size_t field_eoff; 398 400 dns_question_t *question; 399 401 dns_rr_t *rr; … … 428 430 list_initialize(&msg->additional); 429 431 430 dp = (uint8_t *)data + sizeof(dns_header_t); 431 dsize = size - sizeof(dns_header_t); 432 doff = sizeof(dns_header_t); 432 433 433 434 qd_count = uint16_t_be2host(hdr->qd_count); … … 436 437 for (i = 0; i < qd_count; i++) { 437 438 printf("decode question..\n"); 438 rc = dns_question_decode(d p, dsize, &question, &field_size);439 rc = dns_question_decode(data, size, doff, &question, &field_eoff); 439 440 if (rc != EOK) { 440 441 printf("error decoding question\n"); … … 443 444 printf("ok decoding question\n"); 444 445 445 dp += field_size; 446 dsize -= field_size; 446 doff = field_eoff; 447 447 } 448 448 … … 452 452 for (i = 0; i < an_count; i++) { 453 453 printf("decode answer..\n"); 454 rc = dns_rr_decode(d p, dsize, &rr, &field_size);454 rc = dns_rr_decode(data, size, doff, &rr, &field_eoff); 455 455 if (rc != EOK) { 456 456 printf("error decoding answer\n"); … … 459 459 printf("ok decoding answer\n"); 460 460 461 dp += field_size; 462 dsize -= field_size; 461 doff = field_eoff; 463 462 } 464 463
Note:
See TracChangeset
for help on using the changeset viewer.