Skip to content

Commit

Permalink
Fix double free in Cu6mPlayer::~Cu6mPlayer() (issue adplug#91)
Browse files Browse the repository at this point in the history
Leave deallocation of song_data to destructor when
decompression fails, just like on success.

This fixes CVE-2019-15151.

Even though load() is apparently not supposed to be called
twice (and bad things happen in many players if you do),
let's also avoid leaking song_data's memory in that case.

Fixes: adplug#91
  • Loading branch information
miller-alex committed Mar 24, 2020
1 parent 8f0e614 commit 8abb932
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/u6m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
}

// load section
delete[] song_data;
song_data = new unsigned char[decompressed_filesize];
unsigned char* compressed_song_data = new unsigned char[filesize-3];

Expand All @@ -74,7 +75,6 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
fp.close(f);

// attempt to decompress the song data
// if unsuccessful, deallocate song_data[] on the spot, and return(false)
data_block source, destination;
source.size = filesize-4;
source.data = compressed_song_data;
Expand All @@ -84,7 +84,6 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
if (!lzw_decompress(source,destination))
{
delete[] compressed_song_data;
delete[] song_data;
return(false);
}

Expand Down

0 comments on commit 8abb932

Please sign in to comment.