Skip to content

Commit

Permalink
Bug fix---remove VLAs from codebase.
Browse files Browse the repository at this point in the history
The Windows C compiler doesn't support variable length arrays.  It's now
considered optional in C11, so might as well avoid them.
  • Loading branch information
spc476 committed Jun 16, 2022
1 parent 1b9648a commit 05aead5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ UNAME := $(shell uname)
VERSION := $(shell git describe --tag)

ifeq ($(VERSION),)
VERSION=v2.0.5
VERSION=v2.0.6
endif

# ===================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package = "org.conman.dns"
version = "2.0.5-1"
version = "2.0.6-1"

source =
{
url = "git+https://github.com/spc476/SPCDNS.git",
tag = "v2.0.5"
tag = "v2.0.6"
}

description =
Expand Down
30 changes: 19 additions & 11 deletions src/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ static inline dns_rcode_t encode_edns0rr_nsid(
)
{
size_t newlen;
size_t nidx;
size_t i;

assert(econtext_okay(data));
assert(opt != NULL);
Expand All @@ -635,18 +637,12 @@ static inline dns_rcode_t encode_edns0rr_nsid(
if (data->packet.size < newlen + sizeof(uint16_t) + sizeof(uint16_t))
return RCODE_NO_MEMORY;

char buffer[newlen + 1];
size_t nidx;
size_t i;

for (i = nidx = 0 ; i < opt->len ; i++ , nidx += 2)
sprintf(&buffer[nidx],"%02X",opt->data[i]);

assert(newlen == strlen(buffer));

write_uint16(&data->packet,opt->code);
write_uint16(&data->packet,newlen);
memcpy(data->packet.ptr,buffer,newlen);

for (i = nidx = 0 ; i < opt->len ; i++ , nidx += 2)
sprintf((char *)&data->packet.ptr[nidx],"%02X",opt->data[i]);

data->packet.ptr += newlen;
data->packet.size -= newlen;
return RCODE_OKAY;
Expand Down Expand Up @@ -1676,7 +1672,19 @@ static dns_rcode_t dloc_double(
if (len > data->parse.size - 1)
return RCODE_FORMAT_ERROR;

char buffer[len + 1];
/*-----------------------------------------------------------------------
; Microsoft C compilers don't support VLAs. So I'm picking an arbitrary
; limit that hopefully won't break things. I'm not sure what the actual
; length limit is for a double value (as a string to be parsed), so I
; checked some C code, found a 36 digit double number, then doubled that.
; Hopefully this is good enough.
;------------------------------------------------------------------------*/

char buffer[72];

if (len >= sizeof(buffer))
return RCODE_FORMAT_ERROR;

memcpy(buffer,&data->parse.ptr[1],len);
buffer[len++] = '\0';

Expand Down

0 comments on commit 05aead5

Please sign in to comment.