"I love the smell of patches in the morning. It smells like ... victory."

Attached is the patch that fixes the source of the bug in Http.cpp
This fix has been tested.

Also is a patch to make PCData methods more paranoid, since they were
segfaulting.  I not only patched FreeAmpStreams::PCData but several
other PCData methods to try and prevent the same problem there
(untested).

Also I patched Eof to be slightly more paranoid, though this was not a
problem in this case.

And I patched Scanf to assert valid preconditions to the pointer arithmetic
it uses.  Seems safer.

-- 
Chris Kuklewicz
Index: ui/musicbrowser/src/FreeAmpStreams.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/src/FreeAmpStreams.cpp,v
retrieving revision 1.2
diff -u -r1.2 FreeAmpStreams.cpp
--- ui/musicbrowser/src/FreeAmpStreams.cpp      2000/06/01 22:38:52     1.2
+++ ui/musicbrowser/src/FreeAmpStreams.cpp      2000/09/23 11:27:00
@@ -101,6 +101,11 @@
 
 Error FreeAmpStreams::PCData(string &data)
 {
+    if (NULL==m_info)
+    {
+        cerr << "FreeAmpStreams::PCData called with m_info==NULL" << endl;
+        return kError_InvalidParam;
+    }
     if (m_curElement == string("Url"))
     {
         m_info->m_streamUrl = data;
Index: ui/musicbrowser/src/Icecast.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/src/Icecast.cpp,v
retrieving revision 1.3
diff -u -r1.3 Icecast.cpp
--- ui/musicbrowser/src/Icecast.cpp     2000/05/15 22:44:12     1.3
+++ ui/musicbrowser/src/Icecast.cpp     2000/09/23 11:27:01
@@ -85,6 +85,11 @@
 
 Error IcecastStreams::PCData(string &data)
 {
+    if (NULL==m_info)
+    {
+        cerr << "IcecastStreams::PCData called with m_info==NULL" << endl;
+        return kError_InvalidParam;
+    }
     if (m_path == string("/directory/resource/name"))
     {
         m_info->m_name = data;
Index: lib/http/src/Http.cpp
===================================================================
RCS file: /src/repository/freeamp/lib/http/src/Http.cpp,v
retrieving revision 1.12
diff -u -r1.12 Http.cpp
--- lib/http/src/Http.cpp       2000/09/01 10:57:59     1.12
+++ lib/http/src/Http.cpp       2000/09/23 11:27:01
@@ -90,7 +90,7 @@
 
     eRet = Download(url, false);
     if (IsntError(eRet))
-        page = string((char *)m_buffer);
+        page = string((char *)m_buffer,m_bytesInBuffer);
 
     if (m_buffer)
     {
Index: dlm/rmp/rmp.cpp
===================================================================
RCS file: /src/repository/freeamp/dlm/rmp/rmp.cpp,v
retrieving revision 1.10
diff -u -r1.10 rmp.cpp
--- dlm/rmp/rmp.cpp     2000/06/21 13:34:36     1.10
+++ dlm/rmp/rmp.cpp     2000/09/23 11:27:01
@@ -166,21 +166,41 @@
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/TITLE"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetTitle(oData.c_str());
         return kError_NoErr;
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/ALBUM"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetAlbum(oData.c_str());
         return kError_NoErr;
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/ARTIST"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetArtist(oData.c_str());
         return kError_NoErr;
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/GENRE"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetGenre(oData.c_str());
         return kError_NoErr;
     }
@@ -191,26 +211,46 @@
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/SIZE"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetSize(atoi(oData.c_str()));
         return kError_NoErr;
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/YEAR"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetYear(atoi(oData.c_str()));
         return kError_NoErr;
     }
     if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/DURATION"))
     {
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetTime(atoi(oData.c_str()));
         return kError_NoErr;
     }
-       if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/FORMAT"))
+    if (m_oPath == string("/PACKAGE/TRACKLIST/TRACK/FORMAT"))
     {
-               uint32 bumpItUp = 0;
+        uint32 bumpItUp = 0;
+        
+        if(*oData.c_str() == '.')
+            bumpItUp = 1;
 
-               if(*oData.c_str() == '.')
-                       bumpItUp = 1;
-
+        if (NULL==m_pMetaData)
+        {
+            cerr << "RMP::PCData called with m_info==NULL" << endl;
+            return kError_NoErr;
+        }
        m_pMetaData->SetFormatExtension(oData.c_str() + bumpItUp);
         return kError_NoErr;
     }
Index: lib/xml/src/Parse.cpp
===================================================================
RCS file: /src/repository/freeamp/lib/xml/src/Parse.cpp,v
retrieving revision 1.7
diff -u -r1.7 Parse.cpp
--- lib/xml/src/Parse.cpp       2000/05/24 17:08:33     1.7
+++ lib/xml/src/Parse.cpp       2000/09/23 11:27:01
@@ -110,6 +110,7 @@
     strcat(szCustomFormat, "%n");
 
     iOffset = 0;
+    assert(m_uScanOffset <= m_oXML.size());
     iRet = sscanf(m_oXML.c_str() + m_uScanOffset, szCustomFormat, 
                   szData, &iOffset);
     if (iRet > 0 || iOffset > 0)
@@ -125,7 +126,7 @@
     if (m_fpFile)
        return feof(m_fpFile) != 0;
 
-    if (m_uScanOffset == m_oXML.size())
+    if (m_uScanOffset >= m_oXML.size())
        return true;
 
     return false;

Reply via email to