• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

c-ares / c-ares / 28529475594
90%

Build:
DEFAULT BRANCH: main
Ran 01 Jul 2026 03:42PM UTC
Jobs 1
Files 177
Run time 2min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

01 Jul 2026 03:39PM UTC coverage: 91.674% (-0.007%) from 91.681%
28529475594

push

github

web-flow
fix: prevent undefined-behavior left shift in ares_calc_query_timeout() (#1151)

## Summary

Fixes #1144.

`ares_calc_query_timeout()` left-shifts `timeplus` by `rounds` without
bounding the exponent. When a query is requeued 64+ times for a single
server (persistent connection failures with `num_servers == 1`),
`rounds` reaches 64 and `timeplus <<= 64` invokes undefined behavior on
a 64-bit `size_t` (C11 §6.5.7¶3).

The existing `channel->maxtimeout` clamp runs **after** the shift and
cannot prevent the UB.

## Fix

Saturate `timeplus` to `SIZE_MAX` when:
- `rounds >= sizeof(timeplus) * CHAR_BIT` (shift width ≥ type width),
**or**
- `timeplus > (SIZE_MAX >> rounds)` (shift would overflow).

The subsequent `maxtimeout` clamp then normalizes the value as before,
preserving retry-timeout semantics.

## Verification

Tested with UBSan-instrumented build (`-fsanitize=undefined`) at base
commit `46b7f689`:
- **Before**: `src/lib/ares_process.c:1156:14: runtime error: shift
exponent 64 is too large for 64-bit type 'size_t' (aka 'unsigned long')`
- **After**: No UBSan findings; harness exits cleanly (exit code 0)

Pre/post validation matrix:
| Check | Pre-patch | Post-patch |
|-------|-----------|------------|
| Build | exit 0 | exit 0 |
| Reproducer exit | exit 1 (UB triggered) | exit 0 (clean) |
| UBSan shift error | present | absent |

Reproducer: configure c-ares with a single non-responsive DNS server
(`127.0.0.1:53` with nothing listening), set `opts.tries >= 65`,
`opts.timeout = opts.maxtimeout = 1`. After 64 connection-failure
requeues through the `read_conn_packets → handle_conn_error →
ares_requeue_query → ares_send_query → ares_calc_query_timeout` path,
the UB fires without this patch.

Signed-off-by:  Song Li (@SongTonyLi)

3 of 4 new or added lines in 1 file covered. (75.0%)

1 existing line in 1 file now uncovered.

22923 of 25005 relevant lines covered (91.67%)

12965.81 hits per line

Uncovered Changes

Lines Coverage ∆ File
1
83.13
-0.08% src/lib/ares_process.c

Coverage Regressions

Lines Coverage ∆ File
1
83.56
-0.17% src/lib/record/ares_dns_parse.c
Jobs
ID Job ID Ran Files Coverage
1 28529475594.1 01 Jul 2026 03:41PM UTC 935
61.23
GitHub Action Run
Source Files on build 28529475594
  • Tree
  • List 177
  • Changed 55
  • Source Changed 0
  • Coverage Changed 55
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 4c3a6542 on github
  • Prev Build on main (#26365953021)
  • Next Build on main (#28589735398)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc