Skip to content

Commit b1dc0d2

Browse files
committed
clients/authconf.c: handle_authconf_args(): revise section title line parsing [#3329]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent f9f6790 commit b1dc0d2

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

clients/authconf.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ static void handle_authconf_args(size_t numargs, char **arg, int global_scope)
458458
/* Section header [section] */
459459
if (arg[0][0] == '[' && arg[0][strlen(arg[0])-1] == ']') {
460460
char *sect_name = NULL, *sect_user = NULL, *sect_host = NULL, *sect_port = NULL, *normalized_sect_name = NULL;
461+
const char *end_bracket = NULL;
461462
upscli_authconf_t *tmp = NULL;
462463

463464
if (!global_scope) {
@@ -466,13 +467,23 @@ static void handle_authconf_args(size_t numargs, char **arg, int global_scope)
466467
}
467468

468469
sect_name = xstrdup(&arg[0][1]); /* forget leading '[' */
469-
sect_name[strlen(sect_name)-1] = '\0'; /* forget trailing ']' */
470+
end_bracket = strchr(sect_name, ']');
471+
if (!end_bracket) {
472+
free(sect_name);
473+
fatalx(EXIT_FAILURE, "%s: Invalid section header format: %s", __func__, arg[0]);
474+
}
475+
*(char *)(end_bracket) = '\0'; /* forget trailing ']' and any characters after it (comments etc.) */
470476

471477
if (upscli_split_auth_section(sect_name, &normalized_sect_name,
472478
&sect_user, &current_section_with_fixed_username,
473479
&sect_host, &sect_port) < 0
474480
) {
475-
fatalx(EXIT_FAILURE, "Invalid nutauth section header: %s", NUT_STRARG(sect_name));
481+
free(normalized_sect_name);
482+
free(sect_name);
483+
free(sect_user);
484+
free(sect_host);
485+
free(sect_port);
486+
fatalx(EXIT_FAILURE, "Invalid nutauth section header: %s", NUT_STRARG(arg[0]));
476487
}
477488

478489
/* Find if section already exists */

0 commit comments

Comments
 (0)