From: Razvan Cojocaru <[email protected]> gc_realloc() aborts via check_malloc_return() and never returns NULL. Remove the NULL handling from alloc_{local,connection,remote}_entry(), their now unused msglevel parameter, and the callers' checks.
Change-Id: Iec85d53ce1076639bd6ceaf3ba7d53cc9e79d7a3 Signed-off-by: Razvan Cojocaru <[email protected]> Acked-by: Frank Lichtenheld <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2196 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2196 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld <[email protected]> diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 1d8bb2a..de6efdf 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1377,7 +1377,7 @@ } static struct local_entry * -alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc) +alloc_local_entry(struct connection_entry *ce, struct gc_arena *gc) { struct local_list *l = alloc_local_list_if_undef(ce, gc); struct local_entry *e; @@ -1387,16 +1387,7 @@ const int new_cap = l->capacity + 1; const size_t elem_size = sizeof(*l->array); - struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc); - if (!new_array) - { - msg(msglevel, - "Unable to process more local options: out of memory. Number of entries = %d", - l->len); - return NULL; - } - - l->array = new_array; + l->array = gc_realloc(l->array, new_cap * elem_size, gc); l->capacity = new_cap; } @@ -1418,7 +1409,7 @@ } static struct connection_entry * -alloc_connection_entry(struct options *options, const msglvl_t msglevel) +alloc_connection_entry(struct options *options) { struct connection_list *l = alloc_connection_list_if_undef(options); struct connection_entry *e; @@ -1426,16 +1417,7 @@ if (l->len == l->capacity) { int capacity = l->capacity + CONNECTION_LIST_SIZE; - struct connection_entry **ce = - gc_realloc(l->array, capacity * sizeof(struct connection_entry *), &options->gc); - if (ce == NULL) - { - msg(msglevel, - "Unable to process more connection options: out of memory. Number of entries = %d", - l->len); - return NULL; - } - l->array = ce; + l->array = gc_realloc(l->array, capacity * sizeof(struct connection_entry *), &options->gc); l->capacity = capacity; } ALLOC_OBJ_GC(e, struct connection_entry, &options->gc); @@ -1454,7 +1436,7 @@ } static struct remote_entry * -alloc_remote_entry(struct options *options, const msglvl_t msglevel) +alloc_remote_entry(struct options *options) { struct remote_list *l = alloc_remote_list_if_undef(options); struct remote_entry *e; @@ -1462,16 +1444,7 @@ if (l->len == l->capacity) { int capacity = l->capacity + CONNECTION_LIST_SIZE; - struct remote_entry **re = - gc_realloc(l->array, capacity * sizeof(struct remote_entry *), &options->gc); - if (re == NULL) - { - msg(msglevel, - "Unable to process more remote options: out of memory. Number of entries = %d", - l->len); - return NULL; - } - l->array = re; + l->array = gc_realloc(l->array, capacity * sizeof(struct remote_entry *), &options->gc); l->capacity = capacity; } ALLOC_OBJ_GC(e, struct remote_entry, &options->gc); @@ -3069,20 +3042,16 @@ { const struct remote_entry *re = rl->array[i]; struct connection_entry ce = o->ce; - struct connection_entry *ace; ASSERT(re->remote); connection_entry_load_re(&ce, re); - ace = alloc_connection_entry(o, M_USAGE); - ASSERT(ace); + struct connection_entry *ace = alloc_connection_entry(o); *ace = ce; } } else if (!o->remote_list && !o->connection_list) { - struct connection_entry *ace; - ace = alloc_connection_entry(o, M_USAGE); - ASSERT(ace); + struct connection_entry *ace = alloc_connection_entry(o); *ace = o->ce; } @@ -3115,8 +3084,7 @@ { /* if no 'local' directive was specified, convert the global port * setting to a listen entry */ - struct local_entry *e = alloc_local_entry(&o->ce, M_USAGE, &o->gc); - ASSERT(e); + struct local_entry *e = alloc_local_entry(&o->ce, &o->gc); e->port = o->ce.local_port; e->proto = o->ce.proto; } @@ -4486,12 +4454,9 @@ } else if (streq(p[0], "local") && p[1] && !p[4]) { - struct local_entry *e; - VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); - e = alloc_local_entry(&options->ce, M_USAGE, &options->gc); - ASSERT(e); + struct local_entry *e = alloc_local_entry(&options->ce, &options->gc); /* '*' is treated as 'ask the system to get some socket', * therefore force binding on a particular address only when @@ -4522,7 +4487,6 @@ if (is_inline) { struct options sub; - struct connection_entry *e; init_options(&sub); sub.ce = options->ce; @@ -4536,12 +4500,7 @@ goto err; } - e = alloc_connection_entry(options, msglevel); - if (!e) - { - uninit_options(&sub); - goto err; - } + struct connection_entry *e = alloc_connection_entry(options); *e = sub.ce; gc_transfer(&options->gc, &sub.gc); uninit_options(&sub); @@ -4630,11 +4589,7 @@ } if (permission_mask & OPT_P_GENERAL) { - struct remote_entry *e = alloc_remote_entry(options, msglevel); - if (!e) - { - goto err; - } + struct remote_entry *e = alloc_remote_entry(options); *e = re; } else if (permission_mask & OPT_P_CONNECTION) _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
