Commit e295a024 authored by Stefan Pavikevik's avatar Stefan Pavikevik Committed by Marge Bot

check for safe arguments, raising error when invalid (fix #17720)

parent 84dd9610
......@@ -21,7 +21,10 @@
#include <ctype.h>
#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
......@@ -98,6 +101,9 @@ static int openStatsFile (
static StgWord64 decodeSize (
const char *flag, uint32_t offset, StgWord64 min, StgWord64 max);
static double parseDouble (
const char *arg, bool *error);
static void bad_option (const char *s);
#if defined(DEBUG)
......@@ -1326,8 +1332,13 @@ error = true;
if (rts_argv[arg][2] == '\0') {
/* use default */
} else {
double intervalSeconds = parseDouble(rts_argv[arg]+2, &error);
if (error) {
errorBelch("bad value for -i");
}
RtsFlags.ProfFlags.heapProfileInterval =
fsecondsToTime(atof(rts_argv[arg]+2));
fsecondsToTime(intervalSeconds);
}
break;
......@@ -1337,8 +1348,13 @@ error = true;
if (rts_argv[arg][2] == '\0')
RtsFlags.ConcFlags.ctxtSwitchTime = 0;
else {
double intervalSeconds = parseDouble(rts_argv[arg]+2, &error);
if (error) {
errorBelch("bad value for -C");
}
RtsFlags.ConcFlags.ctxtSwitchTime =
fsecondsToTime(atof(rts_argv[arg]+2));
fsecondsToTime(intervalSeconds);
}
break;
......@@ -1348,8 +1364,13 @@ error = true;
// turns off ticks completely
RtsFlags.MiscFlags.tickInterval = 0;
} else {
double intervalSeconds = parseDouble(rts_argv[arg]+2, &error);
if (error) {
errorBelch("bad value for -V");
}
RtsFlags.MiscFlags.tickInterval =
fsecondsToTime(atof(rts_argv[arg]+2));
fsecondsToTime(intervalSeconds);
}
break;
......@@ -1912,6 +1933,35 @@ decodeSize(const char *flag, uint32_t offset, StgWord64 min, StgWord64 max)
return val;
}
/* ----------------------------------------------------------------------------------
* parseDouble: parse a double from a string, setting a flag in case of an error
-------------------------------------------------------------------------------- */
static double
parseDouble(const char *arg, bool *error)
{
char *endptr;
double out;
errno = 0;
out = strtod(arg, &endptr);
if (errno != 0 || endptr == arg) {
*error = true;
return out;
}
while (isspace((unsigned char)*endptr)) {
++endptr;
}
if (*endptr != 0) {
*error = true;
}
return out;
}
#if defined(DEBUG)
static void read_debug_flags(const char* arg)
{
......
main :: IO ()
main = return ()
T17720a: bad value for -i
\ No newline at end of file
T17720b: bad value for -C
\ No newline at end of file
T17720c: bad value for -V
\ No newline at end of file
test('T17720a',
[extra_run_opts('+RTS -ibogus'),
exit_code(1), check_errmsg('bad value for -i'), extra_files(['T17720.hs']),
only_ways(['normal'])],
multimod_compile_and_run,
['T17720', '-rtsopts'])
test('T17720b',
[extra_run_opts('+RTS -Cv'),
exit_code(1), check_errmsg('bad value for -C'), extra_files(['T17720.hs']),
only_ways(['normal'])],
multimod_compile_and_run,
['T17720', '-rtsopts'])
test('T17720c',
[extra_run_opts('+RTS -V3b'),
exit_code(1), check_errmsg('bad value for -V'), extra_files(['T17720.hs']),
only_ways(['normal'])],
multimod_compile_and_run,
['T17720', '-rtsopts'])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment