Blob Blame History Raw
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp
index e0bdf12..01c673d 100644
--- a/src/tuning/bluetooth.cpp
+++ b/src/tuning/bluetooth.cpp
@@ -46,8 +46,8 @@
 bt_tunable::bt_tunable(void) : tunable("", 1.0, "Good", "Bad", "Unknown")
 {
 	sprintf(desc, _("Bluetooth device interface status"));
-	strcpy(toggle_bad, "/usr/sbin/hciconfig hci0 up &> /dev/null &");
-	strcpy(toggle_good, "/usr/sbin/hciconfig hci0 down &> /dev/null");
+	toggle_bad = "/usr/sbin/hciconfig hci0 up &> /dev/null &";
+	toggle_good = "/usr/sbin/hciconfig hci0 down &> /dev/null";
 }
 
 
@@ -188,9 +188,9 @@ const char *bt_tunable::toggle_script(void)
 	good = good_bad();
 
 	if (good == TUNE_GOOD) {
-		return toggle_bad;
+		return toggle_bad.c_str();
 	}
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 
diff --git a/src/tuning/cpufreq.cpp b/src/tuning/cpufreq.cpp
index c169e6e..f696c89 100644
--- a/src/tuning/cpufreq.cpp
+++ b/src/tuning/cpufreq.cpp
@@ -189,7 +189,7 @@ const char *cpufreq_tunable::toggle_script(void) {
 	int good;
 	good = good_bad();
 
-	strcpy(toggle_good, "/sbin/modprobe cpufreq_ondemand > /dev/null 2>&1\n");
+	toggle_good = "/sbin/modprobe cpufreq_ondemand > /dev/null 2>&1\n";
 
 	if (good == TUNE_GOOD) {
 		dir = opendir("/sys/devices/system/cpu");
@@ -202,12 +202,12 @@ const char *cpufreq_tunable::toggle_script(void) {
 			sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
 			if (stat(filename, &statbuf) == -1)
 				continue;
-			sprintf(tmp, "echo '%s' > '%s';\n", original, filename);
-			strcat(toggle_good, tmp);
+			snprintf(tmp, 4096, "echo '%s' > '%s';\n", original, filename);
+			toggle_good += tmp;
 		}
 
 		closedir(dir);
-		return toggle_good;
+		return toggle_good.c_str();
 	}
 
 	dir = opendir("/sys/devices/system/cpu");
@@ -220,12 +220,12 @@ const char *cpufreq_tunable::toggle_script(void) {
 		sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
 		if (stat(filename, &statbuf) == -1)
 			continue;
-		sprintf(tmp, "echo 'ondemand' > '%s';\n", filename);
-		strcat(toggle_good, tmp);
+		snprintf(tmp, 4096, "echo 'ondemand' > '%s';\n", filename);
+		toggle_good += tmp;
 	}
 
 	closedir(dir);
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 
diff --git a/src/tuning/ethernet.cpp b/src/tuning/ethernet.cpp
index 3164b31..d5ad8ed 100644
--- a/src/tuning/ethernet.cpp
+++ b/src/tuning/ethernet.cpp
@@ -52,11 +52,13 @@ extern void create_all_nics(callback fn);
 
 ethernet_tunable::ethernet_tunable(const char *iface) : tunable("", 0.3, _("Good"), _("Bad"), _("Unknown"))
 {
+	char tmp[4096];
+
 	memset(interf, 0, sizeof(interf));
 	strncpy(interf, iface, sizeof(interf));
 	sprintf(desc, _("Wake-on-lan status for device %s"), iface);
-	sprintf(toggle_good, "ethtool -s %s wol d;", iface);
-
+	snprintf(tmp, 4096, "ethtool -s %s wol d;", iface);
+	toggle_good = tmp;
 }
 
 
@@ -137,7 +139,7 @@ const char *ethernet_tunable::toggle_script(void)
 	good = good_bad();
 
 	if (good != TUNE_GOOD) {
-		return toggle_good;
+		return toggle_good.c_str();
 	}
 
 	return NULL;
diff --git a/src/tuning/runtime.cpp b/src/tuning/runtime.cpp
index b57d53e..3369976 100644
--- a/src/tuning/runtime.cpp
+++ b/src/tuning/runtime.cpp
@@ -42,6 +42,7 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char *
 {
 	ifstream file;
 	sprintf(runtime_path, "%s/power/control", path);
+	char tmp[4096];
 
 
 	sprintf(desc, _("Runtime PM for %s device %s"), bus, dev);
@@ -77,8 +78,10 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char *
 
 
 	}
-	sprintf(toggle_good, "echo 'auto' > '%s';", runtime_path);
-	sprintf(toggle_bad, "echo 'on' > '%s';", runtime_path);
+	snprintf(tmp, 4096, "echo 'auto' > '%s';", runtime_path);
+	toggle_good = tmp;
+	snprintf(tmp, 4096, "echo 'on' > '%s';", runtime_path);
+	toggle_bad = tmp;
 }
 
 int runtime_tunable::good_bad(void)
