mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
hdd_menu: avoid possible format-truncation errors
This commit is contained in:
@@ -664,16 +664,17 @@ bool CHDDMenuHandler::scanDevices()
|
|||||||
printf("HDD: root_dev: 0x%04x\n", root_dev);
|
printf("HDD: root_dev: 0x%04x\n", root_dev);
|
||||||
|
|
||||||
for(int i = 0; i < n;i++) {
|
for(int i = 0; i < n;i++) {
|
||||||
char str[256];
|
char str[255];
|
||||||
char vendor[128] = { 0 };
|
char vendor[128] = { 0 };
|
||||||
char model[128] = { 0 };
|
char model[128] = { 0 };
|
||||||
int64_t bytes = 0;
|
int64_t bytes = 0;
|
||||||
int64_t megabytes;
|
int64_t megabytes;
|
||||||
bool oldkernel = false;
|
bool oldkernel = false;
|
||||||
bool isroot = false;
|
bool isroot = false;
|
||||||
|
size_t d_str_size = sizeof(namelist[i]->d_name);
|
||||||
|
|
||||||
printf("HDD: checking /sys/block/%s\n", namelist[i]->d_name);
|
printf("HDD: checking /sys/block/%s\n", namelist[i]->d_name);
|
||||||
snprintf(str, sizeof(str), "/dev/%s", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/dev/%s", namelist[i]->d_name);
|
||||||
int fd = open(str, O_RDONLY);
|
int fd = open(str, O_RDONLY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
if (ioctl(fd, BLKGETSIZE64, &bytes))
|
if (ioctl(fd, BLKGETSIZE64, &bytes))
|
||||||
@@ -696,11 +697,11 @@ bool CHDDMenuHandler::scanDevices()
|
|||||||
|
|
||||||
megabytes = bytes/1000000;
|
megabytes = bytes/1000000;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "/sys/block/%s/device/vendor", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/sys/block/%s/device/vendor", namelist[i]->d_name);
|
||||||
FILE * f = fopen(str, "r");
|
FILE * f = fopen(str, "r");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
printf("Cant open %s\n", str);
|
printf("Cant open %s\n", str);
|
||||||
snprintf(str, sizeof(str), "/sys/block/%s/device/type", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/sys/block/%s/device/type", namelist[i]->d_name);
|
||||||
f = fopen(str, "r");
|
f = fopen(str, "r");
|
||||||
}
|
}
|
||||||
if (f) {
|
if (f) {
|
||||||
@@ -713,13 +714,13 @@ bool CHDDMenuHandler::scanDevices()
|
|||||||
|
|
||||||
/* the Tripledragon only has kernel 2.6.12 available.... :-( */
|
/* the Tripledragon only has kernel 2.6.12 available.... :-( */
|
||||||
if (oldkernel)
|
if (oldkernel)
|
||||||
snprintf(str, sizeof(str), "/proc/ide/%s/model", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/proc/ide/%s/model", namelist[i]->d_name);
|
||||||
else
|
else
|
||||||
snprintf(str, sizeof(str), "/sys/block/%s/device/model", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/sys/block/%s/device/model", namelist[i]->d_name);
|
||||||
f = fopen(str, "r");
|
f = fopen(str, "r");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
printf("Cant open %s\n", str);
|
printf("Cant open %s\n", str);
|
||||||
snprintf(str, sizeof(str), "/sys/block/%s/device/name", namelist[i]->d_name);
|
snprintf(str, sizeof(str)+d_str_size, "/sys/block/%s/device/name", namelist[i]->d_name);
|
||||||
f = fopen(str, "r");
|
f = fopen(str, "r");
|
||||||
}
|
}
|
||||||
if (f) {
|
if (f) {
|
||||||
@@ -748,8 +749,8 @@ bool CHDDMenuHandler::scanDevices()
|
|||||||
hdd.desc = hdd.devname;
|
hdd.desc = hdd.devname;
|
||||||
hdd_list.push_back(hdd);
|
hdd_list.push_back(hdd);
|
||||||
}
|
}
|
||||||
|
d_str_size = sizeof(vendor) + sizeof(model);
|
||||||
snprintf(str, sizeof(str), "%s %s %ld %s", vendor, model, (long)(megabytes < 10000 ? megabytes : megabytes/1000), megabytes < 10000 ? "MB" : "GB");
|
snprintf(str, sizeof(str)+d_str_size, "%s %s %ld %s", vendor, model, (long)(megabytes < 10000 ? megabytes : megabytes/1000), megabytes < 10000 ? "MB" : "GB");
|
||||||
printf("HDD: %s\n", str);
|
printf("HDD: %s\n", str);
|
||||||
devtitle[namelist[i]->d_name] = str;
|
devtitle[namelist[i]->d_name] = str;
|
||||||
|
|
||||||
@@ -1419,7 +1420,7 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
|
|||||||
char M_opt[50],S_opt[50], opt[100];
|
char M_opt[50],S_opt[50], opt[100];
|
||||||
snprintf(S_opt, sizeof(S_opt), "-S%d", g_settings.hdd_sleep);
|
snprintf(S_opt, sizeof(S_opt), "-S%d", g_settings.hdd_sleep);
|
||||||
snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise);
|
snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise);
|
||||||
snprintf(opt, sizeof(opt), "/dev/%s",namelist[i]->d_name);
|
snprintf(opt, sizeof(opt)+sizeof(namelist[i]->d_name), "/dev/%s",namelist[i]->d_name);
|
||||||
|
|
||||||
if (have_nonbb_hdparm)
|
if (have_nonbb_hdparm)
|
||||||
my_system(4, hdparm, M_opt, S_opt, opt);
|
my_system(4, hdparm, M_opt, S_opt, opt);
|
||||||
|
Reference in New Issue
Block a user