fix vips7 split on empty filename

a "" filename in vips7 compat mode could trigger a read beyond the end of
the string

see https://github.com/jcupitt/libvips/issues/1040
This commit is contained in:
John Cupitt 2018-07-23 18:50:53 +01:00
parent 479610ff30
commit b7bac0d88d
1 changed files with 7 additions and 4 deletions

View File

@ -79,12 +79,17 @@ void
im_filename_split( const char *path, char *name, char *mode )
{
char *p;
size_t len;
vips_strncpy( name, path, FILENAME_MAX );
strcpy( mode, "" );
/* Search back towards start stopping at each ':' char.
if( (len = strlen( name )) == 0 )
return;
/* Search backwards towards start, stopping at each ':' char.
*/
for( p = name + strlen( name ) - 1; p > name; p -= 1 )
for( p = name + len - 1; p > name; p -= 1 )
if( *p == ':' ) {
char *q;
@ -120,8 +125,6 @@ im_filename_split( const char *path, char *name, char *mode )
vips_strncpy( mode, p + 1, FILENAME_MAX );
*p = '\0';
}
else
strcpy( mode, "" );
}
/**