Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions recording-daemon/metafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,14 @@ void metafile_change(char *name) {
g_string_append_len(s, buf, ret);
}

// save read position and close file
mf->pos = lseek(fd, 0, SEEK_CUR);
close(fd);

// process contents of metadata file
// XXX use "str" type?
char *head = s->str;
char *endp = s->str + s->len;
while (head < endp) {
char *section_start = head;
// section header
char *nl = memchr(head, '\n', endp - head);
if (!nl || nl == head) {
Expand All @@ -412,6 +411,8 @@ void metafile_change(char *name) {
}
if (memchr(head, '\0', nl - head)) {
ilog(LOG_WARN, "NUL character in section header in %s%s%s", FMT_M(name));
// jump to the end of the read so we don't continually try and process this bad data
mf->pos += (endp - section_start);
break;
}
*(nl++) = '\0';
Expand Down Expand Up @@ -447,6 +448,8 @@ void metafile_change(char *name) {
char *content = head;
if (memchr(content, '\0', slen)) {
ilog(LOG_WARN, "NUL character in content in section %s in %s%s%s", section, FMT_M(name));
// jump to the end of the read so we don't continually try and process this bad data
mf->pos += (endp - section_start);
break;
}

Expand All @@ -460,6 +463,10 @@ void metafile_change(char *name) {
head += 2;

meta_section(mf, section, content, slen);
// update read position by the amount of data we processed
// so that any issues causing a break above will resume at the
// correct position on the next inotify event
mf->pos += (head - section_start);
}

g_string_free(s, TRUE);
Expand Down