xenParseXLChannel: Use g_strndup instead of virStrncpy

Make the temporary string an autofree-ing pointer and copy the contents.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-03-02 13:41:22 +01:00
parent dae4dddb12
commit bd1728e969

View File

@ -1070,7 +1070,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
if (list && list->type == VIR_CONF_LIST) { if (list && list->type == VIR_CONF_LIST) {
list = list->list; list = list->list;
while (list) { while (list) {
char type[10]; g_autofree char *type = NULL;
char *key; char *key;
if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
@ -1087,11 +1087,8 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
if (STRPREFIX(key, "connection=")) { if (STRPREFIX(key, "connection=")) {
int len = nextkey ? (nextkey - data) : strlen(data); int len = nextkey ? (nextkey - data) : strlen(data);
if (virStrncpy(type, data, len, sizeof(type)) < 0) { g_clear_pointer(&type, g_free);
virReportError(VIR_ERR_INTERNAL_ERROR, type = g_strndup(data, len);
_("connection %s too big"), data);
goto skipchannel;
}
} else if (STRPREFIX(key, "name=")) { } else if (STRPREFIX(key, "name=")) {
int len = nextkey ? (nextkey - data) : strlen(data); int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(name); VIR_FREE(name);