summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-02-17 15:27:59 +0100
committerCaolán McNamara <caolanm@redhat.com>2022-02-18 20:42:34 +0100
commit77bef67094579e7d0d2a515f5f8a5def8abe49e8 (patch)
treebb8fe57970d004f26ab80b9165fc438a45b15df8 /sc
parentb4bb43a896f5cffef69aba4082cee64d2be917d7 (diff)
fix range checking in calls like ScDocument::GetNote()
Change-Id: I5612e765b3484b0515f4a16030ee19133ae3126a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130076 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com> (cherry picked from commit 957d99a539df6e21fd40370938ca5dab1613cf8c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130105 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/document.cxx12
-rw-r--r--sc/source/core/data/table2.cxx15
3 files changed, 25 insertions, 4 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index a4e41a7bc318..094c3f018924 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -469,6 +469,8 @@ public:
void GetLastDataPos(SCCOL& rCol, SCROW& rRow) const;
std::unique_ptr<ScPostIt> ReleaseNote( SCCOL nCol, SCROW nRow );
+ ScPostIt* GetNote( SCCOL nCol, SCROW nRow );
+ void SetNote( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPostIt> pNote );
size_t GetNoteCount( SCCOL nCol ) const;
SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 86e13f815c91..106f959e7cf6 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6537,9 +6537,8 @@ ScPostIt* ScDocument::GetNote(const ScAddress& rPos)
ScPostIt* ScDocument::GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
{
- if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) &&
- nCol < maTabs[nTab]->GetAllocatedColumnsCount())
- return maTabs[nTab]->aCol[nCol].GetCellNote(nRow);
+ if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
+ return maTabs[nTab]->GetNote(nCol, nRow);
else
return nullptr;
@@ -6552,7 +6551,8 @@ void ScDocument::SetNote(const ScAddress& rPos, std::unique_ptr<ScPostIt> pNote)
void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPostIt> pNote)
{
- return maTabs[nTab]->CreateColumnIfNotExists(nCol).SetCellNote(nRow, std::move(pNote));
+ if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
+ maTabs[nTab]->SetNote(nCol, nRow, std::move(pNote));
}
bool ScDocument::HasNote(const ScAddress& rPos) const
@@ -6599,6 +6599,9 @@ bool ScDocument::HasColNotes(SCCOL nCol, SCTAB nTab) const
if (!pTab)
return false;
+ if (nCol >= pTab->GetAllocatedColumnsCount())
+ return false;
+
return pTab->aCol[nCol].HasCellNotes();
}
@@ -6642,6 +6645,7 @@ ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos)
else
return CreateNote(rPos);
}
+
ScPostIt* ScDocument::CreateNote(const ScAddress& rPos)
{
ScPostIt* pPostIt = new ScPostIt(*this, rPos);
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index f5f4b8723ab1..c2de8dead98c 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1818,6 +1818,21 @@ std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
return aCol[nCol].ReleaseNote(nRow);
}
+ScPostIt* ScTable::GetNote( SCCOL nCol, SCROW nRow )
+{
+ if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
+ return nullptr;
+ return aCol[nCol].GetCellNote(nRow);
+}
+
+void ScTable::SetNote( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPostIt> pNote )
+{
+ if (!ValidColRow(nCol, nRow))
+ return;
+
+ CreateColumnIfNotExists(nCol).SetCellNote(nRow, std::move(pNote));
+}
+
size_t ScTable::GetNoteCount( SCCOL nCol ) const
{
if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())