Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] [PATCH] zsh/db/gdbm does unnecessary "+1" to strlen()
- X-seq: zsh-workers 40507
- From: Sebastian Gniazdowski <psprint2@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [BUG] [PATCH] zsh/db/gdbm does unnecessary "+1" to strlen()
- Date: Mon, 06 Feb 2017 15:46:11 -0800
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= mesmtp; bh=BQd7TwlePOSiMq8F7ItYUQxfbiA=; b=xVKKI6hybDawo9ekOUAqq NMC4T/7HdoPo58voKYdjhojtAMR0J0BxMYQZkc6T+mp76Tf7GgaK6XZ/Lb+yUcSy ReSOFVyvZGc3eFXMfyuJKxClggex5gEd4avVBTyFmEZhwMzegPrLE8t236vPytV+ 4Obf+kmjKuP93MLJfm+pmw=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=smtpout; bh=BQd7TwlePOSiMq8F7ItYUQxfb iA=; b=CQ27zQMbhA9+sxkYbVw3XUpA8zkeDM9lCfwmzGMGAwwRCF6O007cT+PeG 9k/5UXMsAYVMaaEcMZNtcliMNR+kZlTBPx1+lIeGiv6mhvDzsxElZYeqxAbcYoJm /3A8ilzbke1GA+fHZt91NSTmDdQRmFeiZLxCtjDQPG9EA+bjlo=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello
If I create gdbm hash and key:
ztie -d db/gdbm -f database.zsh mybase
mybase[xyz]=1
then gdbmtool shows:
gdbmtool> list
xyz\000 1\000
Creating such entry via gdbmtool itself doesn't result in the "\000" at
the end.
The patch removes buffer overruns that cause that. It's "+ 1" to data
length when storing, retrieving. That's why it's not possible to
retrieve key "abc" from Zsh if it's created in gdbmtool, etc.
I've recorded both good and bad symptoms on Asciinema. QUALITY
recording, really, almost no mistake, 1:21 sec:
https://asciinema.org/a/5smfk0hdviy8nien4n75isj4a
MORE: unpatched gdbm module **sucks environment, widgets into the
database** (29 sec):
https://asciinema.org/a/12ffm5ltpj9udnmradtat17am
Here is my attempt on pasting the patch, hopefully Fastmail won't break
whitespaces. Also attached.
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 8dd60fc..310e329 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -170,7 +170,7 @@ gdbmgetfn(Param pm)
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
ret = gdbm_exists(dbf, key);
@@ -191,9 +191,9 @@ gdbmsetfn(Param pm, char *val)
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
content.dptr = val;
- content.dsize = strlen(content.dptr) + 1;
+ content.dsize = strlen(content.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
(void)gdbm_store(dbf, key, content, GDBM_REPLACE);
@@ -207,7 +207,7 @@ gdbmunsetfn(Param pm, UNUSED(int um))
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
(void)gdbm_delete(dbf, key);
@@ -302,12 +302,12 @@ gdbmhashsetfn(Param pm, HashTable ht)
v.pm = (Param) hn;
key.dptr = v.pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
queue_signals();
content.dptr = getstrvalue(&v);
- content.dsize = strlen(content.dptr) + 1;
+ content.dsize = strlen(content.dptr);
(void)gdbm_store(dbf, key, content, GDBM_REPLACE);
--
Sebastian Gniazdowski
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 8dd60fc..310e329 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -170,7 +170,7 @@ gdbmgetfn(Param pm)
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
ret = gdbm_exists(dbf, key);
@@ -191,9 +191,9 @@ gdbmsetfn(Param pm, char *val)
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
content.dptr = val;
- content.dsize = strlen(content.dptr) + 1;
+ content.dsize = strlen(content.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
(void)gdbm_store(dbf, key, content, GDBM_REPLACE);
@@ -207,7 +207,7 @@ gdbmunsetfn(Param pm, UNUSED(int um))
GDBM_FILE dbf;
key.dptr = pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
(void)gdbm_delete(dbf, key);
@@ -302,12 +302,12 @@ gdbmhashsetfn(Param pm, HashTable ht)
v.pm = (Param) hn;
key.dptr = v.pm->node.nam;
- key.dsize = strlen(key.dptr) + 1;
+ key.dsize = strlen(key.dptr);
queue_signals();
content.dptr = getstrvalue(&v);
- content.dsize = strlen(content.dptr) + 1;
+ content.dsize = strlen(content.dptr);
(void)gdbm_store(dbf, key, content, GDBM_REPLACE);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author