From a56428ae3a88191d76c857a7d4e42ae3f93d68de Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 30 Sep 2014 05:28:58 -0700 Subject: [PATCH] client (Unix): when get vbox version, make sure it's not an error msg --- client/hostinfo_unix.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 7c25935909..8df69b6915 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -1226,7 +1226,7 @@ bool isDualGPUMacBook() { int HOST_INFO::get_virtualbox_version() { char path[MAXPATHLEN]; char cmd [MAXPATHLEN+35]; - char *newlinePtr; + char buf[256]; FILE* fd; safe_strcpy(path, "/usr/bin/VBoxManage"); @@ -1239,11 +1239,13 @@ int HOST_INFO::get_virtualbox_version() { safe_strcat(cmd, " --version"); fd = popen(cmd, "r"); if (fd) { - if (fgets(virtualbox_version, sizeof(virtualbox_version), fd)) { - newlinePtr = strchr(virtualbox_version, '\n'); - if (newlinePtr) *newlinePtr = '\0'; - newlinePtr = strchr(virtualbox_version, '\r'); - if (newlinePtr) *newlinePtr = '\0'; + if (fgets(buf, sizeof(buf), fd)) { + strip_whitespace(buf); + int n, a,b,c; + n = sscanf(buf, "%d.%d.%d", &a, &b, &c); + if (n == 3) { + strcpy(virtualbox_version, buf); + } } pclose(fd); }