[PATCH] dom_string valgrinf warning

Luciano Montanaro mikelima at virgilio.it
Thu Jul 3 15:24:44 BST 2003


Hi, 
using valgrind on konq-embed produced, among other things,
the following error:


==28582== Invalid read of size 4
==28582==    at 0x82C1D6C: DOM::strcasecmp(DOM::DOMString const&, 
DOM::DOMString const&) (in 
/home/lmonta/kdesrc/kdenox/konq-embed/src/.libs/lt-konqueror)
==28582==    Address 0x43D81A5A is 10 bytes inside a block of size 12 alloc'd
==28582==    at 0x40026317: __builtin_vec_new (vg_replace_malloc.c:197)
==28582==    by 0x4002636E: operator new[](unsigned) (vg_replace_malloc.c:210)
==28582==    by 0x82C0F0C: DOM::DOMString::DOMString(QChar const*, unsigned) 
(in /home/lmonta/kdesrc/kdenox/konq-embed/src/.libs/lt-konqueror)

The problem, I think, is due to the fact that the 'bs' parameter can be 
shorter than 'as', so unallocated memory could be referenced.
I changed also the version using "char *" as the bs.

I found the problem in the 3.1 branch, but it is present on the HEAD branch 
also.

Luciano


? dom_string.patch
Index: dom_string.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/dom/dom_string.cpp,v
retrieving revision 1.36
diff -p -u -r1.36 dom_string.cpp
--- dom_string.cpp	8 Jan 2003 18:52:35 -0000	1.36
+++ dom_string.cpp	3 Jul 2003 14:10:55 -0000
@@ -228,6 +228,7 @@ bool DOM::strcasecmp( const DOMString &a
     const QChar *b = bs.unicode();
     if ( a == b )  return false;
     if ( !( a && b ) )  return true;
+    if ( l != bs.length() ) return true;
     int l = as.length();
     while ( l-- ) {
         if ( *a != *b && a->lower() != b->lower() ) return true;
@@ -241,6 +242,7 @@ bool DOM::strcasecmp( const DOMString &a
     const QChar *a = as.unicode();
     int l = as.length();
     if ( !bs ) return ( l != 0 );
+    if ( l != strlen(bs) ) return true;
     while ( l-- ) {
         if ( a->latin1() != *bs ) {
             char cc = ( ( *bs >= 'A' ) && ( *bs <= 'Z' ) ) ? ( ( *bs ) + 'a' 
- 'A' ) : ( *bs );




More information about the kfm-devel mailing list