added asserts to prevent segfaults from dereferencing null pointers

This commit is contained in:
bjoernf 2023-12-30 05:02:49 +01:00
parent 78a07b128f
commit bf6d09e99a

View File

@ -3,6 +3,7 @@
#include "string_handling.h" #include "string_handling.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
void parse_event(char event_string[], struct event **head) { void parse_event(char event_string[], struct event **head) {
char *start_date = strstr(event_string, "\r\nDTSTART;"); char *start_date = strstr(event_string, "\r\nDTSTART;");
@ -20,6 +21,13 @@ void parse_event(char event_string[], struct event **head) {
memset(end_date_str, '\0', 256); memset(end_date_str, '\0', 256);
memset(summary_str, '\0', 512); memset(summary_str, '\0', 512);
assert(start_date != NULL);
assert(end_date != NULL);
assert(sequence != NULL);
assert(summary != NULL);
assert(location != NULL);
assert(transp != NULL);
strncpy(start_date_str, start_date, end_date - start_date); strncpy(start_date_str, start_date, end_date - start_date);
strncpy(end_date_str, end_date, sequence - end_date); strncpy(end_date_str, end_date, sequence - end_date);