Skip to contentSkip to conversation

qga: fix uname() return value check in guest-get-osinfo

PATCH In review Brad Smith 3 participants 4 messages Oct 30 – Nov 16

lore
Share & tools
lore

Brad Smith

author
#0 lore raw

PATCH 1/1 qga: fix uname() return value check in guest-get-osinfo

qga: fix uname() return value check in guest-get-osinfo

POSIX only specifies that uname() returns a non-negative value on success. Solaris returns 1, so guest-get-osinfo treated every successful call as a failure and reported a stale errno.

Check for a negative return value instead, as linux-user/uname.c already does.

---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
index dcc683f6c9..23abaf1956 100644
@@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 
     info = g_new0(GuestOSInfo, 1);
 
-    if (uname(&kinfo) != 0) {
+    if (uname(&kinfo) < 0) {
         error_setg_errno(errp, errno, "uname failed");
     } else {
         info->kernel_version = g_strdup(kinfo.version);
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Brad Smith

qga: fix uname() return value check in guest-get-osinfo

POSIX only specifies that uname() returns a non-negative value on success. Solaris returns 1, so guest-get-osinfo treated every successful call as a failure and reported a stale errno.

Check for a negative return value instead, as linux-user/uname.c already does.

---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
index dcc683f6c9..23abaf1956 100644
@@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 
     info = g_new0(GuestOSInfo, 1);
 
-    if (uname(&kinfo) != 0) {
+    if (uname(&kinfo) < 0) {
         error_setg_errno(errp, errno, "uname failed");
     } else {
         info->kernel_version = g_strdup(kinfo.version);
Signature · 1 line
2.56.0
author
#2 lore raw
In reply to Brad Smith
Quoted 8 lines · Brad Smith

qga: fix uname() return value check in guest-get-osinfo

POSIX only specifies that uname() returns a non-negative value on success. Solaris returns 1, so guest-get-osinfo treated every successful call as a failure and reported a stale errno.

Check for a negative return value instead, as linux-user/uname.c already does.

ping. It would be good to get this into 11.2.

Quoted 18 lines
---
  qga/commands-posix.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
index dcc683f6c9..23abaf1956 100644
@@ -1322,7 +1322,7 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 
      info = g_new0(GuestOSInfo, 1);
 
-    if (uname(&kinfo) != 0) {
+    if (uname(&kinfo) < 0) {
          error_setg_errno(errp, errno, "uname failed");
      } else {
          info->kernel_version = g_strdup(kinfo.version);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Brad Smith
Quoted 6 lines · Brad Smith

qga: fix uname() return value check in guest-get-osinfo

POSIX only specifies that uname() returns a non-negative value on success. Solaris returns 1, so guest-get-osinfo treated every successful call as a failure and reported a stale errno.

Quoted 7 lines

Check for a negative return value instead, as linux-user/uname.c already does.

---
  qga/commands-posix.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)