[PATCH 3/4] libmpdemux/mf: init_mf_from_glob_pattern: Use same signedness in comparison
Alexander Strasser <[email protected]> Tue, 1 Jun 2021 22:05:58 +0200
| Newsgroups | gmane.comp.video.mplayer.devel |
|---|---|
| Message-ID | <58664582100c81d64ffc2d124c4a2796378e0ed9.1622577107.git.eclipse7@gmx.net> |
Additionally detect if the number of matches of glob was bigger than what fits into signed int and fail in that case. Signed-off-by: Alexander Strasser <[email protected]> --- libmpdemux/mf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libmpdemux/mf.c b/libmpdemux/mf.c index 7e75b714c..89fc2a7a0 100644 --- a/libmpdemux/mf.c +++ b/libmpdemux/mf.c @@ -118,11 +118,18 @@ static int init_mf_from_glob_pattern(mf_t* mf, const char * filename){ { free( fname ); return 0; } mf->nr_of_files=gg.gl_pathc; + if (mf->nr_of_files < 0) + { + mf->nr_of_files = 0; + free( fname ); + globfree( &gg ); + return 0; + } mf->names=calloc( gg.gl_pathc, sizeof( char* ) ); mp_msg( MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d (%zu)\n", mf->nr_of_files, gg.gl_pathc * sizeof( char* ) ); - for( i=0;i < gg.gl_pathc;i++ ) + for( i=0;i < mf->nr_of_files;i++ ) { struct stat fs; if (stat( gg.gl_pathv[i],&fs ) == -1) continue; --