summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-08-16 11:37:10 -0400
committerFranklin Wei <git@fwei.tk>2017-08-16 11:40:42 -0400
commitf31a400bac0b72e773e32d2a17ac839145dded2b (patch)
treedc812d909b41fe51870b568cc5e4cb2315b95c7c
parentc78ff7f6153d2a787bfd8cb3410dff8db74b2789 (diff)
downloadrockbox-f31a400bac0b72e773e32d2a17ac839145dded2b.tar.gz
rockbox-f31a400bac0b72e773e32d2a17ac839145dded2b.zip
puzzles: add more parameter validation checks
Fixes some annoying crashes. Change-Id: If3c293bd90e301c3e697d1e5fcb1b0aa2ea320fb
-rw-r--r--apps/plugins/puzzles/src/blackbox.c2
-rw-r--r--apps/plugins/puzzles/src/flood.c4
-rw-r--r--apps/plugins/puzzles/src/mines.c2
-rw-r--r--apps/plugins/puzzles/src/netslide.c2
-rw-r--r--apps/plugins/puzzles/src/pattern.c2
-rw-r--r--apps/plugins/puzzles/src/sixteen.c3
-rw-r--r--apps/plugins/puzzles/src/twiddle.c2
7 files changed, 15 insertions, 2 deletions
diff --git a/apps/plugins/puzzles/src/blackbox.c b/apps/plugins/puzzles/src/blackbox.c
index b334cf7117..192b7f11b6 100644
--- a/apps/plugins/puzzles/src/blackbox.c
+++ b/apps/plugins/puzzles/src/blackbox.c
@@ -200,6 +200,8 @@ static char *validate_params(const game_params *params, int full)
return "Minimum number of balls may not be greater than maximum";
if (params->minballs >= params->w * params->h)
return "Too many balls to fit in grid";
+ if (params->minballs < 1)
+ return "Number of balls must be at least one";
return NULL;
}
diff --git a/apps/plugins/puzzles/src/flood.c b/apps/plugins/puzzles/src/flood.c
index 1262be8175..59e160cfc3 100644
--- a/apps/plugins/puzzles/src/flood.c
+++ b/apps/plugins/puzzles/src/flood.c
@@ -213,8 +213,10 @@ static game_params *custom_params(const config_item *cfg)
static char *validate_params(const game_params *params, int full)
{
- if (params->w < 2 && params->h < 2)
+ if (params->w * params->h < 2)
return "Grid must contain at least two squares";
+ if (params->w < 1 || params->h < 1)
+ return "Width and height must both be at least one";
if (params->colours < 3 || params->colours > 10)
return "Must have between 3 and 10 colours";
if (params->leniency < 0)
diff --git a/apps/plugins/puzzles/src/mines.c b/apps/plugins/puzzles/src/mines.c
index 3bfe832a5f..4bee0f3157 100644
--- a/apps/plugins/puzzles/src/mines.c
+++ b/apps/plugins/puzzles/src/mines.c
@@ -265,6 +265,8 @@ static char *validate_params(const game_params *params, int full)
return "Width and height must both be greater than two";
if (params->n > params->w * params->h - 9)
return "Too many mines for grid size";
+ if (params->n < 1)
+ return "Number of mines must be greater than zero";
/*
* FIXME: Need more constraints here. Not sure what the
diff --git a/apps/plugins/puzzles/src/netslide.c b/apps/plugins/puzzles/src/netslide.c
index 663febc61a..96ac8e7eea 100644
--- a/apps/plugins/puzzles/src/netslide.c
+++ b/apps/plugins/puzzles/src/netslide.c
@@ -320,6 +320,8 @@ static char *validate_params(const game_params *params, int full)
return "Barrier probability may not be negative";
if (params->barrier_probability > 1)
return "Barrier probability may not be greater than 1";
+ if (params->movetarget < 0)
+ return "Number of shuffling moves may not be negative";
return NULL;
}
diff --git a/apps/plugins/puzzles/src/pattern.c b/apps/plugins/puzzles/src/pattern.c
index 9a74e55318..15cdd281c9 100644
--- a/apps/plugins/puzzles/src/pattern.c
+++ b/apps/plugins/puzzles/src/pattern.c
@@ -179,6 +179,8 @@ static char *validate_params(const game_params *params, int full)
{
if (params->w <= 0 || params->h <= 0)
return "Width and height must both be greater than zero";
+ if (params->w * params->w < 2)
+ return "Grid must contain at least two squares";
return NULL;
}
diff --git a/apps/plugins/puzzles/src/sixteen.c b/apps/plugins/puzzles/src/sixteen.c
index edc9771867..aaf524a0d6 100644
--- a/apps/plugins/puzzles/src/sixteen.c
+++ b/apps/plugins/puzzles/src/sixteen.c
@@ -178,7 +178,8 @@ static char *validate_params(const game_params *params, int full)
{
if (params->w < 2 || params->h < 2)
return "Width and height must both be at least two";
-
+ if (params->movetarget < 0)
+ return "Number of shuffling moves may not be negative";
return NULL;
}
diff --git a/apps/plugins/puzzles/src/twiddle.c b/apps/plugins/puzzles/src/twiddle.c
index 6e05f4ddec..224c0418f1 100644
--- a/apps/plugins/puzzles/src/twiddle.c
+++ b/apps/plugins/puzzles/src/twiddle.c
@@ -217,6 +217,8 @@ static char *validate_params(const game_params *params, int full)
return "Width must be at least the rotating block size";
if (params->h < params->n)
return "Height must be at least the rotating block size";
+ if (params->movetarget < 0)
+ return "Number of shuffling moves may not be negative";
return NULL;
}