Skip to content

Commit 234be02

Browse files
uli42sunweaver
authored andcommittedJun 22, 2019
glyph.c: fix a read beyond end of heap buffer
If compiled with -fsanitize=address this showed up when running startlxde: ==11551==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60d000018fbc at pc 0x7f270a9ed57b bp 0x7fff30ef3050 sp 0x7fff30ef2800 READ of size 204 at 0x60d000018fbc thread T0 #0 0x7f270a9ed57a (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xb857a) #1 0x559dafcd5c93 in FindGlyphRef ../../render/glyph.c:179 #2 0x559dafcd705d in AddGlyph /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c:71 #3 0x559dafccc0ff in ProcRenderAddGlyphs ../../mi/../render/render.c:1186 #4 0x559dafcbd5a5 in ProcRenderDispatch /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXrender.c:1689 #5 0x559dafcbc4ea in Dispatch /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c:476 #6 0x559dafc4e9b0 in main /work/nx-libs/nx-X11/programs/Xserver/dix/main.c:353 #7 0x7f2708e1d09a in __libc_start_main ../csu/libc-start.c:308 #8 0x559dafc4f5d9 in _start (/work/nx-libs/nx-X11/programs/Xserver/nxagent+0x6e5d9) 0x60d000018fbc is located 0 bytes to the right of 140-byte region [0x60d000018f30,0x60d000018fbc) allocated by thread T0 here: #0 0x7f270aa1e330 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9330) #1 0x559dafcd646c in AllocateGlyph ../../render/glyph.c:348 This happens when two glyphs are compared via memcmp and the smaller one happens to be identical to the beginning of the bigger one. Newer render implementations use a sha1 hash instead of memcmp so this patch will (hopefully) be obsolete once render gets updated.
1 parent 8205db4 commit 234be02

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
 

‎nx-X11/programs/Xserver/hw/nxagent/NXglyph.c

+61
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,67 @@
5959

6060
#endif
6161

62+
GlyphRefPtr
63+
FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare)
64+
{
65+
CARD32 elt, step, s;
66+
GlyphPtr glyph;
67+
GlyphRefPtr table, gr, del;
68+
CARD32 tableSize = hash->hashSet->size;
69+
70+
table = hash->table;
71+
elt = signature % tableSize;
72+
step = 0;
73+
del = 0;
74+
for (;;)
75+
{
76+
gr = &table[elt];
77+
s = gr->signature;
78+
glyph = gr->glyph;
79+
if (!glyph)
80+
{
81+
if (del)
82+
gr = del;
83+
break;
84+
}
85+
if (glyph == DeletedGlyph)
86+
{
87+
if (!del)
88+
del = gr;
89+
else if (gr == del)
90+
break;
91+
}
92+
#ifdef NXAGENT_SERVER
93+
else if (s == signature && match && glyph->size != compare->size)
94+
{
95+
/*
96+
* if the glyphsize is different there's no need to do a memcmp
97+
* because it will surely report difference. And even worse:
98+
* it will read beyond the end of glyph under some
99+
* circumstances, which can be detected when compiling with
100+
* -fsanitize=address.
101+
*/
102+
}
103+
#endif
104+
else if (s == signature &&
105+
(!match ||
106+
memcmp (&compare->info, &glyph->info, compare->size) == 0))
107+
{
108+
break;
109+
}
110+
if (!step)
111+
{
112+
step = signature % hash->hashSet->rehash;
113+
if (!step)
114+
step = 1;
115+
}
116+
elt += step;
117+
if (elt >= tableSize)
118+
elt -= tableSize;
119+
}
120+
return gr;
121+
}
122+
62123
void
63124
AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
64125
{

‎nx-X11/programs/Xserver/render/glyph.c

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ GlyphInit (ScreenPtr pScreen)
144144
return TRUE;
145145
}
146146

147+
#ifndef NXAGENT_SERVER
147148
GlyphRefPtr
148149
FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare)
149150
{
@@ -192,6 +193,7 @@ FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare)
192193
}
193194
return gr;
194195
}
196+
#endif
195197

196198
CARD32
197199
HashGlyph (GlyphPtr glyph)

0 commit comments

Comments
 (0)
Please sign in to comment.