mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
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:
committed by
Alessandro Di Federico
parent
db6c6b1f90
commit
7e96bb2189
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user