NLnetLabs / ldns

LDNS is a DNS library that facilitates DNS tool programming
https://nlnetlabs.nl/ldns
BSD 3-Clause "New" or "Revised" License
295 stars 99 forks source link

LOC parser mishandles centimetres #121

Closed FGasper closed 3 years ago

FGasper commented 3 years ago
#include <stdio.h>

#include <ldns/ldns.h>
#include <ldns/host2str.h>

int main() {
    const char* rrtxt = "foo 12345 IN LOC 12 45 52.333 N 105 40 33.452 W -24m 0.1m 0.1m 0.1m";

    ldns_rr* myrr = NULL;

    ldns_rr_new_frm_str(&myrr, rrtxt, 999, NULL, NULL);

    printf("%s", ldns_rr2str(myrr));

    ldns_rr_free(myrr);

    return 0;
}

^^ This outputs:

foo.    12345   IN  LOC 12 45 52.333 N 105 40 33.452 W -24m 0.01m 0.01m 0.01m

Note that the last few values are 0.01m, not 0.1m.

The reason is that loc_parse_cm does this:

    if (*my_str == '.') {
        my_str++;
        cm = (uint32_t)strtol(my_str, &my_str, 10);
    }

It needs to multiply cm by 10 if only 1 digit is given.

wtoorop commented 3 years ago

Fix is merged