nvram: use flex array

Clarifies that the struct needs to be over allocated.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22370
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
This commit is contained in:
Rosen Penev 2026-02-10 18:10:15 -08:00 committed by Jonas Jelonek
parent 51a018ee49
commit 55d146432f
No known key found for this signature in database
2 changed files with 3 additions and 4 deletions

View file

@ -77,7 +77,6 @@ static nvram_tuple_t * _nvram_realloc( nvram_handle_t *h, nvram_tuple_t *t,
return NULL;
/* Copy name */
t->name = (char *) &t[1];
strcpy(t->name, name);
t->value = NULL;
@ -242,9 +241,9 @@ nvram_tuple_t * nvram_getall(nvram_handle_t *h)
for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) {
for (t = h->nvram_hash[i]; t; t = t->next) {
if( (x = (nvram_tuple_t *) malloc(sizeof(nvram_tuple_t))) != NULL )
if( (x = malloc(sizeof(*x) + strlen(t->name) + 1)) != NULL )
{
x->name = t->name;
strcpy(x->name, t->name);
x->value = t->value;
x->next = l;
l = x;

View file

@ -38,9 +38,9 @@ struct nvram_header {
} __attribute__((__packed__));
struct nvram_tuple {
char *name;
char *value;
struct nvram_tuple *next;
char name[];
};
struct nvram_handle {