Skip to content

Commit 993f590

Browse files
authored
Retry failed lookups after one week in libcdb (#2323)
* Retry failed lookups after one week in libcdb The libc databases might be updated to include the searched version, so a request that failed once might work in the future. Refs #983 * Update CHANGELOG
1 parent e466f5c commit 993f590

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The table below shows which release corresponds to each branch, and what date th
8484
- [#2328][2328] Lookup using $PATHEXT file extensions in `which` on Windows
8585
- [#2189][2189] Explicitly define p64/u64 functions for IDE support
8686
- [#2339][2339] Fix: Allow setting attributes on gdb Breakpoints
87+
- [#2323][2323] Retry failed lookups after one week in libcdb
8788

8889
[2242]: https://github.com/Gallopsled/pwntools/pull/2242
8990
[2277]: https://github.com/Gallopsled/pwntools/pull/2277
@@ -99,6 +100,7 @@ The table below shows which release corresponds to each branch, and what date th
99100
[2328]: https://github.com/Gallopsled/pwntools/pull/2328
100101
[2189]: https://github.com/Gallopsled/pwntools/pull/2189
101102
[2339]: https://github.com/Gallopsled/pwntools/pull/2339
103+
[2323]: https://github.com/Gallopsled/pwntools/pull/2323
102104

103105
## 4.12.0 (`beta`)
104106

pwnlib/libcdb.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import division
66

77
import os
8+
import time
89
import six
910
import tempfile
1011

@@ -29,6 +30,9 @@
2930
urls = os.environ['DEBUGINFOD_URLS'].split(' ')
3031
DEBUGINFOD_SERVERS = urls + DEBUGINFOD_SERVERS
3132

33+
# Retry failed lookups after some time
34+
NEGATIVE_CACHE_EXPIRY = 60 * 60 * 24 * 7 # 1 week
35+
3236
# https://gitlab.com/libcdb/libcdb wasn't updated after 2019,
3337
# but still is a massive database of older libc binaries.
3438
def provider_libcdb(hex_encoded_id, hash_type):
@@ -109,6 +113,10 @@ def search_by_hash(hex_encoded_id, hash_type='build_id', unstrip=True):
109113
cache, cache_valid = _check_elf_cache('libcdb', hex_encoded_id, hash_type)
110114
if cache_valid:
111115
return cache
116+
117+
# We searched for this buildid before, but didn't find anything.
118+
if cache is None:
119+
return None
112120

113121
# Run through all available libc database providers to see if we have a match.
114122
for provider in PROVIDERS:
@@ -141,6 +149,10 @@ def _search_debuginfo_by_hash(base_url, hex_encoded_id):
141149
cache, cache_valid = _check_elf_cache('libcdb_dbg', hex_encoded_id, 'build_id')
142150
if cache_valid:
143151
return cache
152+
153+
# We searched for this buildid before, but didn't find anything.
154+
if cache is None:
155+
return None
144156

145157
# Try to find separate debuginfo.
146158
url = '/buildid/{}/debuginfo'.format(hex_encoded_id)
@@ -191,8 +203,11 @@ def _check_elf_cache(cache_type, hex_encoded_id, hash_type):
191203

192204
data = read(cache)
193205
if not data.startswith(b'\x7FELF'):
194-
log.info_once("Skipping unavailable ELF %s", hex_encoded_id)
195-
return cache, False
206+
# Retry failed lookups after some time
207+
if time.time() > os.path.getmtime(cache) + NEGATIVE_CACHE_EXPIRY:
208+
return cache, False
209+
log.info_once("Skipping invalid cached ELF %s", hex_encoded_id)
210+
return None, False
196211

197212
log.info_once("Using cached data from %r", cache)
198213
return cache, True

0 commit comments

Comments
 (0)