[vlc-devel] [PATCH] lib: core: fix arg stack overflow warning
Francois Cartegnie
fcvlcdev at free.fr
Tue May 22 19:43:25 CEST 2018
for arg count close to half stack
---
lib/core.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/lib/core.c b/lib/core.c
index 0178a83d44..e9142807fc 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -46,10 +46,18 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
if (unlikely(p_new == NULL))
return NULL;
- const char *my_argv[argc + 2];
+ if(unlikely(SIZE_MAX - argc < 2))
+ return NULL;
+
+ if(unlikely(SIZE_MAX / sizeof(char *) < (size_t)argc + 2))
+ return NULL;
+
+ const char **my_argv = malloc( (argc + 2) * sizeof(*my_argv) );
+ if(unlikely(!my_argv))
+ goto error;
+
my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
- for( int i = 0; i < argc; i++ )
- my_argv[i + 1] = argv[i];
+ memcpy( &my_argv[1], argv, argc * sizeof(*argv) );
my_argv[argc + 1] = NULL; /* C calling conventions require a NULL */
libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
@@ -62,6 +70,7 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
goto error;
}
+ free(my_argv);
p_new->p_libvlc_int = p_libvlc_int;
p_new->vlm = NULL;
p_new->ref_count = 1;
@@ -70,6 +79,7 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
return p_new;
error:
+ free (my_argv);
free (p_new);
libvlc_threads_deinit ();
return NULL;
--
2.14.3
More information about the vlc-devel
mailing list