From 56eba164bd725d7f2b3a0f7df9d165e84cb7fe10 Mon Sep 17 00:00:00 2001
From: Jan Willamowius <jan@willamowius.de>
Date: 周一, 22 4月 2019 00:55:58 +0800
Subject: [PATCH] make sure there is room for nul byte

---
 src/library/os/os-linux.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/library/os/os-linux.c b/src/library/os/os-linux.c
index af21f2c..b4d9441 100644
--- a/src/library/os/os-linux.c
+++ b/src/library/os/os-linux.c
@@ -109,7 +109,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++;
@@ -169,7 +169,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);
 						}
@@ -290,7 +290,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