!39 gdbm_dump fix command line error detection

From: @foolstrong 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
This commit is contained in:
openeuler-ci-bot 2022-06-23 02:56:41 +00:00 committed by Gitee
commit c3301ea818
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 78 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Name: gdbm
Version: 1.22
Release: 4
Release: 5
Epoch: 1
Summary: A library of database functions that work similar to the standard UNIX dbm
License: GPLv3+
@ -8,7 +8,8 @@ URL: http://www.gnu.org/software/gdbm/
Source0: http://ftp.gnu.org/gnu/gdbm/gdbm-%{version}.tar.gz
Patch0: Fix-gdbmtool-import-command.patch
Patch1: Fix-binary-dump-format-for-key-and-or-data-of-zero-s.patch
Patch1: Fix-binary-dump-format-for-key-and-or-data-of-zero-s.patch
Patch2: gdbm_dump-fix-command-line-error-detection.patch
BuildRequires: gcc libtool gettext readline-devel
@ -100,6 +101,9 @@ fi
%{_infodir}/*.info*
%changelog
* Wed Jun 22 2022 wangzhqiang <wangzhiqiang95@huawei.com> - 1:1.22-5
- DESC: gdbm_dump-fix-command-line-error-detection
* Fri Jun 17 2022 wangzhiqiang <wangzhiqiang95@huawei.com> - 1:1.22-4
- DESC: Fix binary dump format for key and or data of zero size

View File

@ -0,0 +1,72 @@
From c96c160375bd1f3861651311e8645fb6478a1ffd Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Mon, 20 Jun 2022 11:50:46 +0300
Subject: [PATCH] gdbm_dump: fix command line error detection
This fixes https://puszcza.gnu.org.ua/bugs/?567
---
src/gdbm_dump.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/gdbm_dump.c b/src/gdbm_dump.c
index a480152..2f37eac 100644
--- a/src/gdbm_dump.c
+++ b/src/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);
}
-
--
1.8.3.1