Skip to content

Commit 90dbd5d

Browse files
Check validity of iterator before dereferencing
1 parent a8c87eb commit 90dbd5d

File tree

7 files changed

+1172
-1
lines changed

7 files changed

+1172
-1
lines changed

src/interface/shared/data_iterator.i

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2023-24 Jim Easterbrook [email protected]
3+
// Copyright (C) 2023-25 Jim Easterbrook [email protected]
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -44,6 +44,13 @@ the 'end' value and can not be dereferenced."
4444
// Creating a new iterator keeps a reference to the current one
4545
KEEP_REFERENCE(container_type##_iterator*)
4646
KEEP_REFERENCE(container_type##_iterator_base*)
47+
// Check validity of pointer before dereferencing
48+
%typemap(check) container_type##_iterator* self {
49+
if (!$1->valid() && strncmp("$symname", "delete_", 7)) {
50+
SWIG_exception_fail(SWIG_ValueError, "in method '" "$symname"
51+
"', invalid iterator cannot be dereferenced");
52+
}
53+
}
4754
// Detect end of iteration
4855
%exception container_type##_iterator_base::__next__ %{
4956
$action

0 commit comments

Comments
 (0)