Skip to content

Commit

Permalink
fix segfault when using invalid ROI or AfWindow parameters (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 17, 2024
1 parent 70d44b9 commit fc34d67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 8 additions & 11 deletions parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ const char *parameters_get_error() {
bool parameters_unserialize(parameters_t *params, const uint8_t *buf, size_t buf_size) {
memset(params, 0, sizeof(parameters_t));

char *tmp = malloc(buf_size + 1);
memcpy(tmp, buf, buf_size);
tmp[buf_size] = 0x00;

while (true) {
char *entry = strsep(&tmp, " ");
if (entry == NULL) {
break;
}
char *copy = malloc(buf_size + 1);
memcpy(copy, buf, buf_size);
copy[buf_size] = 0x00;
char *ptr = copy;
char *entry;

while ((entry = strsep(&ptr, " ")) != NULL) {
char *key = strsep(&entry, ":");
char *val = strsep(&entry, ":");

Expand Down Expand Up @@ -160,15 +157,15 @@ bool parameters_unserialize(parameters_t *params, const uint8_t *buf, size_t buf
}
}

free(tmp);
free(copy);

params->buffer_count = 6;
params->capture_buffer_count = params->buffer_count * 2;

return true;

failed:
free(tmp);
free(copy);
parameters_destroy(params);

return false;
Expand Down
11 changes: 8 additions & 3 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
#include "window.h"

bool window_load(const char *encoded, window_t *window) {
char *copy = strdup(encoded);
float vals[4];
int i = 0;
char *token = strtok((char *)encoded, ",");
while (token != NULL) {
char *ptr = copy;
char *token;

while ((token = strsep(&ptr, ",")) != NULL) {
vals[i] = atof(token);
if (vals[i] < 0 || vals[i] > 1) {
free(copy);
return false;
}

i++;
token = strtok(NULL, ",");
}

free(copy);

if (i != 4) {
return false;
}
Expand Down

0 comments on commit fc34d67

Please sign in to comment.