Skip to content

Commit e475d10

Browse files
Bug#21286722 MISSING SANITY CHECKS FOR MALLOC() IN RESTORE.CPP, DBUTIL.CPP, SQLCLIENT.CPP
PART 1: RESTORE.CPP In RESTORE.CPP when we try to create the Constructor for RestoreDataIterator it calls system malloc and does not check for failure. As this can lead to crash, have added a validation function(validateRestoreDataIterator, validateBackupFile) which checks for the malloc failure. Hence, whenever we try to create an instance of class RestoreDataIterator it is mandatory to call validateRestoreDataIterator and validateBackupFile. Currently it’s been used only once. So, have added validation check in that location.
1 parent b645850 commit e475d10

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

storage/ndb/tools/restore/Restore.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -803,6 +803,19 @@ RestoreDataIterator::RestoreDataIterator(const RestoreMetaData & md, void (* _fr
803803
m_row_bitfield_len = 0;
804804
}
805805

806+
807+
bool
808+
RestoreDataIterator::validateRestoreDataIterator()
809+
{
810+
if (!m_bitfield_storage_ptr)
811+
{
812+
err << "m_bitfield_storage_ptr is NULL" << endl;
813+
return false;
814+
}
815+
return true;
816+
}
817+
818+
806819
RestoreDataIterator::~RestoreDataIterator()
807820
{
808821
free_bitfield_storage();
@@ -1335,6 +1348,17 @@ BackupFile::BackupFile(void (* _free_data_callback)())
13351348
#endif
13361349
}
13371350

1351+
bool
1352+
BackupFile::validateBackupFile()
1353+
{
1354+
if (!m_buffer)
1355+
{
1356+
err << "m_buffer is NULL" << endl;
1357+
return false;
1358+
}
1359+
return true;
1360+
}
1361+
13381362
BackupFile::~BackupFile()
13391363
{
13401364
(void)ndbzclose(&m_file);

storage/ndb/tools/restore/Restore.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -370,6 +370,7 @@ class BackupFile {
370370
public:
371371
bool readHeader();
372372
bool validateFooter();
373+
bool validateBackupFile();
373374

374375
const char * getPath() const { return m_path;}
375376
const char * getFilename() const { return m_fileName;}
@@ -451,6 +452,7 @@ class RestoreDataIterator : public BackupFile {
451452
// Read data file fragment header
452453
bool readFragmentHeader(int & res, Uint32 *fragmentId);
453454
bool validateFragmentFooter();
455+
bool validateRestoreDataIterator();
454456

455457
const TupleS *getNextTuple(int & res);
456458
TableS *getCurrentTable();

storage/ndb/tools/restore/restore_main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -1552,6 +1552,19 @@ main(int argc, char** argv)
15521552
}
15531553

15541554
RestoreDataIterator dataIter(metaData, &free_data_callback);
1555+
1556+
if (!dataIter.validateBackupFile())
1557+
{
1558+
err << "Unable to allocate memory for BackupFile constructor" << endl;
1559+
exitHandler(NDBT_FAILED);
1560+
}
1561+
1562+
1563+
if (!dataIter.validateRestoreDataIterator())
1564+
{
1565+
err << "Unable to allocate memory for RestoreDataIterator constructor" << endl;
1566+
exitHandler(NDBT_FAILED);
1567+
}
15551568

15561569
// Read data file header
15571570
if (!dataIter.readHeader())

0 commit comments

Comments
 (0)