mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
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:
+11
-2
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user