mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
iscsi-scstd: Keep portal tokenizer state local
Use a separate strtok_r saveptr for each listen-address, internal-portal validation and portal-match operation. Preserve delimiters, limits and buffer ownership. No tokenizer race was reproduced; this change makes the parser state explicit and local to each operation. Cppcheck reports strtokCalled at these tokenization sites: Non reentrant function 'strtok' called. For threadsafe applications it is recommended to use the reentrant replacement function 'strtok_r'.
This commit is contained in:
@@ -1131,7 +1131,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
/* We have been provided with a string, check the contents. */
|
||||
if (strchr(p, ' ')) {
|
||||
char *portals = strdup(p);
|
||||
char *portal;
|
||||
char *portal, *saveptr;
|
||||
|
||||
if (!portals) {
|
||||
log_error("Memory error (internal_portal)");
|
||||
@@ -1139,7 +1139,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
portal = strtok(portals, " ");
|
||||
portal = strtok_r(portals, " ", &saveptr);
|
||||
while (portal != NULL) {
|
||||
if (!is_addr(portal)) {
|
||||
log_error("Invalid address supplied %s", portal);
|
||||
@@ -1147,7 +1147,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
portal = strtok(NULL, " ");
|
||||
portal = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
free(portals);
|
||||
} else {
|
||||
|
||||
@@ -910,7 +910,7 @@ int main(int argc, char **argv)
|
||||
gid = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'a': {
|
||||
char *server_address, *token;
|
||||
char *server_address, *token, *saveptr;
|
||||
int i = 0;
|
||||
|
||||
server_address = strdup(optarg);
|
||||
@@ -919,14 +919,14 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
token = strtok(server_address, " ");
|
||||
token = strtok_r(server_address, " ", &saveptr);
|
||||
|
||||
while ((i < ADDR_MAX) && token) {
|
||||
log_debug(0, "Address to listen: %s\n", token);
|
||||
server_addresses[i] = token;
|
||||
|
||||
i++;
|
||||
token = strtok(NULL, " ");
|
||||
token = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -1029,14 +1029,15 @@ static bool on_internal_portal(struct connection *conn)
|
||||
char *portals = strdup(internal_portal);
|
||||
|
||||
if (portals) {
|
||||
char *portal = strtok(portals, " ");
|
||||
char *saveptr;
|
||||
char *portal = strtok_r(portals, " ", &saveptr);
|
||||
|
||||
while (portal != NULL) {
|
||||
if (!strcmp(portal, conn->target_portal)) {
|
||||
free(portals);
|
||||
return true;
|
||||
}
|
||||
portal = strtok(NULL, " ");
|
||||
portal = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
free(portals);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user