feat: introduce sanitizers

had to fix some things
This commit is contained in:
Asger Gitz-Johansen 2024-08-26 19:35:05 +02:00
parent 0f1aa982f4
commit cfffa43428
6 changed files with 57 additions and 13 deletions

View File

@ -18,9 +18,12 @@ CFLAGS += -DSCI_NAME="\"$(NAME)\""
CFLAGS += -DSCI_DESCRIPTION="\"$(DESCRIPTION)\""
CFLAGS += -D_POSIX_C_SOURCE=2
CFLAGS += -D_GNU_SOURCE
CFLAGS += -Wall -Werror -std=c11 -g
CFLAGS += -Wall -Werror -std=c11
CFLAGS += -Iinclude
CFLAGS += -lpthread -luuid
CFLAGS += -fsanitize=address
CFLAGS += -fsanitize=undefined
CFLAGS += -g
.PHONY: all clean dist install

View File

@ -20,6 +20,7 @@
- [ ] Port this document to gitea issue tracking
- [x] enable PATH-able programs and argv in the command section
- [ ] custom environment variable passing. Something like `-e MY_TOKEN` ala docker-style
- [x] address sanitizers please.
- [ ] Ninth things ninth, fix bugs, see below
- [ ] Tenth things tenth, write manpages, choose license
- [ ] Eleventh things Eleventh, polish

View File

@ -48,4 +48,11 @@ void remove_strlist_node(strlist_node* node);
// This function is not threadsafe.
void clear_strlist(strlist_node* root);
// Convert a strlist to an array of strings.
// Note that this copies the strlist, you still have to free it.
// The array itself is NULL terminated, enabling you to iterate to the end.
// The array should be free'd, as well as each of the entries.
// Returns NULL if the provided strlist is empty.
char** strlist_to_array(strlist_node* root);
#endif

View File

@ -24,7 +24,10 @@ void set_logdir(const char* logdir) {
char* create_pipeline_id() {
uuid_t uuid;
uuid_generate(uuid);
char* pipeline_id = malloc(32);
// example uuid
// 662ddee9-ee7c-4d13-8999-a2604c6d12d6
// it's 36 characters (+null)
char* pipeline_id = malloc(sizeof(char) * 37);
uuid_unparse_lower(uuid, pipeline_id);
return pipeline_id;
}
@ -99,4 +102,5 @@ end:
free(url);
free(trigger);
free(id);
free(data);
}

View File

@ -18,6 +18,7 @@
#include "notify.h"
#include "util.h"
#include "log.h"
#include <stdlib.h>
#define EV_SIZE sizeof(struct inotify_event)
#define BUF_LEN EV_SIZE * 32
@ -39,13 +40,13 @@ void listen_for_changes(const pipeline_conf* config, notify_callback callback) {
assert(r != -1);
for(int i = 0; i < r; ) {
struct inotify_event* e = (struct inotify_event*)&buffer[i];
pipeline_event ev;
ev.event = e;
ev.name = config->name;
ev.url = config->url;
ev.trigger = config->trigger;
ev.command = config->command;
callback(&ev);
pipeline_event* ev = malloc(sizeof(pipeline_event));
ev->event = e;
ev->name = config->name;
ev->url = config->url;
ev->trigger = config->trigger;
ev->command = config->command;
callback(ev);
i += EV_SIZE + e->len;
}
ASSERT_SYSCALL_SUCCESS(close(fd));

View File

@ -53,10 +53,38 @@ void remove_strlist_node(strlist_node* node) {
void clear_strlist(strlist_node* root) {
strlist_node* cursor = root;
while(cursor != NULL) {
cursor = cursor->next;
if(cursor->str)
if(cursor->str != NULL)
free(cursor->str);
cursor->str = NULL;
free(cursor->previous);
strlist_node* prev = cursor;
cursor = cursor->next;
free(prev);
}
}
size_t strlist_length(strlist_node* root) {
size_t result = 0;
strlist_node* cursor = root;
while(cursor != NULL) {
result++;
cursor = cursor->next;
}
return result;
}
char** strlist_to_array(strlist_node* root) {
size_t len = strlist_length(root);
if(len <= 0)
return NULL;
char** result = malloc(sizeof(char*) * (len + 1));
memset(result, len+1, (size_t)NULL);
strlist_node* cursor = root;
for(int i = 0; i < len; i++) {
if(cursor == NULL)
break;
if(cursor->str == NULL)
continue;
result[i] = strdup(cursor->str);
cursor = cursor->next;
}
return result;
}