Skip to content

Commit

Permalink
fix vips7 split on empty filename
Browse files Browse the repository at this point in the history
a "" filename in vips7 compat mode could trigger a read beyond the end of
the string

see https://github.com/jcupitt/libvips/issues/1040
  • Loading branch information
jcupitt committed Jul 23, 2018
1 parent 479610f commit b7bac0d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libvips/deprecated/vips7compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, "" );
}

/**
Expand Down

0 comments on commit b7bac0d

Please sign in to comment.