revng.api: avoid NULL dereferencing in extract

The call to `rp_container_extract_one` can return a null pointer, add a
check that allows to avoid dereferencing it if this happens.
This commit is contained in:
Giacomo Vercesi
2023-06-23 09:01:26 +02:00
committed by Alessandro Di Federico
parent db6c6b1f90
commit 7e96bb2189
2 changed files with 10 additions and 2 deletions
+7 -1
View File
@@ -117,7 +117,13 @@ class Manager:
# TODO: we really should be able to provide a detailed error here
raise RevngException("Failed to produce targets")
return {t.serialize(): t.extract() for t in targets}
result = {}
for target in targets:
extracted_target = target.extract()
if extracted_target is None:
raise RevngException(f"Target {target.serialize()} extraction failed")
result[target.serialize()] = extracted_target
return result
def produce_target(
self,
+3 -1
View File
@@ -54,8 +54,10 @@ class Target:
_serialized = _api.rp_target_create_serialized_string(self._target)
return make_python_string(_serialized)
def extract(self) -> str | bytes:
def extract(self) -> str | bytes | None:
_buffer = _api.rp_container_extract_one(self._container._container, self._target)
if _buffer == ffi.NULL:
return None
size = _api.rp_buffer_size(_buffer)
data = _api.rp_buffer_data(_buffer)
return convert_buffer(data, size, self._container.mime)