Changeset 9d8bd3ac in mainline for uspace/srv/net/dnsres/dns_msg.c


Ignore:
Timestamp:
2013-04-20T09:15:42Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1dcf6d
Parents:
0041cd6d
Message:

Need entire message buffer in order to support pointers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsres/dns_msg.c

    r0041cd6d r9d8bd3ac  
    110110}
    111111
    112 static int dns_name_decode(uint8_t *buf, size_t size, char **rname,
    113     size_t *act_size)
     112static int dns_name_decode(uint8_t *buf, size_t size, size_t boff, char **rname,
     113    size_t *eoff)
    114114{
    115115        uint8_t *bp;
     
    118118        size_t i;
    119119
    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);
    122125
    123126        while (true) {
     
    156159        printf("\n");
    157160
    158         *act_size = bp - buf;
     161        *eoff = bp - buf;
    159162        return EOK;
    160163}
     
    218221}
    219222
    220 static int dns_question_decode(uint8_t *buf, size_t buf_size,
    221     dns_question_t **rquestion, size_t *act_size)
     223static int dns_question_decode(uint8_t *buf, size_t buf_size, size_t boff,
     224    dns_question_t **rquestion, size_t *eoff)
    222225{
    223226        dns_question_t *question;
    224         size_t name_size;
     227        size_t name_eoff;
    225228        int rc;
    226229
     
    230233
    231234        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);
    233236        if (rc != EOK) {
    234237                printf("error decoding name..\n");
     
    238241
    239242        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);
    243246                free(question);
    244247                return EINVAL;
    245248        }
    246249
    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);
    251254
    252255        *rquestion = question;
     
    254257}
    255258
    256 static int dns_rr_decode(uint8_t *buf, size_t buf_size,
    257     dns_rr_t **retrr, size_t *act_size)
     259static int dns_rr_decode(uint8_t *buf, size_t buf_size, size_t boff,
     260    dns_rr_t **retrr, size_t *eoff)
    258261{
    259262        dns_rr_t *rr;
    260         size_t name_size;
     263        size_t name_eoff;
    261264        uint8_t *bp;
    262265        size_t bsz;
     
    269272
    270273        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);
    272275        if (rc != EOK) {
    273276                printf("error decoding name..\n");
     
    277280
    278281        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);
    282285                free(rr->name);
    283286                free(rr);
     
    285288        }
    286289
    287         bp = buf + name_size;
    288         bsz = buf_size - name_size;
     290        bp = buf + name_eoff;
     291        bsz = buf_size - name_eoff;
    289292
    290293        if (bsz < 3 * sizeof(uint16_t) + sizeof(uint32_t)) {
     
    324327        bsz -= rdlength;
    325328
    326         *act_size = bp - buf;
     329        *eoff = bp - buf;
    327330        *retrr = rr;
    328331        return EOK;
     
    393396        dns_message_t *msg;
    394397        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;
    398400        dns_question_t *question;
    399401        dns_rr_t *rr;
     
    428430        list_initialize(&msg->additional);
    429431
    430         dp = (uint8_t *)data + sizeof(dns_header_t);
    431         dsize = size - sizeof(dns_header_t);
     432        doff = sizeof(dns_header_t);
    432433
    433434        qd_count = uint16_t_be2host(hdr->qd_count);
     
    436437        for (i = 0; i < qd_count; i++) {
    437438                printf("decode question..\n");
    438                 rc = dns_question_decode(dp, dsize, &question, &field_size);
     439                rc = dns_question_decode(data, size, doff, &question, &field_eoff);
    439440                if (rc != EOK) {
    440441                        printf("error decoding question\n");
     
    443444                printf("ok decoding question\n");
    444445
    445                 dp += field_size;
    446                 dsize -= field_size;
     446                doff = field_eoff;
    447447        }
    448448
     
    452452        for (i = 0; i < an_count; i++) {
    453453                printf("decode answer..\n");
    454                 rc = dns_rr_decode(dp, dsize, &rr, &field_size);
     454                rc = dns_rr_decode(data, size, doff, &rr, &field_eoff);
    455455                if (rc != EOK) {
    456456                        printf("error decoding answer\n");
     
    459459                printf("ok decoding answer\n");
    460460
    461                 dp += field_size;
    462                 dsize -= field_size;
     461                doff = field_eoff;
    463462        }
    464463
Note: See TracChangeset for help on using the changeset viewer.