aboutsummaryrefslogtreecommitdiff
path: root/swaynag
diff options
context:
space:
mode:
authorNihal Jere <nihal@nihaljere.xyz>2022-03-18 20:21:56 -0500
committerSimon Ser <contact@emersion.fr>2022-05-07 15:57:18 +0200
commite8028be8390c3daeadf5775d2e1c21c644ff4ee4 (patch)
tree8d20af8275a3b2e5a5300b9e3171b1bcaebf69b7 /swaynag
parent5d924f2b12055761b8b155bce61925b6384f070b (diff)
swaynag: improve robustness when loading config
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c17
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) {
if (line[0] == '[') {
char *close = strchr(line, ']');
- if (!close) {
- fprintf(stderr, "Closing bracket not found on line %d\n",
- line_number);
+ if (!close || close != &line[nread - 2] || nread <= 3) {
+ fprintf(stderr, "Line %d is malformed\n", line_number);
result = 1;
break;
}
- char *name = calloc(1, close - line);
- if (!name) {
- perror("calloc");
- return EXIT_FAILURE;
- }
- strncat(name, line + 1, close - line - 1);
- type = swaynag_type_get(types, name);
+ *close = '\0';
+ type = swaynag_type_get(types, &line[1]);
if (!type) {
- type = swaynag_type_new(name);
+ type = swaynag_type_new(&line[1]);
list_add(types, type);
}
- free(name);
} else {
char *flag = malloc(nread + 3);
if (!flag) {