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


Ignore:
Timestamp:
2013-04-20T09:38:59Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7262f89
Parents:
9d8bd3ac
Message:

Pointer decoding.

File:
1 edited

Legend:

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

    r9d8bd3ac rf1dcf6d  
    4747#define NAME  "dnsres"
    4848
     49static uint16_t dns_uint16_t_decode(uint8_t *, size_t);
     50
    4951#include <stdio.h>
    5052static int dns_name_encode(char *name, uint8_t *buf, size_t buf_size,
     
    117119        size_t lsize;
    118120        size_t i;
     121        size_t ptr;
     122        size_t eptr;
    119123
    120124        if (boff > size)
     
    129133                }
    130134
    131 
    132135                lsize = *bp;
    133136                ++bp;
     
    137140                        break;
    138141
    139                 if (bp != buf + 1)
     142                if (bp != buf + boff + 1)
    140143                        printf(".");
    141144
    142145                if ((lsize & 0xc0) == 0xc0) {
     146                        printf("Pointer\n");
    143147                        /* Pointer */
    144                         printf("compression not supported!\n");
    145                         return EINVAL;
     148                        if (bsize < 1) {
     149                                printf("Pointer- bsize < 1\n");
     150                                return EINVAL;
     151                        }
     152
     153                        ptr = dns_uint16_t_decode(bp - 1, bsize) & 0x3fff;
     154                        if (ptr >= (size_t)(bp - buf)) {
     155                                printf("Pointer- forward ref %u, pos=%u\n",
     156                                    ptr, bp - buf);
     157                                /* Forward reference */
     158                                return EINVAL;
     159                        }
     160
     161                        /*
     162                         * Make sure we will not decode any byte twice.
     163                         * XXX Is assumption correct?
     164                         */
     165                        eptr = buf - bp;
     166
     167                        printf("ptr=%u, eptr=%u\n", ptr, eptr);
     168                        bp = buf + ptr;
     169                        bsize = eptr - ptr;
     170                        continue;
    146171                }
    147172
Note: See TracChangeset for help on using the changeset viewer.