summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2022-06-20 11:50:46 +0300
committerSergey Poznyakoff <gray@gnu.org>2022-06-20 11:50:46 +0300
commitc96c160375bd1f3861651311e8645fb6478a1ffd (patch)
tree56d154f2b3874a45519aa8571cca2bf704214695
parentc3dc7294670c91af89e0122c6979de70c63ce4f7 (diff)
downloadgdbm-c96c160375bd1f3861651311e8645fb6478a1ffd.tar.gz
gdbm_dump: fix command line error detection
This fixes https://puszcza.gnu.org.ua/bugs/?567
-rw-r--r--tools/gdbm_dump.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/tools/gdbm_dump.c b/tools/gdbm_dump.c
index a480152..2f37eac 100644
--- a/tools/gdbm_dump.c
+++ b/tools/gdbm_dump.c
@@ -57,19 +57,31 @@ main (int argc, char **argv)
format = GDBM_DUMP_FMT_ASCII;
else
{
- format = atoi (optarg);
- switch (format)
+ char *p;
+ unsigned long n;
+
+ errno = 0;
+ n = strtoul (optarg, &p, 10);
+ if (errno || *p != 0)
+ {
+ error (_("unknown dump format"));
+ exit (EXIT_USAGE);
+ }
+
+ switch (n)
{
case GDBM_DUMP_FMT_BINARY:
case GDBM_DUMP_FMT_ASCII:
+ format = n;
break;
+
default:
error (_("unknown dump format"));
exit (EXIT_USAGE);
}
}
break;
-
+
default:
error (_("unknown option"));
exit (EXIT_USAGE);
@@ -90,7 +102,7 @@ main (int argc, char **argv)
error (_("too many arguments; try `%s -h' for more info"), progname);
exit (EXIT_USAGE);
}
-
+
dbname = argv[0];
if (argc == 2)
filename = argv[1];
@@ -124,9 +136,8 @@ main (int argc, char **argv)
{
gdbm_perror (_("dump error"), filename);
}
-
+
gdbm_close (dbf);
exit (rc == GDBM_NO_ERROR ? EXIT_OK : EXIT_FATAL);
}
-