summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-08-05 22:34:44 +0100
committerVincent Sanders <vince@kyllikki.org>2016-08-05 22:34:44 +0100
commitafc79d5912a34b4e5471722ffbf1ec0f8459a2a7 (patch)
tree596b5953e278d453435150597d3ff3fcf5286cef /utils
parentf17e88e7098a5b1c817184e6bf59dcc5d9073ae9 (diff)
downloadnetsurf-afc79d5912a34b4e5471722ffbf1ec0f8459a2a7.tar.gz
netsurf-afc79d5912a34b4e5471722ffbf1ec0f8459a2a7.tar.bz2
Improve user option testing and API parameter checking
Diffstat (limited to 'utils')
-rw-r--r--utils/nsoption.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/utils/nsoption.c b/utils/nsoption.c
index 7e7766622..e4354bf3f 100644
--- a/utils/nsoption.c
+++ b/utils/nsoption.c
@@ -583,21 +583,32 @@ nsoption_init(nsoption_set_default_t *set_defaults,
/* exported interface documented in utils/nsoption.h */
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
{
+ nserror res;
+
/* check to see if global table selected */
if (opts == NULL) {
- opts = nsoptions;
+ res = nsoption_free(nsoptions);
+ if (res == NSERROR_OK) {
+ nsoptions = NULL;
+ }
+ } else {
+ res = nsoption_free(opts);
+ }
+ if (res != NSERROR_OK) {
+ return res;
}
-
- nsoption_free(opts);
/* check to see if global table selected */
if (defs == NULL) {
- defs = nsoptions_default;
+ res = nsoption_free(nsoptions_default);
+ if (res == NSERROR_OK) {
+ nsoptions_default = NULL;
+ }
+ } else {
+ res = nsoption_free(defs);
}
- nsoption_free(defs);
-
- return NSERROR_OK;
+ return res;
}
@@ -621,6 +632,10 @@ nsoption_read(const char *path, struct nsoption_s *opts)
/** @todo is this and API bug not being a parameter */
defs = nsoptions_default;
+ if ((opts == NULL) || (defs == NULL)) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
fp = fopen(path, "r");
if (!fp) {
LOG("Failed to open file '%s'", path);
@@ -687,6 +702,10 @@ nsoption_write(const char *path,
defs = nsoptions_default;
}
+ if ((opts == NULL) || (defs == NULL)) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
fp = fopen(path, "w");
if (!fp) {
LOG("failed to open file '%s' for writing", path);
@@ -708,10 +727,13 @@ nsoption_dump(FILE *outf, struct nsoption_s *opts)
return NSERROR_BAD_PARAMETER;
}
- /* check to see if global table selected */
+ /* check to see if global table selected and available */
if (opts == NULL) {
opts = nsoptions;
}
+ if (opts == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
return nsoption_output(outf, opts, NULL, true);
}
@@ -728,10 +750,17 @@ nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
int mv_loop;
unsigned int entry_loop;
- /* check to see if global table selected */
+ if ((pargc == NULL) || (argv == NULL)) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* check to see if global table selected and available */
if (opts == NULL) {
opts = nsoptions;
}
+ if (opts == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
while (idx < *pargc) {
arg = argv[idx];