[vlc-commits] [Git][videolan/vlc][master] 4 commits: url: reject out-of-range FDs

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Sep 19 18:48:01 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
83cba1b2 by Rémi Denis-Courmont at 2021-09-19T18:02:31+00:00
url: reject out-of-range FDs

FD must be positive `int`.

The test in unsigned space is equivalent to  `fd < 0 || fd > INT_MAX`,
but:
 - it is faster and,
 - it will not cause impossible predicate warnings on platforms
   where `INT_MAX` equals `LONG_MAX`.

- - - - -
f6179681 by Rémi Denis-Courmont at 2021-09-19T18:02:31+00:00
input: absolute URLs do not necessarily have ://

This accepts a lone ':', which is not followed by two forward slashes
if the URL lacks a host part.

- - - - -
c1c7b3cf by Rémi Denis-Courmont at 2021-09-19T18:02:31+00:00
access: forcefully convert MRL to local file path

This functionally reverts e124481d14b4a7778d26c12a0253e493f3dfcd34.
Fixes #26115.

- - - - -
70a6d76c by Rémi Denis-Courmont at 2021-09-19T18:02:31+00:00
Revert "url: handle proprietary dir:// MRL scheme"

This reverts commit de9d757daa5eff75c2a0fbee5c7152cf816d6524.
This kludge is no longer necessary.

- - - - -


5 changed files:

- src/input/access.c
- src/input/demux.c
- src/input/input.c
- src/input/item.c
- src/text/url.c


Changes:

=====================================
src/input/access.c
=====================================
@@ -117,7 +117,7 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
         char *url = access->psz_url;
         msg_Dbg(access, "creating access: %s", url);
 
-        const char *p = strstr(url, "://");
+        const char *p = strchr(url, ':');
         if (p == NULL)
             goto error;
 
@@ -125,8 +125,17 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
         if (unlikely(access->psz_name == NULL))
             goto error;
 
-        access->psz_location = p + 3;
+        access->psz_location = p + (strncmp(p + 1, "//", 2) ? 1 : 3);
         access->psz_filepath = vlc_uri2path(url);
+        if (access->psz_filepath == NULL)
+        {   /* FIXME: some access plugins want a file path for non-file MRLs */
+            char *file_url;
+            if (asprintf(&file_url, "file://%s", access->psz_location) >= 0)
+            {
+                access->psz_filepath = vlc_uri2path(file_url);
+                free(file_url);
+            }
+        }
         if (access->psz_filepath != NULL)
             msg_Dbg(access, " (path: %s)", access->psz_filepath);
 


=====================================
src/input/demux.c
=====================================
@@ -118,7 +118,7 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_input,
                             const char *module, const char *url,
                             stream_t *s, es_out_t *out, bool b_preparsing )
 {
-    const char *p = strstr(url, "://");
+    const char *p = strchr(url, ':');
     if (p == NULL) {
         errno = EINVAL;
         return NULL;
@@ -143,7 +143,9 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_input,
     if (unlikely(p_demux->psz_url == NULL))
         goto error;
 
-    p_demux->psz_location = p_demux->psz_url + 3 + (p - url);
+    p_demux->psz_location = p_demux->psz_url + 1 + (p - url);
+    if (strncmp(p_demux->psz_location, "//", 2) == 0)
+        p_demux->psz_location += 2;
     p_demux->psz_filepath = vlc_uri2path(url); /* parse URL */
 
     if( !b_preparsing )


=====================================
src/input/input.c
=====================================
@@ -3273,12 +3273,11 @@ static void input_SplitMRL( const char **access, const char **demux,
     char *p;
 
     /* Separate <path> from <access>[/<demux>]:// */
-    p = strstr( buf, "://" );
+    p = strchr( buf, ':');
     if( p != NULL )
     {
-        *p = '\0';
-        p += 3; /* skips "://" */
-        *path = p;
+        *(p++) = '\0'; /* skips ':' */
+        *path = p + (strncmp(p, "//", 2) ? 0 : 2); /* skips "//" */
 
         /* Remove HTML anchor if present (not supported).
          * The hash symbol itself should be URI-encoded. */


=====================================
src/input/item.c
=====================================
@@ -300,7 +300,7 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
 {
     assert( psz_uri );
 #ifndef NDEBUG
-    if( !strstr( psz_uri, "://" )
+    if( !strchr( psz_uri, ':' )
      || strchr( psz_uri, ' ' ) || strchr( psz_uri, '"' ) )
         fprintf( stderr, "Warning: %s(\"%s\"): file path instead of URL.\n",
                  __func__, psz_uri );
@@ -1210,7 +1210,7 @@ static enum input_item_type_e GuessType( const input_item_t *p_item, bool *p_net
 
     *p_net = false;
 
-    if( strstr( p_item->psz_uri, "://" ) == NULL )
+    if( strchr( p_item->psz_uri, ':' ) == NULL )
         return ITEM_TYPE_UNKNOWN; /* invalid URI */
 
     const struct item_type_entry *e =


=====================================
src/text/url.c
=====================================
@@ -266,8 +266,7 @@ char *vlc_uri2path (const char *url)
     /* Decode path */
     vlc_uri_decode (path);
 
-    if ((schemelen == 4 && !strncasecmp(url, "file", 4))
-     || (schemelen == 3 && !strncasecmp(url, "dir", 3)))
+    if (schemelen == 4 && !strncasecmp (url, "file", 4))
     {
 #if !defined (_WIN32) && !defined (__OS2__)
         /* Leading slash => local path */
@@ -298,9 +297,9 @@ char *vlc_uri2path (const char *url)
     else
     if (schemelen == 2 && !strncasecmp (url, "fd", 2))
     {
-        int fd = strtol (path, &end, 0);
+        long fd = strtol(path, &end, 0);
 
-        if (*end)
+        if (*end || ((unsigned long)fd) > INT_MAX)
             goto out;
 
 #if !defined( _WIN32 ) && !defined( __OS2__ )
@@ -316,7 +315,7 @@ char *vlc_uri2path (const char *url)
                 ret = strdup ("/dev/stderr");
                 break;
             default:
-                if (asprintf (&ret, "/dev/fd/%d", fd) == -1)
+                if (asprintf (&ret, "/dev/fd/%ld", fd) == -1)
                     ret = NULL;
         }
 #else



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c405cc28f031f4c325e2fe84cb9216184a0f31b7...70a6d76c8662cc515a6eb1aad59aecd58a0084da

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c405cc28f031f4c325e2fe84cb9216184a0f31b7...70a6d76c8662cc515a6eb1aad59aecd58a0084da
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list