This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 20017cfe88137de386fdc956f49e0d996779a952
Author: Boris Faure <[email protected]>
AuthorDate: Sun Nov 8 16:10:09 2026 +0000
eina: share single bytes above 0x7f from the right table entry
eina_stringshare_add() returns one-character strings from a static
table indexed by the character. The index was taken from a plain char,
which is signed on most targets, so a byte from 0x80 to 0xff pointed up
to 256 bytes before the table, into whatever read-only data sits there.
The caller then got an unrelated string back, and a later ref or del of
it, being longer than one character, failed the stringshare node magic
check. Terminology hits this when a program sets the window title to a
lone invalid UTF-8 byte.
---
src/lib/eina/eina_stringshare.c | 2 +-
src/tests/eina/eina_test_stringshare.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/lib/eina/eina_stringshare.c b/src/lib/eina/eina_stringshare.c
index 912c5a1530..76da087e87 100644
--- a/src/lib/eina/eina_stringshare.c
+++ b/src/lib/eina/eina_stringshare.c
@@ -584,7 +584,7 @@ eina_stringshare_add_length(const char *str, unsigned int slen)
{
eina_share_common_population_add(stringshare_share, slen);
- return (Eina_Stringshare *) _eina_stringshare_single + ((*str) << 1);
+ return (Eina_Stringshare *) _eina_stringshare_single + (((unsigned char)*str) << 1);
}
else if (slen < 4)
{
diff --git a/src/tests/eina/eina_test_stringshare.c b/src/tests/eina/eina_test_stringshare.c
index d8ea004938..bdbda26dc7 100644
--- a/src/tests/eina/eina_test_stringshare.c
+++ b/src/tests/eina/eina_test_stringshare.c
@@ -130,6 +130,26 @@ EINA_TEST_START(eina_stringshare_small)
}
EINA_TEST_END
+EINA_TEST_START(eina_stringshare_single_byte)
+{
+ char buf[2] = { 0, 0 };
+ int c;
+
+ for (c = 1; c < 256; c++)
+ {
+ const char *t0;
+
+ buf[0] = (char)c;
+ t0 = eina_stringshare_add(buf);
+ fail_if(t0 == NULL);
+ fail_if(strcmp(t0, buf) != 0);
+ fail_if(t0 != eina_stringshare_add_length(buf, 1));
+ eina_stringshare_del(t0);
+ eina_stringshare_del(t0);
+ }
+}
+EINA_TEST_END
+
EINA_TEST_START(eina_stringshare_test_share)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.