Skip to content

Commit

Permalink
vcard_test.c: NUL-terminate the read data
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Apr 26, 2024
1 parent 9533749 commit b767651
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/test/libicalvcard/vcard_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void test_parse_file(const char *fname)
int fd, r;
struct stat sbuf;
size_t filesize;
void *data = NULL;
char *data = NULL;
vcardcomponent *card;
const char *want =
"BEGIN:VCARD\r\n"
Expand Down Expand Up @@ -96,9 +96,9 @@ static void test_parse_file(const char *fname)
fstat(fd, &sbuf);
filesize = sbuf.st_size; //to make fortify compile happy
data = malloc(filesize+1);
memset(data, 0, filesize+1);
memset((void *) data, 0, filesize+1);

r = read(fd, data, filesize);
r = read(fd, (void *) data, filesize);
fprintf(stderr, "read %d of %ld bytes\n'%s'\n", r, filesize, (char *) data);
close(fd);

Expand All @@ -108,6 +108,8 @@ fprintf(stderr, "read %d of %ld bytes\n'%s'\n", r, filesize, (char *) data);
assert(0);
}

data[r+1] = '\0';

card = vcardparser_parse_string(data);
free(data);

Expand Down

0 comments on commit b767651

Please sign in to comment.