Fix use-after-free bugs

UnsavedFile should now actually be storing the data, not just the pointers to
it.
This commit is contained in:
Strahinja Val Markovic 2013-10-03 15:44:53 -07:00
parent c43327d176
commit 6b11edb2e2
3 changed files with 8 additions and 9 deletions

View File

@ -112,11 +112,8 @@ std::vector< CXUnsavedFile > ToCXUnsavedFiles(
std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() ); std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() );
for ( uint i = 0; i < unsaved_files.size(); ++i ) { for ( uint i = 0; i < unsaved_files.size(); ++i ) {
X_VERIFY( unsaved_files[ i ].filename_ ); clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_.c_str();
X_VERIFY( unsaved_files[ i ].contents_ ); clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_.c_str();
X_VERIFY( unsaved_files[ i ].length_ );
clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_;
clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_;
clang_unsaved_files[ i ].Length = unsaved_files[ i ].length_; clang_unsaved_files[ i ].Length = unsaved_files[ i ].length_;
} }

View File

@ -37,6 +37,8 @@ std::string CXStringToString( CXString text );
std::vector< CompletionData > ToCompletionDataVector( std::vector< CompletionData > ToCompletionDataVector(
CXCodeCompleteResults *results ); CXCodeCompleteResults *results );
// NOTE: CXUnsavedFiles store pointers to data in UnsavedFiles, so UnsavedFiles
// need to outlive CXUnsavedFiles!
std::vector< CXUnsavedFile > ToCXUnsavedFiles( std::vector< CXUnsavedFile > ToCXUnsavedFiles(
const std::vector< UnsavedFile > &unsaved_files ); const std::vector< UnsavedFile > &unsaved_files );

View File

@ -18,13 +18,13 @@
#ifndef UNSAVEDFILE_H_0GIYZQL4 #ifndef UNSAVEDFILE_H_0GIYZQL4
#define UNSAVEDFILE_H_0GIYZQL4 #define UNSAVEDFILE_H_0GIYZQL4
#include <cstddef> #include <string>
struct UnsavedFile { struct UnsavedFile {
UnsavedFile() : filename_( NULL ), contents_( NULL ), length_( 0 ) {} UnsavedFile() : filename_( "" ), contents_( "" ), length_( 0 ) {}
const char *filename_; std::string filename_;
const char *contents_; std::string contents_;
unsigned long length_; unsigned long length_;
// We need this to be able to export this struct to Python via Boost.Python's // We need this to be able to export this struct to Python via Boost.Python's