Skip to content

Commit b22f642

Browse files
azatBrendanCunningham
authored andcommitted
evdns: fix searching empty hostnames
From #332: Here follows a bug report by **Guido Vranken** via the _Tor bug bounty program_. Please credit Guido accordingly. ## Bug report The DNS code of Libevent contains this rather obvious OOB read: ```c static char * search_make_new(const struct search_state *const state, int n, const char *const base_name) { const size_t base_len = strlen(base_name); const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1; ``` If the length of ```base_name``` is 0, then line 3125 reads 1 byte before the buffer. This will trigger a crash on ASAN-protected builds. To reproduce: Build libevent with ASAN: ``` $ CFLAGS='-fomit-frame-pointer -fsanitize=address' ./configure && make -j4 ``` Put the attached ```resolv.conf``` and ```poc.c``` in the source directory and then do: ``` $ gcc -fsanitize=address -fomit-frame-pointer poc.c .libs/libevent.a $ ./a.out ================================================================= ==22201== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60060000efdf at pc 0x4429da bp 0x7ffe1ed47300 sp 0x7ffe1ed472f8 READ of size 1 at 0x60060000efdf thread T0 ``` P.S. we can add a check earlier, but since this is very uncommon, I didn't add it. Fixes: #332 Signed-off-by: Brendan Cunningham <[email protected]>
1 parent daa2561 commit b22f642

File tree

1 file changed

+4
-1
lines changed
  • opal/mca/event/libevent2022/libevent

1 file changed

+4
-1
lines changed

opal/mca/event/libevent2022/libevent/evdns.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,9 +3120,12 @@ search_set_from_hostname(struct evdns_base *base) {
31203120
static char *
31213121
search_make_new(const struct search_state *const state, int n, const char *const base_name) {
31223122
const size_t base_len = strlen(base_name);
3123-
const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;
3123+
char need_to_append_dot;
31243124
struct search_domain *dom;
31253125

3126+
if (!base_len) return NULL;
3127+
need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;
3128+
31263129
for (dom = state->head; dom; dom = dom->next) {
31273130
if (!n--) {
31283131
/* this is the postfix we want */

0 commit comments

Comments
 (0)