[vlc-devel] [PATCH] upnp: fix incorrect starts-with checks

Lyndon Brown jnqnfe at gmail.com
Wed Sep 30 20:57:20 CEST 2020


preview:

From: Lyndon Brown <jnqnfe at gmail.com>
Date: Thu, 6 Jun 2019 02:44:32 +0100
Subject: upnp: fix some misuse of strncmp()

we do not want to be doing a 'starts with' check in these cases, they
should be an equality check

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 054a5d1910..89caa38c84 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -658,7 +658,7 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
     vlc_UrlParse( &url, psz_base_url );
 
     /* Part 1: a user may have provided a custom playlist url */
-    if (strncmp(psz_satip_channellist, "CustomList", 10) == 0) {
+    if (strcmp(psz_satip_channellist, "CustomList") == 0) {
         char *psz_satip_playlist_url = config_GetPsz( "satip-channellist-url" );
         if ( psz_satip_playlist_url ) {
             p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_satip_playlist_url, iconUrl );
@@ -681,8 +681,8 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
 
     /* Part 2: device playlist
      * In Automatic mode, or if requested by the user, check for a SAT>IP m3u list on the device */
-    if (strncmp(psz_satip_channellist, "ServerList", 10) == 0 ||
-        strncmp(psz_satip_channellist, "Auto", strlen ("Auto")) == 0 ) {
+    if (strcmp(psz_satip_channellist, "ServerList") == 0 ||
+        strcmp(psz_satip_channellist, "Auto") == 0 ) {
         const char* psz_m3u_url = xml_getChildElementValue( p_device_element, "satip:X_SATIPM3U" );
         if ( psz_m3u_url ) {
             if ( strncmp( "http", psz_m3u_url, 4) )
@@ -712,7 +712,7 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
             msg_Dbg( m_sd, "SAT>IP server '%s' did not provide a playlist", url.psz_host);
         }
 
-        if(strncmp(psz_satip_channellist, "ServerList", 10) == 0) {
+        if(strcmp(psz_satip_channellist, "ServerList") == 0) {
             /* to comply with the SAT>IP specifications, we don't fallback on another channel list if this path failed,
              * but in Automatic mode, we continue */
             free(psz_satip_channellist);
@@ -727,7 +727,7 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
      * MasterList is a list of usual Satellites */
 
     /* In Auto mode, default to MasterList list from satip.info */
-    if( strncmp(psz_satip_channellist, "Auto", strlen ("Auto")) == 0 ) {
+    if( strcmp(psz_satip_channellist, "Auto") == 0 ) {
         free(psz_satip_channellist);
         psz_satip_channellist = strdup( "MasterList" );
     }
@@ -909,13 +909,13 @@ namespace
             psz_album_artist = xml_getChildElementValue( itemElement, "upnp:albumArtist" );
             psz_albumArt = xml_getChildElementValue( itemElement, "upnp:albumArtURI" );
             const char *psz_media_type = xml_getChildElementValue( itemElement, "upnp:class" );
-            if (strncmp(psz_media_type, "object.item.videoItem", 21) == 0)
+            if (strcmp(psz_media_type, "object.item.videoItem") == 0)
                 media_type = VIDEO;
-            else if (strncmp(psz_media_type, "object.item.audioItem", 21) == 0)
+            else if (strcmp(psz_media_type, "object.item.audioItem") == 0)
                 media_type = AUDIO;
-            else if (strncmp(psz_media_type, "object.item.imageItem", 21) == 0)
+            else if (strcmp(psz_media_type, "object.item.imageItem") == 0)
                 media_type = IMAGE;
-            else if (strncmp(psz_media_type, "object.container", 16 ) == 0)
+            else if (strcmp(psz_media_type, "object.container") == 0)
                 media_type = CONTAINER;
             else
                 return false;



More information about the vlc-devel mailing list