From 97ca2423a4686f7f9e85a33a88556dae4aad1bab Mon Sep 17 00:00:00 2001
From: Maximilien Siavelis <m@siav.pw>
Date: 周一, 06 5月 2019 21:47:20 +0800
Subject: [PATCH] Merge pull request #21 from matteovaralta91/master

---
 src/library/os/os-linux.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/library/os/os-linux.c b/src/library/os/os-linux.c
index 717373a..7869651 100644
--- a/src/library/os/os-linux.c
+++ b/src/library/os/os-linux.c
@@ -65,11 +65,11 @@
 	struct mntent *ent;
 
 	int maxDrives, currentDrive, i, drive_found;
-	__ino64_t *statDrives;
-	DiskInfo *tmpDrives;
-	FILE *aFile;
-	DIR *disk_by_uuid_dir, *disk_by_label;
-	struct dirent *dir;
+	__ino64_t *statDrives = NULL;
+	DiskInfo *tmpDrives = NULL;
+	FILE *aFile = NULL;
+	DIR *disk_by_uuid_dir = NULL, *disk_by_label = NULL;
+	struct dirent *dir = NULL;
 	FUNCTION_RETURN result;
 
 	if (diskInfos != NULL) {
@@ -87,12 +87,15 @@
 	aFile = setmntent("/proc/mounts", "r");
 	if (aFile == NULL) {
 		/*proc not mounted*/
+		free(tmpDrives);
+		free(statDrives);
 		return FUNC_RET_ERROR;
 	}
 
 	currentDrive = 0;
 	while (NULL != (ent = getmntent(aFile))) {
 		if ((strncmp(ent->mnt_type, "ext", 3) == 0
+				|| strncmp(ent->mnt_type, "xfs", 3) == 0
 				|| strncmp(ent->mnt_type, "vfat", 4) == 0
 				|| strncmp(ent->mnt_type, "ntfs", 4) == 0)
 				&& ent->mnt_fsname != NULL
@@ -107,7 +110,7 @@
 				if (drive_found == -1) {
 					LOG_DEBUG("mntent: %s %s %d\n", ent->mnt_fsname, ent->mnt_dir,
 							(unsigned long int)mount_stat.st_ino);
-					strcpy(tmpDrives[currentDrive].device, ent->mnt_fsname);
+					strncpy(tmpDrives[currentDrive].device, ent->mnt_fsname, 255-1);
 					statDrives[currentDrive] = mount_stat.st_ino;
 					drive_found = currentDrive;
 					currentDrive++;
@@ -167,7 +170,7 @@
 				if (stat(cur_dir, &sym_stat) == 0) {
 					for (i = 0; i < currentDrive; i++) {
 						if (sym_stat.st_ino == statDrives[i]) {
-							strncpy(tmpDrives[i].label, dir->d_name, 255);
+							strncpy(tmpDrives[i].label, dir->d_name, 255-1);
 							printf("label %d %s %s\n", i, tmpDrives[i].label,
 									tmpDrives[i].device);
 						}
@@ -288,7 +291,7 @@
 	strcat(proc_path, pidStr);
 	strcat(proc_path, "/exe");
 
-	int ch = readlink(proc_path, path, MAX_PATH);
+	int ch = readlink(proc_path, path, MAX_PATH-1);
 	if (ch != -1) {
 		path[ch] = '\0';
 		strncpy(buffer, path, ch);

--
Gitblit v1.9.1