[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: additional debug for lber memory functions (ITS#584)



This is a MIME message. If you are reading this text, you may want to 
consider changing to a mail reader or gateway that understands how to 
properly handle MIME multipart messages.

--=_2E765B5B.52339AF0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

Yes you are correct.  The storing of the pattern at the end of the
buffer will violate boundary constraints.  I will fix it.

In the mean time, there is a bug ber_memrealloc.  If LDAP_MEMORY_DEBUG
is defined and realloc fails, then variable new is never initialized.

Fix:
Index: memory.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/liblber/memory.c,v
retrieving revision 1.27
diff -u -w -r1.27 memory.c
--- memory.c 2000/05/13 00:36:07 1.27
+++ memory.c 2000/06/09 21:40:56
@@ -198,7 +198,7 @@
 void *
 ber_memrealloc( void* p, ber_len_t s )
 {
- void *new;
+ void *new =3D NULL;
     ber_int_options.lbo_valid =3D LBER_INITIALIZED;
=20
  /* realloc(NULL,s) -> malloc(s) */

-Steve


>>> "Kurt D. Zeilenga" <Kurt@OpenLDAP.org> 09-Jun-00 3:26:44 PM >>>
Looks like this would violate alignment restrictions
on many CPU?

Also, s/(int|long)/ber_len_t/

Kurt

At 06:18 PM 6/9/00 GMT, VTAG@novell.com wrote:
>Full_Name: Alan Clark
>Version: devel
>OS: Linux / NetWare / WinNT
>URL: ftp://ftp.openldap.org/incoming/aclark-000609.patch
>
>The above patch adds additional debug to the lber memory functions.  =3D
>Specifically it
>does the following:
>
>1.  Puts a known value at the end of the buffer (one is already at the =
=3D
>beginning)
>2. Checks for both values being there on all free and realloc functions.  =
=3D
>This identifies
>  buffers that have had their head or tail overwritten.
>3.  Any memory freed is filled with poison - 0xff to make it easier to =
=3D
>find code
>  that uses memory after it is free'd.
>
>Since we now have the buffer size, at both alloc and free time,
>I put in a little counter that gives the current value for amount of =3D
>memory allocated.  Note: this value won't be correct if the library is =
=3D
>running=3D20
>in the kernel or for multi-threaded applications, as there is no lock =3D
>around modification
>of the counter.
>
>I added a ber_get/get option to get the value.  This has proved very =3D
>helpful to us
>when searching for memory leaks.
>
>You're welcome to it if it seems useful to you.
>
>-Steve Sonntag
>-Alan Clark
>Manager
>Novell Directory Services
>
>--=3D_045C7138.7E1FB730
>Content-Type: text/html; charset=3DISO-8859-1
>Content-Transfer-Encoding: quoted-printable
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
><HTML><HEAD>
><META content=3D3D"text/html; charset=3D3Diso-8859-1" http-equiv=3D3DConte=
nt-Type=3D
>>
><META content=3D3D"MSHTML 5.00.2014.210" name=3D3DGENERATOR></HEAD>
><BODY style=3D3D"FONT: 8pt MS Sans Serif; MARGIN-LEFT: 2px; MARGIN-TOP: =
=3D
>2px">
><DIV>Full_Name: Alan Clark<BR>Version: devel<BR>OS: Linux / NetWare =
/=3D20
>WinNT<BR>URL: <A=3D20
>href=3D3D"ftp://ftp.openldap.org/incoming/aclark-00060";>ftp://ftp.openldap=
.or=3D
>g/incoming/aclark-00060</A>9</DIV>
><DIV>&nbsp;</DIV>
><DIV>The above patch adds additional debug to the lber memory functions.&n=
b=3D
>sp;=3D20
>Specifically it</DIV>
><DIV>does the following:</DIV>
><DIV>&nbsp;</DIV>
><DIV>1.&nbsp; Puts a known value at the end of the buffer (one is already =
=3D
>at the=3D20
>beginning)</DIV>
><DIV>2. Checks for both values being there on all free and realloc=3D20
>functions.&nbsp; This identifies</DIV>
><DIV>&nbsp; buffers that have had their head or tail overwritten.</DIV>
><DIV>3.&nbsp; Any memory freed is filled with poison - 0xff to make it =
=3D
>easier to=3D20
>find code</DIV>
><DIV>&nbsp; that uses memory after it is free'd.</DIV>
><DIV>&nbsp;</DIV>
><DIV>Since we now have the buffer size, at both alloc and free time,</DIV>=

><DIV>I put in a little counter that gives the current value for amount of =
=3D
>memory=3D20
>allocated.&nbsp; Note: this value won't be correct if the library is =3D
>running=3D20
></DIV>
><DIV>in the kernel or for multi-threaded applications, as there is no =3D
>lock=3D20
>around modification</DIV>
><DIV>of the counter.</DIV>
><DIV>&nbsp;</DIV>
><DIV>I added a ber_get/get option to get the value.&nbsp; This has proved =
=3D
>very=3D20
>helpful to us</DIV>
><DIV>when searching for memory leaks.</DIV>
><DIV>&nbsp;</DIV>
><DIV>You're welcome to it if it seems useful to you.</DIV>
><DIV>&nbsp;</DIV>
><DIV>-Steve Sonntag<BR>-Alan Clark</DIV>
><DIV>Manager</DIV>
><DIV>Novell Directory Services</DIV></BODY></HTML>
>
>--=3D_045C7138.7E1FB730--
>
>

--=_2E765B5B.52339AF0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" http-equiv=3DContent-Type=
>
<META content=3D"MSHTML 5.00.2014.210" name=3DGENERATOR></HEAD>
<BODY style=3D"FONT: 8pt MS Sans Serif; MARGIN-LEFT: 2px; MARGIN-TOP: =
2px"><FONT=20
size=3D1>
<DIV>Yes you are correct.&nbsp; The storing of the pattern at the end =
of=20
the</DIV>
<DIV>buffer will violate boundary constraints.&nbsp; I will fix it.</DIV>
<DIV>&nbsp;</DIV>
<DIV>In the mean time, there is a bug ber_memrealloc.&nbsp; If=20
LDAP_MEMORY_DEBUG</DIV>
<DIV>is defined and realloc fails, then variable new is never initialized.<=
/DIV>
<DIV>&nbsp;</DIV>
<DIV>Fix:</DIV>
<DIV>Index:=20
memory.c<BR>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<BR>RCS=20
file: /repo/OpenLDAP/pkg/ldap/libraries/liblber/memory.c,v<BR>retrieving=20=

revision 1.27<BR>diff -u -w -r1.27 memory.c<BR>--- memory.c&nbsp;2000/05/13=
=20
00:36:07&nbsp;1.27<BR>+++ memory.c&nbsp;2000/06/09 21:40:56<BR>@@ -198,7 =
+198,7=20
@@<BR>&nbsp;void *<BR>&nbsp;ber_memrealloc( void* p, ber_len_t s=20
)<BR>&nbsp;{<BR>-&nbsp;void *new;<BR>+&nbsp;void *new =3D=20
NULL;<BR>&nbsp;&nbsp;&nbsp;&nbsp; ber_int_options.lbo_valid =3D=20
LBER_INITIALIZED;<BR>&nbsp;<BR>&nbsp;&nbsp;/* realloc(NULL,s) -&gt; =
malloc(s)=20
*/</DIV>
<DIV>&nbsp;</DIV>
<DIV>-Steve</DIV></FONT><BR><BR>&gt;&gt;&gt; "Kurt D. Zeilenga"=20
&lt;Kurt@OpenLDAP.org&gt; 09-Jun-00 3:26:44 PM &gt;&gt;&gt;<BR>Looks like =
this=20
would violate alignment restrictions<BR>on many CPU?<BR><BR>Also,=20
s/(int|long)/ber_len_t/<BR><BR>Kurt<BR><BR>At 06:18 PM 6/9/00 GMT,=20
VTAG@novell.com wrote:<BR>&gt;Full_Name: Alan Clark<BR>&gt;Version:=20
devel<BR>&gt;OS: Linux / NetWare / WinNT<BR>&gt;URL:=20
ftp://ftp.openldap.org/incoming/aclark-000609.patch<BR>&gt;<BR>&gt;The =
above=20
patch adds additional debug to the lber memory functions.&nbsp;=20
=3D<BR>&gt;Specifically it<BR>&gt;does the following:<BR>&gt;<BR>&gt;1.&nbs=
p; Puts=20
a known value at the end of the buffer (one is already at the=20
=3D<BR>&gt;beginning)<BR>&gt;2. Checks for both values being there on all =
free and=20
realloc functions.&nbsp; =3D<BR>&gt;This identifies<BR>&gt;&nbsp; buffers =
that=20
have had their head or tail overwritten.<BR>&gt;3.&nbsp; Any memory freed =
is=20
filled with poison - 0xff to make it easier to =3D<BR>&gt;find code<BR>&gt;=
&nbsp;=20
that uses memory after it is free'd.<BR>&gt;<BR>&gt;Since we now have the =
buffer=20
size, at both alloc and free time,<BR>&gt;I put in a little counter that =
gives=20
the current value for amount of =3D<BR>&gt;memory allocated.&nbsp; Note: =
this=20
value won't be correct if the library is =3D<BR>&gt;running=3D20<BR>&gt;in =
the=20
kernel or for multi-threaded applications, as there is no lock =3D<BR>&gt;a=
round=20
modification<BR>&gt;of the counter.<BR>&gt;<BR>&gt;I added a ber_get/get =
option=20
to get the value.&nbsp; This has proved very =3D<BR>&gt;helpful to =
us<BR>&gt;when=20
searching for memory leaks.<BR>&gt;<BR>&gt;You're welcome to it if it =
seems=20
useful to you.<BR>&gt;<BR>&gt;-Steve Sonntag<BR>&gt;-Alan=20
Clark<BR>&gt;Manager<BR>&gt;Novell Directory=20
Services<BR>&gt;<BR>&gt;--=3D_045C7138.7E1FB730<BR>&gt;Content-Type: =
text/html;=20
charset=3DISO-8859-1<BR>&gt;Content-Transfer-Encoding:=20
quoted-printable<BR>&gt;<BR>&gt;&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML =
4.0=20
Transitional//EN"&gt;<BR>&gt;&lt;HTML&gt;&lt;HEAD&gt;<BR>&gt;&lt;META=20
content=3D3D"text/html; charset=3D3Diso-8859-1"=20
http-equiv=3D3DContent-Type=3D<BR>&gt;&gt;<BR>&gt;&lt;META content=3D3D"MSH=
TML=20
5.00.2014.210" name=3D3DGENERATOR&gt;&lt;/HEAD&gt;<BR>&gt;&lt;BODY =
style=3D3D"FONT:=20
8pt MS Sans Serif; MARGIN-LEFT: 2px; MARGIN-TOP:=20
=3D<BR>&gt;2px"&gt;<BR>&gt;&lt;DIV&gt;Full_Name: Alan Clark&lt;BR&gt;Versio=
n:=20
devel&lt;BR&gt;OS: Linux / NetWare /=3D20<BR>&gt;WinNT&lt;BR&gt;URL:=20
&lt;A=3D20<BR>&gt;href=3D3D"ftp://ftp.openldap.org/incoming/aclark-00060"&g=
t;ftp://ftp.openldap.or=3D<BR>&gt;g/incoming/aclark-00060&lt;/A&gt;9&lt;/DI=
V&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;The=20
above patch adds additional debug to the lber memory=20
functions.&amp;nb=3D<BR>&gt;sp;=3D20<BR>&gt;Specifically=20
it&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;does the=20
following:&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;=
DIV&gt;1.&amp;nbsp;=20
Puts a known value at the end of the buffer (one is already =3D<BR>&gt;at=
=20
the=3D20<BR>&gt;beginning)&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;2. Checks for =
both values=20
being there on all free and realloc=3D20<BR>&gt;functions.&amp;nbsp; =
This=20
identifies&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp; buffers that have had =
their=20
head or tail overwritten.&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;3.&amp;nbsp; Any =
memory=20
freed is filled with poison - 0xff to make it =3D<BR>&gt;easier to=3D20<BR>=
&gt;find=20
code&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp; that uses memory after it =
is=20
free'd.&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;DIV=
&gt;Since=20
we now have the buffer size, at both alloc and free=20
time,&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;I put in a little counter that gives =
the=20
current value for amount of =3D<BR>&gt;memory=3D20<BR>&gt;allocated.&amp;nb=
sp; Note:=20
this value won't be correct if the library is=20
=3D<BR>&gt;running=3D20<BR>&gt;&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;in the =
kernel or for=20
multi-threaded applications, as there is no =3D<BR>&gt;lock=3D20<BR>&gt;aro=
und=20
modification&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;of the=20
counter.&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;DI=
V&gt;I=20
added a ber_get/get option to get the value.&amp;nbsp; This has proved=20
=3D<BR>&gt;very=3D20<BR>&gt;helpful to us&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;whe=
n=20
searching for memory=20
leaks.&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;DIV&=
gt;You're=20
welcome to it if it seems useful to=20
you.&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt=
;-Steve=20
Sonntag&lt;BR&gt;-Alan=20
Clark&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;Manager&lt;/DIV&gt;<BR>&gt;&lt;DIV&gt;N=
ovell=20
Directory=20
Services&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;<BR>&gt;<BR>&gt;--=3D_045C713=
8.7E1FB730--<BR>&gt;<BR>&gt;<BR></BODY></HTML>

--=_2E765B5B.52339AF0--