1
0
Fork 0
forked from murx/irc9

Handle missing config arguments on musl

This commit is contained in:
Johannes Findeisen 2026-11-29 04:17:07 +01:00
commit 76578805ba

20
irc9.c
View file

@ -649,11 +649,11 @@ static void load_config(const char *path)
key = strtok_r(p, " \t", &save); key = strtok_r(p, " \t", &save);
if (!key) continue; if (!key) continue;
if (strcasecmp(key, "name") == 0) { if (strcasecmp(key, "name") == 0) {
save += strspn(save, " \t"); if (save) save += strspn(save, " \t");
size_t len = strlen(save); size_t len = save ? strlen(save) : 0;
while (len && (save[len - 1] == ' ' || save[len - 1] == '\t')) while (len && (save[len - 1] == ' ' || save[len - 1] == '\t'))
save[--len] = 0; save[--len] = 0;
if (last && *save) { if (last && len) {
free(last->name); free(last->name);
last->name = dupstr(save); last->name = dupstr(save);
} else { } else {
@ -662,8 +662,8 @@ static void load_config(const char *path)
continue; continue;
} }
if (strcasecmp(key, "autocommand") == 0) { if (strcasecmp(key, "autocommand") == 0) {
save += strspn(save, " \t"); if (save) save += strspn(save, " \t");
if (last && *save && strlen(save) <= MAXLINE - 2 && if (last && save && *save && strlen(save) <= MAXLINE - 2 &&
!strchr(save, '\r')) { !strchr(save, '\r')) {
free(last->autocommand); free(last->autocommand);
last->autocommand = dupstr(save); last->autocommand = dupstr(save);
@ -684,11 +684,11 @@ static void load_config(const char *path)
*channel_tail = channel; *channel_tail = channel;
channel_tail = &channel->next; channel_tail = &channel->next;
save += strspn(save, " \t"); const char *command = save ? save + strspn(save, " \t") : "";
if (*save == '/' && save[1] && strlen(save) < MAXINPUT && if (*command == '/' && command[1] && strlen(command) < MAXINPUT &&
!strchr(save, '\r')) !strchr(command, '\r'))
channel->command = dupstr(save); channel->command = dupstr(command);
else if (*save) else if (*command)
fprintf(stderr, "irc9: ignoring invalid command for channel %s\n", a1); fprintf(stderr, "irc9: ignoring invalid command for channel %s\n", a1);
} }
#endif #endif