@@ -112,10 +115,10 @@ const char *runtime_tunable::toggle_script(void)
 	good = good_bad();
 
 	if (good == TUNE_GOOD) {
-		return toggle_bad;
+		return toggle_bad.c_str();
 	}
 
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 
diff --git a/src/tuning/tunable.h b/src/tuning/tunable.h
index 3372378..8f90ee2 100644
--- a/src/tuning/tunable.h
+++ b/src/tuning/tunable.h
@@ -26,6 +26,7 @@
 #define _INCLUDE_GUARD_TUNABLE_H
 
 #include <vector>
+#include <string>
 
 #include "../lib.h"
 
@@ -43,8 +44,8 @@ class tunable {
 	char bad_string[128];
 	char neutral_string[128];
 protected:
-	char toggle_good[4096];
-	char toggle_bad[4096];
+	string toggle_good;
+	string toggle_bad;
 public:
 	char desc[4096];
 	double score;
diff --git a/src/tuning/tuningsysfs.cpp b/src/tuning/tuningsysfs.cpp
index ec1ca6b..aa4ebd5 100644
--- a/src/tuning/tuningsysfs.cpp
+++ b/src/tuning/tuningsysfs.cpp
@@ -43,11 +43,15 @@
 
 sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown"))
 {
+	char tmp[4096];
+
 	strcpy(sysfs_path, _sysfs_path);
 	strcpy(target_value, _target_content);
 	bad_value[0] = 0;
-	sprintf(toggle_good, "echo '%s' > '%s';", target_value, sysfs_path);
-	sprintf(toggle_bad, "echo '%s' > '%s';", bad_value, sysfs_path);
+	snprintf(tmp, 4096, "echo '%s' > '%s';", target_value, sysfs_path);
+	toggle_good = tmp;
+	snprintf(tmp, 4096, "echo '%s' > '%s';", bad_value, sysfs_path);
+	toggle_bad = tmp;
 }
 
 int sysfs_tunable::good_bad(void)
@@ -92,11 +96,11 @@ const char *sysfs_tunable::toggle_script(void) {
 
 	if (good == TUNE_GOOD) {
 		if (strlen(bad_value) > 0)
-			return toggle_bad;
+			return toggle_bad.c_str();
 		return NULL;
 	}
 
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 
diff --git a/src/tuning/tuningusb.cpp b/src/tuning/tuningusb.cpp
index 74bbacf..2cd7efe 100644
--- a/src/tuning/tuningusb.cpp
+++ b/src/tuning/tuningusb.cpp
@@ -43,6 +43,7 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9,
 	char filename[4096];
 	char vendor[2048];
 	char product[2048];
+	char tmp[4096];
 	string str1, str2;
 	sprintf(usb_path, "%s/power/control", path);
 
@@ -75,8 +76,10 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9,
 	else if (strlen(vendor))
 		sprintf(desc, _("Autosuspend for USB device %s [%s]"), vendor, name);
 
-	sprintf(toggle_good, "echo 'auto' > '%s';", usb_path);
-	sprintf(toggle_bad, "echo 'on' > '%s';", usb_path);
+	snprintf(tmp, 4096, "echo 'auto' > '%s';", usb_path);
+	toggle_good = tmp;
+	snprintf(tmp, 4096, "echo 'on' > '%s';", usb_path);
+	toggle_bad = tmp;
 }
 
 int usb_tunable::good_bad(void)
@@ -110,10 +113,10 @@ const char *usb_tunable::toggle_script(void)
 	good = good_bad();
 
 	if (good == TUNE_GOOD) {
-		return toggle_bad;
+		return toggle_bad.c_str();
 	}
 
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 void add_usb_tunables(void)
diff --git a/src/tuning/wifi.cpp b/src/tuning/wifi.cpp
index 77cdfcc..2cc01b8 100644
--- a/src/tuning/wifi.cpp
+++ b/src/tuning/wifi.cpp
@@ -44,11 +44,15 @@ extern "C" {
 
 wifi_tunable::wifi_tunable(const char *_iface) : tunable("", 1.5, _("Good"), _("Bad"), _("Unknown"))
 {
+	char tmp[4096];
+
 	strcpy(iface, _iface);
 	sprintf(desc, _("Wireless Power Saving for interface %s"), iface);
 
-	sprintf(toggle_good, "iw dev %s set power_save on", iface);
-	sprintf(toggle_bad, "iw dev %s set power_save off", iface);
+	snprintf(tmp, 4096, "iw dev %s set power_save on", iface);
+	toggle_good = tmp;
+	snprintf(tmp, 4096, "iw dev %s set power_save off", iface);
+	toggle_bad = tmp;
 }
 
 int wifi_tunable::good_bad(void)
@@ -78,10 +82,10 @@ const char *wifi_tunable::toggle_script(void)
 	good = good_bad();
 
 	if (good == TUNE_GOOD) {
-		return toggle_bad;
+		return toggle_bad.c_str();
 	}
 
-	return toggle_good;
+	return toggle_good.c_str();
 }
 
 void add_wifi_tunables(void)