summaryrefslogtreecommitdiff
path: root/lib/elf_py.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/elf_py.c')
-rw-r--r--lib/elf_py.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/lib/elf_py.c b/lib/elf_py.c
index 75d2d6007f..81ca668e70 100644
--- a/lib/elf_py.c
+++ b/lib/elf_py.c
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* fast ELF file accessor
* Copyright (C) 2018-2020 David Lamparter for NetDEF, Inc.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Note: this wrapper is intended to be used as build-time helper. While
@@ -293,7 +280,7 @@ static PyObject *elfreloc_getsection(PyObject *self, PyObject *args)
if (!w->es)
Py_RETURN_NONE;
- if (w->symidx == 0) {
+ if (!w->symvalid || w->symidx == 0) {
size_t idx = 0;
Elf_Scn *scn;
@@ -1153,7 +1140,8 @@ static PyObject *elffile_load(PyTypeObject *type, PyObject *args,
fd = open(filename, O_RDONLY | O_NOCTTY);
if (fd < 0 || fstat(fd, &st)) {
PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
- close(fd);
+ if (fd >= 0)
+ close(fd);
goto out;
}
w->len = st.st_size;