mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
Resolve Coverity complaints in tests/securityselinuxlabeltest.c
Two complaints of RESOURCE_FREE due to going to cleanup prior to a VIR_FREE(line). Two complaints of FORWARD_NULL due to 'tmp' being accessed after a strchr() without first checking if the return was NULL. While looking at the code it seems that 'line' need only be allocated once as the while loop will keep reading into line until eof causing an unreported leak since line was never VIR_FREE()'d at the bottom of the loop.
This commit is contained in:
parent
59cc0fe5aa
commit
a443c3a77a
@ -79,6 +79,7 @@ testSELinuxLoadFileList(const char *testname,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
char *line = NULL;
|
||||||
|
|
||||||
*files = NULL;
|
*files = NULL;
|
||||||
*nfiles = 0;
|
*nfiles = 0;
|
||||||
@ -93,37 +94,43 @@ testSELinuxLoadFileList(const char *testname,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(line, 1024) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
char *line;
|
char *file, *context, *tmp;
|
||||||
char *file, *context;
|
|
||||||
if (VIR_ALLOC_N(line, 1024) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!fgets(line, 1024, fp)) {
|
if (!fgets(line, 1024, fp)) {
|
||||||
if (!feof(fp))
|
if (!feof(fp))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tmp = strchr(line, ';');
|
tmp = strchr(line, ';');
|
||||||
|
if (!tmp) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"unexpected format for line '%s'",
|
||||||
|
line);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
*tmp = '\0';
|
*tmp = '\0';
|
||||||
tmp++;
|
tmp++;
|
||||||
|
|
||||||
if (virAsprintf(&file, "%s/securityselinuxlabeldata%s", abs_builddir, line) < 0) {
|
if (virAsprintf(&file, "%s/securityselinuxlabeldata%s",
|
||||||
VIR_FREE(line);
|
abs_builddir, line) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (*tmp != '\0' && *tmp != '\n') {
|
if (*tmp != '\0' && *tmp != '\n') {
|
||||||
if (VIR_STRDUP(context, tmp) < 0) {
|
if (VIR_STRDUP(context, tmp) < 0) {
|
||||||
VIR_FREE(line);
|
|
||||||
VIR_FREE(file);
|
VIR_FREE(file);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = strchr(context, '\n');
|
tmp = strchr(context, '\n');
|
||||||
*tmp = '\0';
|
if (tmp)
|
||||||
|
*tmp = '\0';
|
||||||
} else {
|
} else {
|
||||||
context = NULL;
|
context = NULL;
|
||||||
}
|
}
|
||||||
@ -142,6 +149,7 @@ testSELinuxLoadFileList(const char *testname,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FORCE_FCLOSE(fp);
|
VIR_FORCE_FCLOSE(fp);
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
|
VIR_FREE(line);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user