Skip to content

Commit 8e58ab0

Browse files
Joachim Pouderouxkwrobot
Joachim Pouderoux
authored andcommittedDec 14, 2018
Merge topic 'Fix-vtkSEPReader-use-after-free'
8a7f62e Fix ASAN error use-after-free in vtkSEPReader Acked-by: Kitware Robot <[email protected]> Merge-request: !4995
2 parents 653fee0 + 8a7f62e commit 8e58ab0

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed
 

‎IO/Image/vtkSEPReader.cxx

+9-25
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@ int vtkSEPReader::RequestData(vtkInformation *request,
8484
{
8585
// Replace the filename with the data file and delegate the reading of this
8686
// raw data to the underlying vtkImageReader
87-
const char *fileName = this->FileName;
88-
this->ReplaceFileName(this->DataFile.c_str());
87+
char * const fileName = this->FileName;
88+
89+
// This `const_cast` is valid because the `RequestData` of
90+
// `Superclass` does not try to modify the string pointed by
91+
// `FileName`. (It does not modify the pointer `FileName` as well,
92+
// but that is not why the `const_cast` is valid.)
93+
this->FileName = const_cast<char*>(this->DataFile.c_str());
8994

9095
int res = this->Superclass::RequestData(request, inputVector, outputVector);
9196

92-
// Restore the user providen filename (the header file)
93-
this->ReplaceFileName(fileName);
97+
// Restore the user provided filename (the header file)
98+
this->FileName = fileName;
9499
return res;
95100
}
96101

@@ -210,24 +215,3 @@ int vtkSEPReader::ReadHeader()
210215

211216
return 1;
212217
}
213-
214-
//----------------------------------------------------------------------------
215-
// Replace FileName without calling Modified()
216-
void vtkSEPReader::ReplaceFileName(const char *name)
217-
{
218-
if (this->FileName && name && (!strcmp(this->FileName, name)))
219-
{
220-
return;
221-
}
222-
if (!name && !this->FileName)
223-
{
224-
return;
225-
}
226-
delete[] this->FileName;
227-
this->FileName = nullptr;
228-
if (name)
229-
{
230-
this->FileName = new char[strlen(name) + 1];
231-
strcpy(this->FileName, name);
232-
}
233-
}

‎IO/Image/vtkSEPReader.h

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class VTKIOIMAGE_EXPORT vtkSEPReader : public vtkImageReader
5252

5353
int ReadHeader();
5454

55-
void ReplaceFileName(const char* fname);
5655
std::string DataFile;
5756

5857
private:

0 commit comments

Comments
 (0)
Please sign in to comment.