state: do not derefence unallocated memory
Enforce name_id to be within apk_state allocated area. New apk_name:s can be created later for e.g. unknown packages requested at command line.cute-signatures
parent
33c2bc0d1a
commit
ebe43a5e01
|
@ -23,7 +23,7 @@ struct apk_change {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct apk_state {
|
struct apk_state {
|
||||||
int refs;
|
unsigned int refs, num_names;
|
||||||
struct list_head change_list_head;
|
struct list_head change_list_head;
|
||||||
apk_name_state_t name[];
|
apk_name_state_t name[];
|
||||||
};
|
};
|
||||||
|
|
|
@ -121,6 +121,7 @@ struct apk_state *apk_state_new(struct apk_database *db)
|
||||||
num_bytes = sizeof(struct apk_state) + db->name_id * sizeof(char *);
|
num_bytes = sizeof(struct apk_state) + db->name_id * sizeof(char *);
|
||||||
state = (struct apk_state*) calloc(1, num_bytes);
|
state = (struct apk_state*) calloc(1, num_bytes);
|
||||||
state->refs = 1;
|
state->refs = 1;
|
||||||
|
state->num_names = db->name_id;
|
||||||
list_init(&state->change_list_head);
|
list_init(&state->change_list_head);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -165,6 +166,9 @@ int apk_state_lock_dependency(struct apk_state *state,
|
||||||
struct apk_package *installed = NULL, *latest = NULL, *use;
|
struct apk_package *installed = NULL, *latest = NULL, *use;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (name->id >= state->num_names)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (ns_empty(state->name[name->id])) {
|
if (ns_empty(state->name[name->id])) {
|
||||||
if (dep->result_mask == APK_DEPMASK_CONFLICT)
|
if (dep->result_mask == APK_DEPMASK_CONFLICT)
|
||||||
return apk_state_lock_name(state, name, NULL);
|
return apk_state_lock_name(state, name, NULL);
|
||||||
|
@ -279,6 +283,9 @@ int apk_state_lock_name(struct apk_state *state,
|
||||||
struct apk_package *oldpkg = NULL;
|
struct apk_package *oldpkg = NULL;
|
||||||
int i, j, k, r;
|
int i, j, k, r;
|
||||||
|
|
||||||
|
if (name->id >= state->num_names)
|
||||||
|
return -1;
|
||||||
|
|
||||||
ns_free(state->name[name->id]);
|
ns_free(state->name[name->id]);
|
||||||
state->name[name->id] = ns_from_pkg(newpkg);
|
state->name[name->id] = ns_from_pkg(newpkg);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue