From 99786118c8b43c48456a853669adf2b6efc96b82 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 09:51:32 +0300 Subject: [PATCH] iscsi-scstd: Report iSNS configuration allocation failures The saved Cppcheck report shows that config_isns_load cannot fail: iscsi-scst/usr/config.c:1162: style: Condition 'err==0' is always true [knownConditionTrueFalse] Manual review of that path found an unchecked strdup. An allocation failure discards the existing server name and silently accepts the configuration without its iSNS server. The diagnostic above describes the constant result, not the unchecked allocation itself. Duplicate the replacement before freeing the old name and return -ENOMEM on failure. Propagate that error through config_load before initializing iSNS or applying the remaining configuration. --- iscsi-scst/usr/config.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 7fd6d0430..3cb97d4c5 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -1082,8 +1082,15 @@ static int config_isns_load(const char *config) if ((*p == '\0') || (*p == '#')) continue; if (!strcasecmp(p, ISCSI_ISNS_SERVER_ATTR_NAME)) { + const char *name = config_sep_string(&q); + char *server = strdup(name); + + if (!server) { + log_error("Unable to duplicate iSNS server name %s", name); + return -ENOMEM; + } free(isns_server); - isns_server = strdup(config_sep_string(&q)); + isns_server = server; } else if (!strcasecmp(p, ISCSI_ISNS_ACCESS_CONTROL_ATTR_NAME)) { char *str = config_sep_string(&q); @@ -1159,7 +1166,9 @@ int config_load(const char *config_name) buf[size] = '\0'; err = config_isns_load(buf); - if ((err == 0) && (isns_server != NULL)) { + if (err != 0) + goto out_free; + if (isns_server) { rc = isns_init(); if (rc != 0) {