1
1
Fork 0
mirror of https://github.com/swaywm/sway synced 2024-05-12 14:46:06 +02:00

swaynag: improve robustness when loading config

This commit is contained in:
Nihal Jere 2022-03-18 20:21:56 -05:00 committed by Simon Ser
parent 5d924f2b12
commit e8028be839

View File

@ -422,24 +422,17 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
if (line[0] == '[') { if (line[0] == '[') {
char *close = strchr(line, ']'); char *close = strchr(line, ']');
if (!close) { if (!close || close != &line[nread - 2] || nread <= 3) {
fprintf(stderr, "Closing bracket not found on line %d\n", fprintf(stderr, "Line %d is malformed\n", line_number);
line_number);
result = 1; result = 1;
break; break;
} }
char *name = calloc(1, close - line); *close = '\0';
if (!name) { type = swaynag_type_get(types, &line[1]);
perror("calloc");
return EXIT_FAILURE;
}
strncat(name, line + 1, close - line - 1);
type = swaynag_type_get(types, name);
if (!type) { if (!type) {
type = swaynag_type_new(name); type = swaynag_type_new(&line[1]);
list_add(types, type); list_add(types, type);
} }
free(name);
} else { } else {
char *flag = malloc(nread + 3); char *flag = malloc(nread + 3);
if (!flag) { if (!flag) {