[Libreoffice-commits] core.git: sal/osl
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sun Oct 21 07:42:36 UTC 2018
sal/osl/w32/profile.cxx | 61 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 14 deletions(-)
New commits:
commit 5e8cd8683d345b75297994b3f7aab851835eb124
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Oct 20 23:57:26 2018 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Oct 21 09:42:16 2018 +0200
tdf#120703 (PVS): handle failed calloc/realloc
V522 There might be dereferencing of a potential null pointer 'pProfile'.
Check lines: 215, 213.
V522 There might be dereferencing of a potential null pointer 'pFile'.
Check lines: 1081, 1068.
V701 realloc() possible leak: when realloc() fails in allocating memory,
original pointer 'pProfile->m_Lines' is lost. Consider assigning
realloc() to a temporary pointer.
V522 There might be dereferencing of a potential null pointer 'pProfile->m_Lines'.
Check lines: 1328, 1324.
V701 realloc() possible leak: when realloc() fails in allocating memory,
original pointer 'pProfile->m_Lines' is lost. Consider assigning
realloc() to a temporary pointer.
V522 There might be dereferencing of a potential null pointer 'pProfile->m_Lines'.
Check lines: 1365, 1362.
V701 realloc() possible leak: when realloc() fails in allocating memory,
original pointer 'pSection->m_Entries' is lost. Consider assigning
realloc() to a temporary pointer.
V701 realloc() possible leak: when realloc() fails in allocating memory,
original pointer 'pProfile->m_Sections' is lost. Consider assigning
realloc() to a temporary pointer.
V522 There might be dereferencing of a potential null pointer 'pProfile->m_Sections'.
Check lines: 1540, 1536.
Change-Id: Ib6c2c79c372120268f6101f639a3ed085534cca0
Reviewed-on: https://gerrit.libreoffice.org/62116
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sal/osl/w32/profile.cxx b/sal/osl/w32/profile.cxx
index 63e172ed7553..ccf96ff35e03 100644
--- a/sal/osl/w32/profile.cxx
+++ b/sal/osl/w32/profile.cxx
@@ -211,6 +211,8 @@ oslProfile SAL_CALL osl_openProfile(rtl_uString *strProfileName, sal_uInt32 Flag
}
pProfile = static_cast<osl_TProfileImpl*>(calloc(1, sizeof(osl_TProfileImpl)));
+ if (!pProfile)
+ return nullptr;
pProfile->m_Flags = Flags & FLG_USER;
osl_getSystemPathFromFileURL(strProfileName, &pProfile->m_strFileName);
@@ -1066,6 +1068,8 @@ static bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption ProfileFlags )
{
osl_TFile* pFile = static_cast< osl_TFile*>( calloc( 1, sizeof(osl_TFile) ) );
+ if (!pFile)
+ return nullptr;
bool bWriteable = false;
if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) )
@@ -1321,11 +1325,19 @@ static const sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line)
unsigned int oldmax=pProfile->m_MaxLines;
pProfile->m_MaxLines += LINES_ADD;
- pProfile->m_Lines = static_cast<sal_Char **>(realloc(pProfile->m_Lines, pProfile->m_MaxLines * sizeof(sal_Char *)));
+ if (auto p = static_cast<sal_Char **>(realloc(pProfile->m_Lines, pProfile->m_MaxLines * sizeof(sal_Char *))))
+ {
+ pProfile->m_Lines = p;
- for ( index = oldmax ; index < pProfile->m_MaxLines ; ++index )
+ for ( index = oldmax ; index < pProfile->m_MaxLines ; ++index )
+ {
+ pProfile->m_Lines[index]=nullptr;
+ }
+ }
+ else
{
- pProfile->m_Lines[index]=nullptr;
+ free(pProfile->m_Lines);
+ pProfile->m_Lines = nullptr;
}
}
@@ -1359,12 +1371,19 @@ static const sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Li
else
{
pProfile->m_MaxLines += LINES_ADD;
- pProfile->m_Lines = static_cast<sal_Char **>(realloc(pProfile->m_Lines,
- pProfile->m_MaxLines * sizeof(sal_Char *)));
+ if (auto p = static_cast<sal_Char**>(
+ realloc(pProfile->m_Lines, pProfile->m_MaxLines * sizeof(sal_Char*))))
+ {
+ pProfile->m_Lines = p;
- memset(&pProfile->m_Lines[pProfile->m_NoLines],
- 0,
- (pProfile->m_MaxLines - pProfile->m_NoLines - 1) * sizeof(sal_Char*));
+ memset(&pProfile->m_Lines[pProfile->m_NoLines], 0,
+ (pProfile->m_MaxLines - pProfile->m_NoLines - 1) * sizeof(sal_Char*));
+ }
+ else
+ {
+ free(pProfile->m_Lines);
+ pProfile->m_Lines = nullptr;
+ }
}
if (pProfile->m_Lines == nullptr)
@@ -1474,8 +1493,14 @@ static bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
else
{
pSection->m_MaxEntries += ENTRIES_ADD;
- pSection->m_Entries = static_cast<osl_TProfileEntry *>(realloc(pSection->m_Entries,
- pSection->m_MaxEntries * sizeof(osl_TProfileEntry)));
+ if (auto p = static_cast<osl_TProfileEntry*>(realloc(
+ pSection->m_Entries, pSection->m_MaxEntries * sizeof(osl_TProfileEntry))))
+ pSection->m_Entries = p;
+ else
+ {
+ free(pSection->m_Entries);
+ pSection->m_Entries = nullptr;
+ }
}
if (pSection->m_Entries == nullptr)
@@ -1533,11 +1558,19 @@ static bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Sec
unsigned int oldmax=pProfile->m_MaxSections;
pProfile->m_MaxSections += SECTIONS_ADD;
- pProfile->m_Sections = static_cast<osl_TProfileSection*>(realloc(pProfile->m_Sections,
- pProfile->m_MaxSections * sizeof(osl_TProfileSection)));
- for ( index = oldmax ; index < pProfile->m_MaxSections ; ++index )
+ if (auto p = static_cast<osl_TProfileSection*>(realloc(
+ pProfile->m_Sections, pProfile->m_MaxSections * sizeof(osl_TProfileSection))))
+ {
+ pProfile->m_Sections = p;
+ for ( index = oldmax ; index < pProfile->m_MaxSections ; ++index )
+ {
+ pProfile->m_Sections[index].m_Entries=nullptr;
+ }
+ }
+ else
{
- pProfile->m_Sections[index].m_Entries=nullptr;
+ free(pProfile->m_Sections);
+ pProfile->m_Sections = nullptr;
}
}
More information about the Libreoffice-commits
mailing list