runDoSCase runs one op under the DoS budget. A panic or a timeout exceeds the budget — either is a finding.
(t *testing.T, opName string, data []byte, fn func())
| 1685 | // runDoSCase runs one op under the DoS budget. A panic or a timeout exceeds |
| 1686 | // the budget — either is a finding. |
| 1687 | func runDoSCase(t *testing.T, opName string, data []byte, fn func()) { |
| 1688 | t.Helper() |
| 1689 | done := make(chan struct{}) |
| 1690 | start := time.Now() |
| 1691 | go func() { |
| 1692 | defer func() { |
| 1693 | if r := recover(); r != nil { |
| 1694 | t.Errorf("PANIC in %s on %d-byte input (DoS gate): %v\n%s", |
| 1695 | opName, len(data), r, debug.Stack()) |
| 1696 | } |
| 1697 | close(done) |
| 1698 | }() |
| 1699 | fn() |
| 1700 | }() |
| 1701 | select { |
| 1702 | case <-done: |
| 1703 | elapsed := time.Since(start) |
| 1704 | if elapsed > dosOpBudget { |
| 1705 | t.Errorf("%s took %v on %d-byte input (DoS budget %v exceeded)", |
| 1706 | opName, elapsed, len(data), dosOpBudget) |
| 1707 | } |
| 1708 | case <-time.After(dosOpBudget): |
| 1709 | t.Fatalf("%s hung > %v on %d-byte input (DoS regression)", |
| 1710 | opName, dosOpBudget, len(data)) |
| 1711 | } |
| 1712 | } |
no outgoing calls
no test coverage detected