mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
cpu: fix possible crash in getModels
Commit 86a15a25 introduced a new cpu driver API 'getModels'. Public API allow you to pass NULL for models to get only number of existing models. However the new code will crash with segfault so we have to count with the possibility that the user wants only the number. There is also difference in order of the models gathered by this new API as the old approach was inserting the elements to the end of the array so we should use 'VIR_APPEND_ELEMENT'. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
48a055607c
commit
4a4cff58ef
@ -666,11 +666,15 @@ ppcGetModels(char ***models)
|
||||
|
||||
model = map->models;
|
||||
while (model != NULL) {
|
||||
if (VIR_STRDUP(name, model->name) < 0)
|
||||
goto error;
|
||||
if (models) {
|
||||
if (VIR_STRDUP(name, model->name) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_INSERT_ELEMENT(*models, 0, nmodels, name) < 0)
|
||||
goto error;
|
||||
if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0)
|
||||
goto error;
|
||||
} else {
|
||||
nmodels++;
|
||||
}
|
||||
|
||||
model = model->next;
|
||||
}
|
||||
@ -681,7 +685,10 @@ ppcGetModels(char ***models)
|
||||
return nmodels;
|
||||
|
||||
error:
|
||||
virStringFreeList(*models);
|
||||
if (models) {
|
||||
virStringFreeList(*models);
|
||||
*models = NULL;
|
||||
}
|
||||
nmodels = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -2176,11 +2176,15 @@ x86GetModels(char ***models)
|
||||
|
||||
model = map->models;
|
||||
while (model != NULL) {
|
||||
if (VIR_STRDUP(name, model->name) < 0)
|
||||
goto error;
|
||||
if (models) {
|
||||
if (VIR_STRDUP(name, model->name) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_INSERT_ELEMENT(*models, 0, nmodels, name) < 0)
|
||||
goto error;
|
||||
if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0)
|
||||
goto error;
|
||||
} else {
|
||||
nmodels++;
|
||||
}
|
||||
|
||||
model = model->next;
|
||||
}
|
||||
@ -2188,7 +2192,10 @@ x86GetModels(char ***models)
|
||||
return nmodels;
|
||||
|
||||
error:
|
||||
virStringFreeList(*models);
|
||||
if (models) {
|
||||
virStringFreeList(*models);
|
||||
*models = NULL;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user