[PATCH 0/2] parthelper: Initialize error object

To observe the error fixed in 1/2 apply the following patch and run parthelper under valgrind, e.g. like this: valgrind libvirt_parthelper /dev/sda -g diff --git i/src/util/virdevmapper.c w/src/util/virdevmapper.c index 4d27c9f104..fad76f35a1 100644 --- i/src/util/virdevmapper.c +++ w/src/util/virdevmapper.c @@ -57,6 +57,8 @@ virDevMapperGetMajor(unsigned int *major) VIR_AUTOSTRINGLIST lines = NULL; size_t i; + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blah")); + if (!virFileExists(CONTROL_PATH)) return -2; Michal Prívozník (2): parthelper: Initialize error object parthelper: Don't leak @canonical_path src/storage/parthelper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.26.2

Some functions called from parthelper can report an error. But that means that the error object must be initialized otherwise virResetError() (which happens as a part of virReportError()) will free random pointers. Reported-by: Katerina Koukiou <kkoukiou@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/storage/parthelper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index 812e90d3cb..29a01d3dd5 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -66,7 +66,8 @@ int main(int argc, char **argv) const char *partsep; bool devmap_partsep = false; - if (virGettextInitialize() < 0) + if (virGettextInitialize() < 0 || + virErrorInitialize() < 0) exit(EXIT_FAILURE); if (argc == 3 && STREQ(argv[2], "-g")) { -- 2.26.2

The @canonical_path variable holds canonicalized path passed as argv[1]. The canonicalized path is obtained either via virFileResolveLink() or plain g_strdup(). Nevertheless, in both cases it must be freed. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/storage/parthelper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index 29a01d3dd5..caa2e8fa62 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) PedPartition *part; int cmd = DISK_LAYOUT; const char *path; - char *canonical_path; + g_autofree char *canonical_path = NULL; const char *partsep; bool devmap_partsep = false; -- 2.26.2

On a Thursday in 2020, Michal Privoznik wrote:
To observe the error fixed in 1/2 apply the following patch and run parthelper under valgrind, e.g. like this:
valgrind libvirt_parthelper /dev/sda -g
diff --git i/src/util/virdevmapper.c w/src/util/virdevmapper.c index 4d27c9f104..fad76f35a1 100644 --- i/src/util/virdevmapper.c +++ w/src/util/virdevmapper.c @@ -57,6 +57,8 @@ virDevMapperGetMajor(unsigned int *major) VIR_AUTOSTRINGLIST lines = NULL; size_t i;
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blah")); + if (!virFileExists(CONTROL_PATH)) return -2;
Michal Prívozník (2): parthelper: Initialize error object parthelper: Don't leak @canonical_path
src/storage/parthelper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik