Skip to content

Instantly share code, notes, and snippets.

View josharian's full-sized avatar

Josh Bleecher Snyder josharian

View GitHub Profile
# Test commands for null byte behavior across shells
# Lines starting with # are comments and will be ignored
# Empty lines are also ignored
# Basic printf tests - these should work identically
printf "hello"
printf "before\\x00after"
printf "before\\000after"
printf "test\\x00"
printf "\\x00test"
package main
import (
"bufio"
"flag"
"fmt"
"os"
"os/exec"
"sort"
"strings"
@josharian
josharian / gist:41c71c1321a37eb58e2de9ab4c2dda58
Created July 28, 2025 00:20
test null behavior in shells
#!/bin/bash
# Test script to understand null byte behavior across different shell constructs
# Run this with different shells: bash, zsh, dash, etc.
echo "=== Shell: $0 ==="
echo "Shell version info:"
if command -v bash >/dev/null 2>&1; then
bash --version | head -1
fi
func checksumNoFoldTwoAccum(b []byte, initial uint64) uint64 {
ac := initial
var bc, bcarr uint64
var carry uint64
for len(b) >= 128 {
// add in chunks of eight up to 128
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[:8]), carry)
bc, bcarr = bits.Add64(bc, binary.BigEndian.Uint64(b[8:16]), bcarr)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[16:24]), carry)
bc, bcarr = bits.Add64(bc, binary.BigEndian.Uint64(b[24:32]), bcarr)
func checksumNoFoldBy8s(b []byte, initial uint64) uint64 {
ac := initial
var carry uint64
for len(b) >= 128 {
// add in chunks of eight up to 128
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[:8]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[8:16]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[16:24]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[24:32]), carry)
// ...
// Start Tailscale.
tssrv := &tsnet.Server{
// Silence logs completely.
// They're really verbose, and we don't have anywhere good to put them.
// This will leave us blind if/when we have Tailscale-specific issues,
// but in that case, we'll restore the logs temporarily to debug.
Logf: func(string, ...any) {},
Store: &tsDBStateStore{Q: srv.DB.Q},
AuthKey: os.Getenv("TS_AUTHKEY"),
@josharian
josharian / x.go
Created January 6, 2023 17:52
slow to compile with -race
package p
type T struct {
F float64
}
var A = [100000]*T{
2: TAKMS,
6: TAKGD,
7: TAKMS,
as a theme hint, could squeeze TRAFFIC into the fill, with all its letters circled, for "traffic circle"
diff --git a/device/device.go b/device/device.go
index 5644c8a..db017b6 100644
--- a/device/device.go
+++ b/device/device.go
@@ -44,6 +44,7 @@ type Device struct {
netlinkCancel *rwcancel.RWCancel
port uint16 // listening port
fwmark uint32 // mark value (0 = disabled)
+ brokenRoaming AtomicBool
}
package main
import (
"log"
"os"
"strings"
"github.com/goccy/go-graphviz"
"github.com/goccy/go-graphviz/cgraph"
"github.com/tailscale/hujson"