|
|
480824 |
diff --git a/src/main.cpp b/src/main.cpp
|
|
|
480824 |
index 9da3167..7ead705 100644
|
|
|
480824 |
--- a/src/main.cpp
|
|
|
480824 |
+++ b/src/main.cpp
|
|
|
480824 |
@@ -403,7 +403,12 @@ int main(int argc, char **argv)
|
|
|
480824 |
|
|
|
480824 |
case 'h': /* html report */
|
|
|
480824 |
reporttype = REPORT_HTML;
|
|
|
480824 |
- sprintf(filename, "%s", optarg ? optarg : "powertop.html" );
|
|
|
480824 |
+ snprintf(filename, 4096, "%s", optarg ? optarg : "powertop.html" );
|
|
|
480824 |
+ if (!strlen(filename))
|
|
|
480824 |
+ {
|
|
|
480824 |
+ fprintf(stderr, _("Invalid HTML filename\n"));
|
|
|
480824 |
+ exit(1);
|
|
|
480824 |
+ }
|
|
|
480824 |
break;
|
|
|
480824 |
|
|
|
480824 |
case 't':
|
|
|
480824 |
@@ -424,7 +429,12 @@ int main(int argc, char **argv)
|
|
|
480824 |
|
|
|
480824 |
case 'C': /* csv report*/
|
|
|
480824 |
reporttype = REPORT_CSV;
|
|
|
480824 |
- sprintf(filename, "%s", optarg ? optarg : "powertop.csv");
|
|
|
480824 |
+ snprintf(filename, 4096, "%s", optarg ? optarg : "powertop.csv");
|
|
|
480824 |
+ if (!strlen(filename))
|
|
|
480824 |
+ {
|
|
|
480824 |
+ fprintf(stderr, _("Invalid CSV filename\n"));
|
|
|
480824 |
+ exit(1);
|
|
|
480824 |
+ }
|
|
|
480824 |
break;
|
|
|
480824 |
case '?': /* Unknown option */
|
|
|
480824 |
/* getopt_long already printed an error message. */
|
|
|
480824 |
diff --git a/src/report/report.cpp b/src/report/report.cpp
|
|
|
480824 |
index c018bb1..b01b925 100644
|
|
|
480824 |
--- a/src/report/report.cpp
|
|
|
480824 |
+++ b/src/report/report.cpp
|
|
|
480824 |
@@ -149,28 +149,27 @@ static void system_info(void)
|
|
|
480824 |
void init_report_output(char *filename_str, int iterations)
|
|
|
480824 |
{
|
|
|
480824 |
size_t period;
|
|
|
480824 |
- char file_prefix[4096];
|
|
|
480824 |
- char file_postfix[8];
|
|
|
480824 |
+ string filename;
|
|
|
480824 |
time_t stamp;
|
|
|
480824 |
char datestr[200];
|
|
|
480824 |
|
|
|
480824 |
- string mystring = string(filename_str);
|
|
|
480824 |
- sprintf(file_postfix, "%s",
|
|
|
480824 |
- (reporttype == REPORT_HTML ? "html" : "csv"));
|
|
|
480824 |
- period=mystring.find_last_of(".");
|
|
|
480824 |
- sprintf(file_prefix, "%s",mystring.substr(0,period).c_str());
|
|
|
480824 |
- memset(&datestr, 0, 200);
|
|
|
480824 |
- memset(&stamp, 0, sizeof(time_t));
|
|
|
480824 |
- stamp=time(NULL);
|
|
|
480824 |
- strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp));
|
|
|
480824 |
-
|
|
|
480824 |
- if (iterations != 1)
|
|
|
480824 |
- sprintf(reportout.filename, "%s-%s.%s",
|
|
|
480824 |
- file_prefix, datestr,file_postfix);
|
|
|
480824 |
+ if (iterations == 1)
|
|
|
480824 |
+ sprintf(reportout.filename, "%s", filename_str);
|
|
|
480824 |
else
|
|
|
480824 |
- sprintf(reportout.filename, "%s.%s",
|
|
|
480824 |
- file_prefix, file_postfix);
|
|
|
480824 |
-
|
|
|
480824 |
+ {
|
|
|
480824 |
+ filename = string(filename_str);
|
|
|
480824 |
+ period = filename.find_last_of(".");
|
|
|
480824 |
+ if (period > filename.length())
|
|
|
480824 |
+ period = filename.length();
|
|
|
480824 |
+ memset(&datestr, 0, 200);
|
|
|
480824 |
+ memset(&stamp, 0, sizeof(time_t));
|
|
|
480824 |
+ stamp = time(NULL);
|
|
|
480824 |
+ strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp));
|
|
|
480824 |
+ snprintf(reportout.filename, 4096, "%s-%s%s",
|
|
|
480824 |
+ filename.substr(0, period).c_str(), datestr,
|
|
|
480824 |
+ filename.substr(period).c_str());
|
|
|
480824 |
+ }
|
|
|
480824 |
+
|
|
|
480824 |
reportout.report_file = fopen(reportout.filename, "wm");
|
|
|
480824 |
if (!reportout.report_file) {
|
|
|
480824 |
fprintf(stderr, _("Cannot open output file %s (%s)\n"),
|