Skip to content

Commit aac2bc7

Browse files
author
Requiem
committed
Fixed firmware detections on Linux
1 parent df15ccb commit aac2bc7

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/vmaware.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5864,32 +5864,30 @@ struct VM {
58645864
return false;
58655865
#elif (LINUX)
58665866
// Author: dmfrpro
5867-
if (!util::is_admin()) {
5868-
return false;
5869-
}
5870-
58715867
DIR* dir = opendir("/sys/firmware/acpi/tables/");
58725868
if (!dir) {
58735869
debug("FIRMWARE: could not open ACPI tables directory");
58745870
return false;
58755871
}
58765872

5877-
// Same targets as the Windows branch but without "WAET"
58785873
constexpr const char* targets[] = {
5879-
"Parallels Software International","Parallels(R)","innotek",
5880-
"Oracle","VirtualBox","vbox","VBOX","VS2005R2",
5874+
"Parallels Software International","Parallels(R)",
5875+
"innotek","Oracle","VirtualBox","vbox","VBOX","VS2005R2",
58815876
"VMware, Inc.","VMware","VMWARE",
58825877
"S3 Corp.","Virtual Machine","QEMU","pc-q35","BOCHS","BXPC"
58835878
};
58845879

58855880
struct dirent* entry;
58865881
while ((entry = readdir(dir)) != nullptr) {
58875882
// Skip "." and ".."
5888-
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
5883+
if (strcmp(entry->d_name, ".") == 0 ||
5884+
strcmp(entry->d_name, "..") == 0)
58895885
continue;
58905886

58915887
char path[PATH_MAX];
5892-
snprintf(path, sizeof(path), "/sys/firmware/acpi/tables/%s", entry->d_name);
5888+
snprintf(path, sizeof(path),
5889+
"/sys/firmware/acpi/tables/%s",
5890+
entry->d_name);
58935891

58945892
int fd = open(path, O_RDONLY);
58955893
if (fd == -1) {
@@ -5898,17 +5896,11 @@ struct VM {
58985896
}
58995897

59005898
struct stat statbuf;
5901-
if (fstat(fd, &statbuf) != 0) {
5899+
if (fstat(fd, &statbuf) != 0 || S_ISDIR(statbuf.st_mode)) {
59025900
debug("FIRMWARE: skipped ", entry->d_name);
59035901
close(fd);
59045902
continue;
59055903
}
5906-
if (S_ISDIR(statbuf.st_mode)) {
5907-
debug("FIRMWARE: skipped directory ", entry->d_name);
5908-
close(fd);
5909-
continue;
5910-
}
5911-
59125904
long file_size = statbuf.st_size;
59135905
if (file_size <= 0) {
59145906
debug("FIRMWARE: file empty or error ", entry->d_name);
@@ -5922,13 +5914,20 @@ struct VM {
59225914
close(fd);
59235915
continue;
59245916
}
5917+
5918+
ssize_t n = read(fd, buffer, file_size);
59255919
close(fd);
5920+
if (n != file_size) {
5921+
debug("FIRMWARE: could not read full table ", entry->d_name);
5922+
free(buffer);
5923+
continue;
5924+
}
59265925

59275926
for (const char* target : targets) {
59285927
size_t targetLen = strlen(target);
5929-
if (targetLen == 0 || file_size < static_cast<long>(targetLen))
5928+
if ((long)targetLen > file_size)
59305929
continue;
5931-
for (long j = 0; j <= file_size - static_cast<long>(targetLen); ++j) {
5930+
for (long j = 0; j <= file_size - (long)targetLen; ++j) {
59325931
if (memcmp(buffer + j, target, targetLen) == 0) {
59335932
const char* brand = nullptr;
59345933
if (strcmp(target, "Parallels Software International") == 0 ||
@@ -5947,13 +5946,14 @@ struct VM {
59475946
strcmp(target, "VMWARE") == 0) {
59485947
brand = brands::VMWARE;
59495948
}
5950-
else if (strcmp(target, "QEMU")) {
5949+
else if (strcmp(target, "QEMU") == 0) {
59515950
brand = brands::QEMU;
59525951
}
59535952
else if (strcmp(target, "BOCHS") == 0 ||
59545953
strcmp(target, "BXPC") == 0) {
59555954
brand = brands::BOCHS;
59565955
}
5956+
59575957
free(buffer);
59585958
closedir(dir);
59595959
if (brand)

0 commit comments

Comments
 (0)