diff options
author | 2022-03-18 20:21:56 -0500 | |
---|---|---|
committer | 2022-05-07 15:57:18 +0200 | |
commit | e8028be8390c3daeadf5775d2e1c21c644ff4ee4 (patch) | |
tree | 8d20af8275a3b2e5a5300b9e3171b1bcaebf69b7 /swaynag | |
parent | swaynag: do error checking and rename read_from_stdin (diff) | |
download | sway-e8028be8390c3daeadf5775d2e1c21c644ff4ee4.tar.gz sway-e8028be8390c3daeadf5775d2e1c21c644ff4ee4.tar.zst sway-e8028be8390c3daeadf5775d2e1c21c644ff4ee4.zip |
swaynag: improve robustness when loading config
Diffstat (limited to 'swaynag')
-rw-r--r-- | swaynag/config.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/swaynag/config.c b/swaynag/config.c index 5ff00bdb..ac5f31c0 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -422,24 +422,17 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) { | |||
422 | 422 | ||
423 | if (line[0] == '[') { | 423 | if (line[0] == '[') { |
424 | char *close = strchr(line, ']'); | 424 | char *close = strchr(line, ']'); |
425 | if (!close) { | 425 | if (!close || close != &line[nread - 2] || nread <= 3) { |
426 | fprintf(stderr, "Closing bracket not found on line %d\n", | 426 | fprintf(stderr, "Line %d is malformed\n", line_number); |
427 | line_number); | ||
428 | result = 1; | 427 | result = 1; |
429 | break; | 428 | break; |
430 | } | 429 | } |
431 | char *name = calloc(1, close - line); | 430 | *close = '\0'; |
432 | if (!name) { | 431 | type = swaynag_type_get(types, &line[1]); |
433 | perror("calloc"); | ||
434 | return EXIT_FAILURE; | ||
435 | } | ||
436 | strncat(name, line + 1, close - line - 1); | ||
437 | type = swaynag_type_get(types, name); | ||
438 | if (!type) { | 432 | if (!type) { |
439 | type = swaynag_type_new(name); | 433 | type = swaynag_type_new(&line[1]); |
440 | list_add(types, type); | 434 | list_add(types, type); |
441 | } | 435 | } |
442 | free(name); | ||
443 | } else { | 436 | } else { |
444 | char *flag = malloc(nread + 3); | 437 | char *flag = malloc(nread + 3); |
445 | if (!flag) { | 438 | if (!flag) { |