Merge branch 'tmp-NULL-dereference' into 'master'

Avoid NULL dereference in case of memory exhaustion

Closes #721

See merge request openconnect/ocserv!545
This commit is contained in:
Nikos Mavrogiannopoulos
2026-05-16 20:20:49 +00:00
2 changed files with 17 additions and 2 deletions
+13 -2
View File
@@ -228,6 +228,7 @@ static void append_routes(sec_mod_instance_st *sec_mod_instance, proc_st *proc,
/* if we have known_iroutes, we must append them to the routes list */ /* if we have known_iroutes, we must append them to the routes list */
if (vhost->config->n_known_iroutes > 0 || if (vhost->config->n_known_iroutes > 0 ||
vhost->config->append_routes) { vhost->config->append_routes) {
main_server_st *s = sec_mod_instance->server;
char **old_routes = gc->routes; char **old_routes = gc->routes;
unsigned int old_routes_size = gc->n_routes; unsigned int old_routes_size = gc->n_routes;
unsigned int i, j, append; unsigned int i, j, append;
@@ -237,9 +238,14 @@ static void append_routes(sec_mod_instance_st *sec_mod_instance, proc_st *proc,
if (vhost->config->append_routes) if (vhost->config->append_routes)
to_append += vhost->config->network->n_routes; to_append += vhost->config->network->n_routes;
gc->n_routes = 0;
gc->routes = gc->routes =
talloc_array(proc, char *, old_routes_size + to_append); talloc_array(proc, char *, old_routes_size + to_append);
if (gc->routes == NULL) {
gc->routes = old_routes;
mslog(s, proc, LOG_ERR, "memory error");
return;
}
gc->n_routes = 0;
for (i = 0; i < old_routes_size; i++) { for (i = 0; i < old_routes_size; i++) {
gc->routes[i] = talloc_strdup(proc, old_routes[i]); gc->routes[i] = talloc_strdup(proc, old_routes[i]);
@@ -295,11 +301,16 @@ static void append_routes(sec_mod_instance_st *sec_mod_instance, proc_st *proc,
old_routes = gc->no_routes; old_routes = gc->no_routes;
old_routes_size = gc->n_no_routes; old_routes_size = gc->n_no_routes;
gc->n_no_routes = 0;
gc->no_routes = talloc_array( gc->no_routes = talloc_array(
proc, char *, proc, char *,
old_routes_size + old_routes_size +
vhost->config->network->n_no_routes); vhost->config->network->n_no_routes);
if (gc->no_routes == NULL) {
gc->no_routes = old_routes;
mslog(s, proc, LOG_ERR, "memory error");
return;
}
gc->n_no_routes = 0;
for (i = 0; i < old_routes_size; i++) { for (i = 0; i < old_routes_size; i++) {
gc->no_routes[i] = gc->no_routes[i] =
+4
View File
@@ -1880,6 +1880,10 @@ static bool set_env_from_ws(main_server_st *s)
} }
entries[index] = talloc_zero(s, SnapshotEntryMsg); entries[index] = talloc_zero(s, SnapshotEntryMsg);
if (entries[index] == NULL) {
mslog(s, NULL, LOG_ERR, "memory error");
goto cleanup;
}
*entries[index] = entry_template; *entries[index] = entry_template;
entries[index]->file_descriptor = fd; entries[index]->file_descriptor = fd;
entries[index]->file_name = (char *)file_name; entries[index]->file_name = (char *)file_name;