Skip to content

Commit

Permalink
lstab: Don't free lstab on update.
Browse files Browse the repository at this point in the history
The modification timestamp of the leapfile is checked with every
call of lstab_utc2tai(). If the file is modified, the provided lstab
structure is freed and a new one is allocated from the updated leapfile.
But the new lstab is not returned to the caller as the function doesn't
accept a pointer to the pointer to lstab. This causes reading from the
freed memory and leak of the newly allocated memory.

Modify update_leapsecond_table() to read the updated leapfile into the
existing lstab structure instead of the reallocation.

Signed-off-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Feb 28, 2024
1 parent 77c054c commit 737ff39
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lstab.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ struct lstab *lstab_create(const char *filename)

int update_leapsecond_table(struct lstab *lstab)
{
const char* leapfile;
struct stat statbuf;
int err;

Expand All @@ -212,14 +211,14 @@ int update_leapsecond_table(struct lstab *lstab)
return 0;
}
printf("updating leap seconds file\n");
leapfile = lstab->leapfile;
lstab_destroy(lstab);

lstab = lstab_create(leapfile);
if (!lstab) {
if (lstab_read(lstab, lstab->leapfile)) {
lstab->length = 0;
return -1;
}

lstab->lsfile_mtime = statbuf.st_mtim.tv_sec;

return 0;
}

Expand Down

0 comments on commit 737ff39

Please sign in to comment.