qga: Fix crash due to redundant error setting in qmp_guest_file_open()
PATCH 1/1 qga: Fix crash due to redundant error setting in qmp_guest_file_open()
Avoid setting GError multiple times in qmp_guest_file_open() by checking if errp is already set.
This prevents crash caused by repeated error handling calls.
--- qga/commands-win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
qga/commands-win32.c +3 -1
@@ -263,7 +263,9 @@ int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) fd =guest_file_handle_add (fh, errp);if (fd <0 ) {CloseHandle (fh); -error_setg (errp,"failed to add handle to qmp handle table" ); +if (!*errp) { +error_setg (errp,"failed to add handle to qmp handle table" ); + } goto done; }
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 14 lines · Wei Wang
Avoid setting GError multiple times in
qmp_guest_file_open()by checking if errp is already set.
This prevents crash caused by repeated error handling calls.Signed-off-by Wei Wang <[email protected]>--- qga/commands-win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)qga/commands-win32.c +0
-0
qga/commands-win32.c int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) · line 268
Quoted 7 lines
qga/commands-win32.c +3
-1@@ -263,7 +263,9 @@ int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) fd =guest_file_handle_add (fh, errp);if (fd <0 ) {CloseHandle (fh); -error_setg (errp,"failed to add handle to qmp handle table" ); +if (!*errp) { +error_setg (errp,"failed to add handle to qmp handle table" ); + }
guest_file_handle_add() only returns -1 when qga_get_fd_handle returns -1, and qga_get_fd_handle always sets errp.
Therefore, your new conditional call to error_setg will never be executed; remove it entirely.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 14 lines · Wei Wang
Avoid setting GError multiple times in
qmp_guest_file_open()by checking if errp is already set.
This prevents crash caused by repeated error handling calls.Signed-off-by Wei Wang <[email protected]>--- qga/commands-win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)qga/commands-win32.c +0
-0
qga/commands-win32.c int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) · line 270
Quoted 9 lines
qga/commands-win32.c +3
-1@@ -263,7 +263,9 @@ int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) fd =guest_file_handle_add (fh, errp);if (fd <0 ) {CloseHandle (fh); -error_setg (errp,"failed to add handle to qmp handle table" ); +if (!*errp) { +error_setg (errp,"failed to add handle to qmp handle table" ); + } goto done; }
Can guest_file_handle_add() fail without setting an error?
If yes, that's the bug that needs fixing.
If no, the error_setg() here is wrong and needs to be deleted.
Quoted 23 lines · Markus Armbruster
qga/commands-win32.c int64_t qmp_guest_file_open(const char *path, const
Quoted 14 lines · Wei Wang
Avoid setting GError multiple times in
qmp_guest_file_open()by checking if errp is already set.
This prevents crash caused by repeated error handling calls.Signed-off-by Wei Wang <[email protected]>--- qga/commands-win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)qga/commands-win32.c +0
-0@@ -263,7 +263,9 @@ int64_t qmp_guest_file_open(const char *path, constchar *mode, Error **errp)
qga/commands-win32.c int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp)
Quoted 6 lines
qga/commands-win32.c +2
-1fd =guest_file_handle_add (fh, errp);if (fd <0 ) {CloseHandle (fh); -error_setg (errp,"failed to add handle to qmp handle table" ); +if (!*errp) { + error_setg(errp, "failed to add handle to qmp handle
Quoted 7 lines
table");
qga/commands-win32.c int64_t qmp_guest_file_open(const char *path, const char *mode, Error **errp) · line 270
Quoted 3 lines
qga/commands-win32.c +1
-0+ } goto done; }Can
guest_file_handle_add()fail without setting an error?
I checked the code, and it looks like guest_file_handle_add always set error if fail
Quoted 6 lines
If yes, that's the bug that needs fixing.
If no, the
error_setg()here is wrong and needs to be deleted.