Skip to content

Commit

Permalink
Fixed segfaults on OpenBSD.
Browse files Browse the repository at this point in the history
This patch initializes the first element of the linked list of files
to point to itself. Leaving them uninitialized or pointing to NULL
will cause a segfault on OpenBSD.

Please note that I have not tested this on other BSD varieties.
  • Loading branch information
Colin Stolley committed Feb 15, 2014
1 parent 1069320 commit c234cac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions kqfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void register_paths(int kq, FILE *in, uint32_t watch_flags,
char *line;
size_t len, bytes_read = 0;
int pathlen;
static struct path_entry *paths_head;
static struct path_entry *paths_head = NULL;
struct path_entry *new_path;

/*
Expand Down Expand Up @@ -187,6 +187,12 @@ void register_paths(int kq, FILE *in, uint32_t watch_flags,
strncpy(new_path->path, line, pathlen);
new_path->path[pathlen] = '\0';

if (!paths_head) {
paths_head = new_path;
paths_head->next = paths_head;
paths_head->prev = paths_head;
}

insque(new_path, paths_head);

if (!paths_tail) { paths_tail = new_path; }
Expand Down Expand Up @@ -275,7 +281,7 @@ void dump_paths(int sig)
do {
fprintf(stderr, "%s\n", p_entry->path);
p_entry = p_entry->next;
} while (p_entry);
} while (p_entry && p_entry != paths_tail);
}

int main(int argc, char *argv[])
Expand Down

0 comments on commit c234cac

Please sign in to comment.