Skip to content

Commit 1507866

Browse files
committed
Fix potential heap use after free in CSVRow::iterator
1 parent 27282ed commit 1507866

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

include/internal/csv_row.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace csv {
203203

204204
CSV_INLINE HEDLEY_NON_NULL(2)
205205
CSVRow::iterator::iterator(const CSVRow* _reader, int _i)
206-
: daddy(_reader), i(_i) {
206+
: daddy(_reader), data(_reader->data), i(_i) {
207207
if (_i < (int)this->daddy->size())
208208
this->field = std::make_shared<CSVField>(
209209
this->daddy->operator[](_i));

include/internal/csv_row.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ namespace csv {
267267
#endif
268268

269269
private:
270-
const CSVRow * daddy = nullptr; // Pointer to parent
271-
std::shared_ptr<CSVField> field = nullptr; // Current field pointed at
272-
int i = 0; // Index of current field
270+
const CSVRow * daddy = nullptr; // Pointer to parent
271+
internals::RawCSVDataPtr data = nullptr; // Keep data alive for lifetime of iterator
272+
std::shared_ptr<CSVField> field = nullptr; // Current field pointed at
273+
int i = 0; // Index of current field
273274
};
274275

275276
/** A reverse iterator over the contents of a CSVRow. */

0 commit comments

Comments
 (0)