Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
7894f59ad7
!74 [sync] PR-73: Minor fix in the compatibility library
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2023-03-22 01:26:52 +00:00
wangzhiqiang
4bd3e38227 Minor fix in the compatibility library.
Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
(cherry picked from commit c5fa3c54ad925d72ccaa47c63e03f40bd711db56)
2023-03-20 19:54:51 +08:00
openeuler-ci-bot
1798855b33
!61 [sync] PR-60: sync branch master
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-07-05 13:18:12 +00:00
wangzhiqiang
f549c60ebc sync branch master
fix semantics of gdbm_load -r. improve handling of -u in gdbm_load

Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
(cherry picked from commit 6749d2328d0262ec4f47611116a3c384758c7218)
2022-07-05 20:57:22 +08:00
openeuler-ci-bot
2defeb2242
!53 [sync] PR-49: Fix location tracking in gdbmtool. Fix the recover command
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-06-28 08:48:55 +00:00
wangzhiqiang
2325ca23d6 Fix location tracking in gdbmtool. Fix the recover command
Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
(cherry picked from commit 09b9806f80585dac73fba6d640574c3d1eb7174f)
2022-06-28 16:19:37 +08:00
openeuler-ci-bot
f4822c45eb
!46 gdbm_dump fix command line error detection
From: @yanxiaodan 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-06-24 13:23:50 +00:00
yanxiaodan
d09822df15
update gdbm.spec. 2022-06-24 12:58:48 +00:00
yanxiaodan
339e1adf84
update gdbm.spec. 2022-06-24 12:52:34 +00:00
yanxiaodan
9be8961013
gdbm_dump fix command line error detection 2022-06-24 12:51:32 +00:00
6 changed files with 791 additions and 2 deletions

View File

