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.
This commit is contained in:
Gleb Chesnokov
2026-10-21 13:20:12 +03:00
parent 6ba7a47525
commit 99786118c8
+11 -2
View File
@@ -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) {