Skip to content
Closed

ai slop #35410

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/source-lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ on:
paths:
- "src/**/*.rs"
- "src/jsc/bindings/**"
- "packages/bun-uws/**"
- "packages/bun-usockets/**"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
- "scripts/build/**"
- "scripts/glob-sources.ts"
- "test/harness.ts"
Expand All @@ -26,6 +28,8 @@ on:
paths:
- "src/**/*.rs"
- "src/jsc/bindings/**"
- "packages/bun-uws/**"
- "packages/bun-usockets/**"
- "scripts/build/**"
- "scripts/glob-sources.ts"
- "test/harness.ts"
Expand Down
4 changes: 4 additions & 0 deletions packages/bun-uws/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// clang-format off


#include <cstdio>
#include <string>
#include <charconv>
#include <string_view>
Expand Down Expand Up @@ -418,16 +419,19 @@ struct TemplatedApp {

/* Terminate on misleading idleTimeout values */
if (behavior.idleTimeout && behavior.idleTimeout < 8) {
fputs("Error: idleTimeout must be either 0 or greater than 8!\n", stderr);
std::terminate();
}

/* Maximum idleTimeout is 16 minutes */
if (behavior.idleTimeout > 240 * 4) {
fputs("Error: idleTimeout must not be greater than 960 seconds!\n", stderr);
std::terminate();
}

/* Maximum maxLifetime is 4 hours */
if (behavior.maxLifetime > 240) {
fputs("Error: maxLifetime must not be greater than 240 minutes!\n", stderr);
Comment thread
robobun marked this conversation as resolved.
std::terminate();
}

Expand Down
2 changes: 2 additions & 0 deletions packages/bun-uws/src/HttpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "WebSocketData.h"
#include "SocketKinds.h"

#include <cstdio>
#include <string>
#include <map>
#include <string_view>
Expand Down Expand Up @@ -464,6 +465,7 @@ struct HttpContext {

/* Returning from a request handler without responding or attaching an onAborted handler is ill-use */
if (!((HttpResponse<SSL> *) s)->hasResponded() && !httpResponseData->onAborted && !httpResponseData->socketData) {
fputs("Error: Returning from a request handler without responding or attaching an abort handler is forbidden!\n", stderr);
std::terminate();
}

Expand Down
2 changes: 2 additions & 0 deletions packages/bun-uws/src/TopicTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#pragma once
#include <cstdio>
#include <map>
#include <list>
#include <unordered_set>
Expand Down Expand Up @@ -106,6 +107,7 @@ struct TopicTree {

void checkIteratingSubscriber(Subscriber *s) {
if (iteratingSubscriber == s) {
fputs("Error: WebSocket must not subscribe or unsubscribe to topics while iterating its topics!\n", stderr);
std::terminate();
}
}
Expand Down
48 changes: 48 additions & 0 deletions test/internal/source-lints/uws-terminate-diagnostic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Glob } from "bun";
import { expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import path from "node:path";

// #35256 banned <iostream> from Bun's release build and stripped the
// `std::cerr << "Error: ..."` lines ahead of each std::terminate() in bun-uws.
// Bun routes std::terminate through its own crash handler (JSCInitialize calls
// std::set_terminate), so without these writes every guard dies with the same
// generic "panic: A C++ exception occurred" and nothing names which uWS
// invariant fired. Keep every std::terminate() in bun-uws paired with a
// preceding fputs/fprintf to stderr, the replacement the shim prescribes.
test("bun-uws std::terminate() sites write a diagnostic to stderr first", async () => {
const uwsSrc = path.resolve(import.meta.dir, "..", "..", "..", "packages", "bun-uws", "src");
Comment thread
robobun marked this conversation as resolved.

let terminates = 0;
const violations: string[] = [];
const glob = new Glob("**/*.{h,hpp,cpp}");
for await (const rel of glob.scan({ cwd: uwsSrc })) {
const source = readFileSync(path.join(uwsSrc, rel), "utf8");
const lines = source.split("\n");
for (let i = 0; i < lines.length; i++) {
if (!/\bstd::terminate\s*\(\s*\)/.test(lines[i])) continue;
terminates++;
// Look back over the immediately preceding non-empty lines inside the
// same block for a stderr write.
let j = i - 1;
let ok = false;
while (j >= 0) {
const prev = lines[j].trim();
if (prev === "" || prev.startsWith("//") || prev.startsWith("/*") || prev.startsWith("*")) {
j--;
continue;
}
if (prev.endsWith("{")) break;
if (/\b(fputs|fprintf)\b.*\bstderr\b/.test(prev)) ok = true;
break;
}
if (!ok) {
violations.push(`packages/bun-uws/src/${rel}:${i + 1}`);
}
}
}

expect(terminates).toBeGreaterThan(0);
violations.sort();
expect(violations).toEqual([]);
});
Loading