@ -0,0 +1,453 @@
From b8271d89db991558e10c26d45d960bbc0257fa31 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Sat, 18 Jun 2022 17:18:05 +0300
Subject: [PATCH] Fix location tracking in gdbmtool. Fix the recover command.
In particular, this addresses https://puszcza.gnu.org.ua/bugs/?566
* src/gdbmtool.c: Fix parameter parsing failure
(recover_handler): Accept varargs
(command_tab): Use argdoc to provide help for varargs
(help_handler): Handle argdoc
* src/gram.y: Accept a single unadorned key=value pair as argument.
Conflict: Fix only the part that caused the problem
Origin Patch: https://git.gnu.org.ua/gdbm.git/commit/?id=b8271d89db991558e10c26d45d960bbc0257fa31
---
src/gdbmtool.c | 178 +++++++++++++++++++++++++++++++++++++++------------------
src/gram.y | 8 +++
2 files changed, 131 insertions(+), 55 deletions(-)
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index 03ba482..cdfe61d 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -579,64 +579,98 @@ recover_handler (struct handler_param *param)
gdbm_recovery rcvr;
int flags = 0;
int rc;
- int i;
char *p;
int summary = 0;
- for (i = 0; i < param->argc; i++)
+ if (param->vararg)
{
- char *arg = PARAM_STRING (param, i);
- if (strcmp (arg, "verbose") == 0)
- {
- rcvr.errfun = err_printer;
- flags |= GDBM_RCVR_ERRFUN;
- }
- else if (strcmp (arg, "force") == 0)
- {
- flags |= GDBM_RCVR_FORCE;
- }
- else if (strcmp (arg, "summary") == 0)
- {
- summary = 1;
- }
- else if (strcmp (arg, "backup") == 0)
- {
- flags |= GDBM_RCVR_BACKUP;
- }
- else if (strncmp (arg, "max-failures=", 13) == 0)
+ struct gdbmarg *arg;
+ int i;
+
+ for (arg = param->vararg, i = 0; arg; arg = arg->next, i++)
{
- rcvr.max_failures = strtoul (arg + 13, &p, 10);
- if (*p)
+ if (arg->type == GDBM_ARG_STRING)
{
- printf (_("not a number (stopped near %s)\n"), p);
- return;
+ if (strcmp(arg->v.string, "verbose") == 0)
+ {
+ rcvr.errfun = err_printer;
+ flags |= GDBM_RCVR_ERRFUN;
+ }
+ else if (strcmp (arg->v.string, "force") == 0)
+ {
+ flags |= GDBM_RCVR_FORCE;
+ }
+ else if (strcmp (arg->v.string, "summary") == 0)
+ {
+ summary = 1;
+ }
+ else if (strcmp (arg->v.string, "backup") == 0)
+ {
+ flags |= GDBM_RCVR_BACKUP;
+ }
+ else
+ {
+ lerror (&arg->loc, _("unrecognized argument: %s"), arg->v.string);
+ return;
+ }
}
- flags |= GDBM_RCVR_MAX_FAILURES;
- }
- else if (strncmp (arg, "max-failed-keys=", 16) == 0)
- {
- rcvr.max_failed_keys = strtoul (arg + 16, &p, 10);
- if (*p)
+ else if (arg->type == GDBM_ARG_KVPAIR)
{
- printf (_("not a number (stopped near %s)\n"), p);
- return;
+ if (arg->v.kvpair->type != KV_STRING)
+ {
+ lerror (&arg->loc, _("%s: bad argument type"), arg->v.kvpair->key);
+ return;
+ }
+ else if (arg->v.kvpair->next)
+ {
+ lerror (&arg->loc, _("unexpected compound statement"));
+ return;
+ }
+
+ if (strcmp (arg->v.kvpair->key, "max-failures") == 0)
+ {
+ rcvr.max_failures = strtoul (arg->v.kvpair->val.s, &p, 10);
+
+ if (*p)
+ {
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
+ return;
+ }
+ flags |= GDBM_RCVR_MAX_FAILURES;
+ }
+ else if (strcmp (arg->v.kvpair->key, "max-failed-keys") == 0)
+ {
+ rcvr.max_failed_keys = strtoul (arg->v.kvpair->val.s, &p, 10);
+
+ if (*p)
+ {
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
+ return;
+ }
+ flags |= GDBM_RCVR_MAX_FAILED_KEYS;
+ }
+ else if (strcmp (arg->v.kvpair->key, "max-failed-buckets") == 0)
+ {
+ rcvr.max_failures = strtoul (arg->v.kvpair->val.s, &p, 10);
+
+ if (*p)
+ {
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
+ return;
+ }
+ flags |= GDBM_RCVR_MAX_FAILED_BUCKETS;
+ }
+ else
+ {
+ lerror (&arg->loc, _("unrecognized argument: %s"), arg->v.kvpair->key);
+ return;
+ }
}
- flags |= GDBM_RCVR_MAX_FAILED_KEYS;
- }
- else if (strncmp (arg, "max-failed-buckets=", 19) == 0)
- {
- rcvr.max_failures = strtoul (arg + 19, &p, 10);
- if (*p)
+ else
{
- printf (_("not a number (stopped near %s)\n"), p);
+ lerror (&arg->loc, _("unexpected datum"));
return;
}
- flags |= GDBM_RCVR_MAX_FAILED_BUCKETS;
- }
- else
- {
- terror (_("unrecognized argument: %s"), arg);
- return;
}
}
@@ -1184,6 +1218,7 @@ struct command
void (*handler) (struct handler_param *param);
void (*end) (void *data);
struct argdef args[NARGS];
+ char *argdoc[NARGS];
int variadic;
enum command_repeat_type repeat;
char *doc;
@@ -1194,12 +1229,14 @@ struct command command_tab[] = {
{ S(count), T_CMD,
checkdb_begin, count_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("count (number of entries)") },
{ S(delete), T_CMD,
checkdb_begin, delete_handler, NULL,
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("delete a record") },
@@ -1209,12 +1246,14 @@ struct command command_tab[] = {
{ "[truncate]", GDBM_ARG_STRING },
{ "[binary|ascii]", GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("export") },
{ S(fetch), T_CMD,
checkdb_begin, fetch_handler, NULL,
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("fetch record") },
@@ -1224,12 +1263,14 @@ struct command command_tab[] = {
{ "[replace]", GDBM_ARG_STRING },
{ "[nometa]" , GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
FALSE,
N_("import") },
{ S(list), T_CMD,
list_begin, list_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("list") },
@@ -1237,6 +1278,7 @@ struct command command_tab[] = {
checkdb_begin, nextkey_handler, NULL,
{ { N_("[KEY]"), GDBM_ARG_DATUM, DS_KEY },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NOARG,
N_("nextkey") },
@@ -1245,37 +1287,42 @@ struct command command_tab[] = {
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
{ N_("DATA"), GDBM_ARG_DATUM, DS_CONTENT },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("store") },
{ S(first), T_CMD,
checkdb_begin, firstkey_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("firstkey") },
{ S(reorganize), T_CMD,
checkdb_begin, reorganize_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("reorganize") },
{ S(recover), T_CMD,
checkdb_begin, recover_handler, NULL,
- { { "[verbose]", GDBM_ARG_STRING },
- { "[summary]", GDBM_ARG_STRING },
- { "[backup]", GDBM_ARG_STRING },
- { "[force]", GDBM_ARG_STRING },
- { "[max-failed-keys=N]", GDBM_ARG_STRING },
- { "[max-failed-buckets=N]", GDBM_ARG_STRING },
- { "[max-failures=N]", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
+ { { NULL } },
+ { "[verbose]",
+ "[summary]",
+ "[backup]",
+ "[force]",
+ "[max-failed-keys=N]",
+ "[max-failed-buckets=N]",
+ "[max-failures=N]",
+ NULL },
+ TRUE,
REPEAT_NEVER,
N_("recover the database") },
{ S(avail), T_CMD,
avail_begin, avail_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print avail list") },
@@ -1283,24 +1330,28 @@ struct command command_tab[] = {
print_bucket_begin, print_current_bucket_handler, NULL,
{ { N_("NUMBER"), GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print a bucket") },
{ S(current), T_CMD,
print_current_bucket_begin, print_current_bucket_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print current bucket") },
{ S(dir), T_CMD,
print_dir_begin, print_dir_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print hash directory") },
{ S(header), T_CMD,
print_header_begin , print_header_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print database file header") },
@@ -1308,48 +1359,56 @@ struct command command_tab[] = {
NULL, hash_handler, NULL,
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("hash value of key") },
{ S(cache), T_CMD,
print_cache_begin, print_cache_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print the bucket cache") },
{ S(status), T_CMD,
NULL, status_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print current program status") },
{ S(version), T_CMD,
NULL, print_version_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print version of gdbm") },
{ S(help), T_CMD,
help_begin, help_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("print this help list") },
{ S(quit), T_CMD,
NULL, quit_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("quit the program") },
{ S(set), T_SET,
NULL, NULL, NULL,
{ { "[VAR=VALUE...]" }, { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("set or list variables") },
{ S(unset), T_UNSET,
NULL, NULL, NULL,
{ { "VAR..." }, { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("unset variables") },
@@ -1358,6 +1417,7 @@ struct command command_tab[] = {
{ { "key|content", GDBM_ARG_STRING },
{ "{ FIELD-LIST }", GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("define datum structure") },
@@ -1365,18 +1425,21 @@ struct command command_tab[] = {
NULL, source_handler, NULL,
{ { "FILE", GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("source command script") },
{ S(close), T_CMD,
NULL, close_handler, NULL,
{ { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("close the database") },
{ S(open), T_CMD,
NULL, open_handler, NULL,
{ { "FILE", GDBM_ARG_STRING }, { NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("open new database") },
@@ -1386,6 +1449,7 @@ struct command command_tab[] = {
{ { N_("[FROM]"), GDBM_ARG_STRING },
{ N_("[COUNT]"), GDBM_ARG_STRING },
{ NULL } },
+ { NULL },
FALSE,
REPEAT_NEVER,
N_("show input history") },
@@ -1393,6 +1457,7 @@ struct command command_tab[] = {
{ S(debug), T_CMD,
NULL, debug_handler, NULL,
{ { NULL } },
+ { NULL },
TRUE,
REPEAT_NEVER,
N_("query/set debug level") },
@@ -1476,6 +1541,9 @@ help_handler (struct handler_param *param)
for (i = 0; i < NARGS && cmd->args[i].name; i++)
n += fprintf (fp, " %s", gettext (cmd->args[i].name));
+ for (i = 0; i < NARGS && cmd->argdoc[i]; i++)
+ n += fprintf (fp, " %s", gettext (cmd->argdoc[i]));
+
if (n < CMDCOLS)
fprintf (fp, "%*.s", CMDCOLS-n, "");
fprintf (fp, " %s", gettext (cmd->doc));
diff --git a/src/gram.y b/src/gram.y
index 6c79c7a..a389f48 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -130,6 +130,13 @@ arg : string
{
$$ = gdbmarg_string ($1, &@1);
}
+ | T_IDENT '=' string
+ {
+ struct locus loc = { .beg = @1.beg, .end = @3.end };
+ struct kvpair *kvp = kvpair_string (&loc, $3);
+ kvp->key = $1;
+ $$ = gdbmarg_kvpair (kvp, &loc);
+ }
| compound
{
$$ = gdbmarg_kvpair ($1, &@1);
@@ -158,6 +165,7 @@ kvpair : value
| T_IDENT '=' value
{
$3->key = $1;
+ $3->loc.beg = @1.beg;
$$ = $3;
}
;
--
1.8.3.1

View File

@ -0,0 +1,109 @@
From 0591202918948d41e331094b283ff699ab916c54 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Fri, 1 Jul 2022 14:03:22 +0300
Subject: [PATCH] Fix semantics of gdbm_load -r
Fixes https://puszcza.gnu.org.ua/bugs/index.php?573
* src/gdbm_load.c: New option: --update (-U)
The --replace (-r) option is valid only if used together with
--update.
* doc/gdbm.texi: Document changes.
---
doc/gdbm.texi | 23 ++++++++++++++++++++---
src/gdbm_load.c | 18 +++++++++++++++++-
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index 4a0b1a7..f1e23ba 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -2772,9 +2772,17 @@ must be given as the second argument.
In general, if two arguments are given the second one is treated as
the name of the database to create, overriding the file name specified
-in the flat file.
+in the flat file. All existing keys will be removed from this
+database prior to loading from the dump. Use the @option{--update}
+(@option{-U}) option if it is not what you wish.
-The utility understands the following command line arguments:
+When given the @option{--update} (@option{-U}) option,
+@command{gdbm_load} will update the existing database with the data
+from the dump. It will bail out if the dump contains a key that is
+already present in the database. To silently overwrite existing keys,
+use the @option{--replace} (@option{-r}) option.
+
+The utility understands the following command line options:
@table @option
@@ -2800,7 +2808,16 @@ Do not restore file meta-data (ownership and mode) from the flat file.
@item -r
@itemx --replace
-Replace existing keys.
+Replace existing keys. This option can be used only together with
+@option{--update} (@option{-U}).
+
+@item -U
+@itemx --update
+Update an existing database. The database name must be given in the
+second argument to @command{gdbm_load}. The key/value pairs from the
+dump file will be added to that database, without removing the
+existing keys. To overwrite the existing keys from the dump file, use
+@option{--update --replace}.
@item -u @var{user}[:@var{group}]
@itemx --user=@var{user}[:@var{group}]
diff --git a/src/gdbm_load.c b/src/gdbm_load.c
index 2d96ada..dd5cdc5 100644
--- a/src/gdbm_load.c
+++ b/src/gdbm_load.c
@@ -32,8 +32,9 @@ gid_t owner_gid;
char *parseopt_program_doc = "load a GDBM database from a file";
char *parseopt_program_args = "FILE [DB_FILE]";
struct gdbm_option optab[] = {
- { 'r', "replace", NULL, N_("replace records in the existing database") },
+ { 'r', "replace", NULL, N_("replace records in the existing database (needs -U)") },
{ 'm', "mode", N_("MODE"), N_("set file mode") },
+ { 'U', "update", NULL, N_("update the existing database") },
{ 'u', "user", N_("NAME|UID[:NAME|GID]"), N_("set file owner") },
{ 'n', "no-meta", NULL, N_("do not attempt to set file meta-data") },
{ 'M', "mmap", NULL, N_("use memory mapping") },
@@ -139,6 +140,10 @@ main (int argc, char **argv)
}
break;
+ case 'U':
+ oflags = (oflags & ~GDBM_OPENMASK) | GDBM_WRCREAT;
+ break;
+
case 'u':
{
size_t len;
@@ -231,10 +236,21 @@ main (int argc, char **argv)
error (_("too many arguments; try `%s -h' for more info"), progname);
exit (EXIT_USAGE);
}
+
+ if (replace && (oflags & GDBM_OPENMASK) != GDBM_WRCREAT)
+ {
+ error (_("-r is useless without -U"));
+ exit (EXIT_USAGE);
+ }
filename = argv[0];
if (argc == 2)
dbname = argv[1];
+ else if (oflags & GDBM_WRCREAT)
+ {
+ error (_("-U requires DB_FILE to be supplied"));
+ exit (EXIT_USAGE);
+ }
else
dbname = NULL;
--
1.8.3.1

View File

@ -0,0 +1,78 @@
From 4cfdc68fd862a4e80f42f14aa92cb25db08b2466 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Sat, 2 Jul 2022 19:29:47 +0300
Subject: [PATCH] Improve handling of -u in gdbm_load
* src/gdbm_load.c (main): Imply the owner login group if owner name
is followed by a :, and the current login group otherwise.
* doc/gdbm.texi: Document changes.
---
doc/gdbm.texi | 13 ++++++++-----
src/gdbm_load.c | 9 +++++++--
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index f1e23ba..f954212 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -2819,13 +2819,16 @@ dump file will be added to that database, without removing the
existing keys. To overwrite the existing keys from the dump file, use
@option{--update --replace}.
-@item -u @var{user}[:@var{group}]
-@itemx --user=@var{user}[:@var{group}]
-Set file owner. The @var{user} can be either a valid user name or
+@item -u @var{owner}[:[@var{group}]]
+@itemx --user=@var{owner}[:[@var{group}]]
+Set file owner. The @var{owner} can be either a valid user name or
UID. Similarly, the @var{group} is either a valid group name or GID.
-If @var{group} is not given, the main group of @var{user} is used.
+If @var{group} is not given, the main group of @var{owner} is implied, if
+@var{owner} is followed by a @samp{:}, otherwise the login group of the
+current user is implied.
-User and group parts can be separated by a dot, instead of the colon.
+User and group parts can be separated by a dot, instead of the colon,
+but such usage is discouraged.
@item -h
@itemx --help
diff --git a/src/gdbm_load.c b/src/gdbm_load.c
index dd5cdc5..028134b 100644
--- a/src/gdbm_load.c
+++ b/src/gdbm_load.c
@@ -148,9 +148,10 @@ main (int argc, char **argv)
{
size_t len;
struct passwd *pw;
+ int delim;
len = strcspn (optarg, ".:");
- if (optarg[len])
+ if ((delim = optarg[len]) != 0)
optarg[len++] = 0;
pw = getpwnam (optarg);
if (pw)
@@ -187,7 +188,7 @@ main (int argc, char **argv)
}
}
}
- else
+ else if (delim)
{
if (!pw)
{
@@ -200,6 +201,10 @@ main (int argc, char **argv)
}
owner_gid = pw->pw_gid;
}
+ else
+ {
+ owner_gid = getgid();
+ }
meta_mask |= GDBM_META_MASK_OWNER;
}
break;
--
1.8.3.1

View File

@ -0,0 +1,60 @@
From 3e63a788d4c7b5cb1173937118135c2bcca35a02 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Fri, 3 Mar 2023 13:52:56 +0200
Subject: [PATCH] Minor fix in the compatibility library.
* compat/dbmopen.c (ndbm_open_dir_file0): Don't try to unlink
the 1.8-compatible dir file or create a missing one if the database
is being opened read-only.
---
compat/dbmopen.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index b11af98..cb979b5 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -81,12 +81,21 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
{
if (st.st_dev == pagst.st_dev && st.st_ino == pagst.st_ino)
{
- if (unlink (file_name))
+ if (flags == O_RDONLY)
{
- if ((mode & GDBM_OPENMASK) == GDBM_READER)
- /* Ok, try to cope with it. */
- return pagfd;
- else if (errno != ENOENT)
+ /*
+ * Don't touch the link if the database is opened read-only.
+ * Return a meaningful file descriptor for the sake
+ * of those programs that compare it with pagfd trying
+ * to detect old GDBM versions (as Sendmail does).
+ */
+ if ((fd = open ("/dev/null", flags)) == -1)
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, TRUE);
+ return fd;
+ }
+ else if (unlink (file_name))
+ {
+ if (errno != ENOENT)
{
gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, TRUE);
return -1;
@@ -138,6 +147,13 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
return -1;
}
}
+ else if (flags == O_RDONLY)
+ {
+ /* See the comment above. */
+ if ((fd = open ("/dev/null", flags)) == -1)
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, TRUE);
+ return fd;
+ }
/* File does not exist. Create it. */
fd = open (file_name, flags | O_CREAT, pagst.st_mode & 0777);
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: gdbm
Version: 1.18.1
Release: 4
Release: 8
Epoch: 1
Summary: A library of database functions that work similar to the standard UNIX dbm
License: GPLv3+
@ -9,8 +9,13 @@ Source0: http://ftp.gnu.org/gnu/gdbm/gdbm-%{version}.tar.gz
Patch0: 0000-Fix-gdbmtool-import-command.patch
Patch1: 0001-fix-gdbm_dump-usage-stack-overflow.patch
Patch2: gdbm_dump-fix-command-line-error-detection.patch
Patch3: 0002-Fix-location-tracking-in-gdbmtool.-Fix-the-recover-c.patch
Patch4: 0003-Fix-semantics-of-gdbm_load-r.patch
Patch5: 0004-Improve-handling-of-u-in-gdbm_load.patch
Patch6: Minor-fix-in-the-compatibility-library.patch
BuildRequires: gcc libtool gettext readline-devel git
BuildRequires: gcc libtool gettext readline-devel git bison flex texinfo
Provides: %{name}-libs
Provides: %{name}-libs%{?_isa}
@ -100,6 +105,18 @@ fi
%{_infodir}/*.info*
%changelog
* Mon Mar 20 2023 wangzhiqiang <wangzhiqiang95@huawei.com> - 1:1.18.1-8
- Minor fix in the compatibility library
* Tue Jul 5 2022 wangzhiqiang <wangzhiqiang95@huawei.com> - 1:1.18.1-7
- fix semantics of gdbm_load -r. improve handling of -u in gdbm_load
* Mon Jun 27 2022 wangzhiqiang <wangzhiqiang95@huawei.com> - 1:1.18.1-6
- Fix location tracking in gdbmtool. Fix the recover command
* Fri Jun 24 2022 yanxiaodan <yanxiaodan@huawei.com> - 1:1.18.1-5
- gdbm_dump-fix-command-line-error-detection
* Wed Mar 02 2022 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 1.18.1-4
- Fix stack overflow in print_usage

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