* [U-Boot] [PATCH] hashtable: Fix length calculation in hexport_r
@ 2018-07-17 18:25 Zubair Lutfullah Kakakhel
2018-07-26 19:54 ` [U-Boot] " Tom Rini
0 siblings, 1 reply; 3+ messages in thread
From: Zubair Lutfullah Kakakhel @ 2018-07-17 18:25 UTC (permalink / raw)
To: u-boot
The length returned by hexport_r has a few redundant characters.
This appears as NULL characters at the end so seems harmless.
Remove the surplus counts in two places
totlen += strlen(ep->key) + 2;
I'm guessing the +2 here is for = and sep char. But there is another
totlen += 2; line that does that.
size = totletn + 1;
Doesn't make sense and isn't justified with any comment.
Signed-off-by: Zubair Lutfullah Kakakhel <zubair@resin.io>
---
lib/hashtable.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 52aab6d..64faa63 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -622,7 +622,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
list[n++] = ep;
- totlen += strlen(ep->key) + 2;
+ totlen += strlen(ep->key);
if (sep == '\0') {
totlen += strlen(ep->data);
@@ -662,7 +662,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
return (-1);
}
} else {
- size = totlen + 1;
+ size = totlen;
}
/* Check if the user provided a buffer */
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] hashtable: Fix length calculation in hexport_r
2018-07-17 18:25 [U-Boot] [PATCH] hashtable: Fix length calculation in hexport_r Zubair Lutfullah Kakakhel
@ 2018-07-26 19:54 ` Tom Rini
0 siblings, 0 replies; 3+ messages in thread
From: Tom Rini @ 2018-07-26 19:54 UTC (permalink / raw)
To: u-boot
On Tue, Jul 17, 2018 at 07:25:38PM +0100, Zubair Lutfullah Kakakhel wrote:
> The length returned by hexport_r has a few redundant characters.
> This appears as NULL characters at the end so seems harmless.
>
> Remove the surplus counts in two places
>
> totlen += strlen(ep->key) + 2;
> I'm guessing the +2 here is for = and sep char. But there is another
> totlen += 2; line that does that.
>
> size = totletn + 1;
> Doesn't make sense and isn't justified with any comment.
>
> Signed-off-by: Zubair Lutfullah Kakakhel <zubair@resin.io>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180726/8893f84e/attachment.sig>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] hashtable: fix length calculation in hexport_r
@ 2018-12-14 9:42 AKASHI Takahiro
0 siblings, 0 replies; 3+ messages in thread
From: AKASHI Takahiro @ 2018-12-14 9:42 UTC (permalink / raw)
To: u-boot
The commit below incorrectly fixed hexport_r();
> size = totlen + 1;
One extra byte is necessary to NULL-terminate a whole buffer, "resp."
Fixes: f1b20acb4a03 ("hashtable: Fix length calculation in hexport_r")
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
lib/hashtable.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 1c48692b69ed..93028ed83b26 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -662,7 +662,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
return (-1);
}
} else {
- size = totlen;
+ size = totlen + 1;
}
/* Check if the user provided a buffer */
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-12-14 9:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-17 18:25 [U-Boot] [PATCH] hashtable: Fix length calculation in hexport_r Zubair Lutfullah Kakakhel
2018-07-26 19:54 ` [U-Boot] " Tom Rini
2018-12-14 9:42 [U-Boot] [PATCH] hashtable: fix " AKASHI Takahiro
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.