nandi/frqpublic Fork 0
ca5b5a3
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Tell the key buffers their size, not an offset past their end

jolt.ffi/write took (ptr type offset value) and now takes (ptr type
value offset), with the offset trailing and optional — the babashka.ffi
order, changed upstream in 4feca766. Jolt moved its own callers in that
commit; these two did not move, and nothing said so, because the arity
is still legal and both arguments are still integers.

So `(ffi/write plen :size_t 0 32)` stopped meaning "this buffer is 32
bytes" and started meaning "store 0 at offset 32" — an eight-byte write
thirty-two bytes past the end of an eight-byte block, immediately
before EVP_PKEY_get_raw_public_key. slen is the same store sixty-four
bytes out. What that cost was a heap glibc noticed later and elsewhere:
`malloc(): unaligned tcache chunk detected`, aborting inside OpenSSL's
own allocator on the TLS dial, with a backtrace that names ecx_export
and nothing of frq's.

The runtime bump two commits ago did not introduce this; it uncovered
it. read still takes its offset third, and glimmer, glimmer-vidya and
glimmer-tui call neither, so these were the only two sites.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nandi committed 2026-09-06T01:55:46-07:00 Browse files
ca5b5a3 parent: 0ee8bba
modified src/frq/msgsig.jolt +2 -2
@@ -122,7 +122,7 @@
122122 (let [pub (ffi/alloc 32)
123123 plen (ffi/alloc (ffi/sizeof :size_t))]
124124 (try
125- (ffi/write plen :size_t 0 32)
125+ (ffi/write plen :size_t 32)
126126 (when (= 1 (c-get-raw-pub pkey pub plen))
127127 (let [raw (ffi/read-array pub 32)]
128128 (reset! signer
@@ -149,7 +149,7 @@
149149 ctx (c-md-ctx-new)]
150150 (try
151151 (ffi/write-array msg bs)
152- (ffi/write slen :size_t 0 64)
152+ (ffi/write slen :size_t 64)
153153 (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey))
154154 (= 1 (c-sign ctx sig slen msg n)))
155155 (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t)))))
@@ -122,7 +122,7 @@
122 (let [pub (ffi/alloc 32)122 (let [pub (ffi/alloc 32)
123 plen (ffi/alloc (ffi/sizeof :size_t))]123 plen (ffi/alloc (ffi/sizeof :size_t))]
124 (try124 (try
125- (ffi/write plen :size_t 0 32)125+ (ffi/write plen :size_t 32)
126 (when (= 1 (c-get-raw-pub pkey pub plen))126 (when (= 1 (c-get-raw-pub pkey pub plen))
127 (let [raw (ffi/read-array pub 32)]127 (let [raw (ffi/read-array pub 32)]
128 (reset! signer128 (reset! signer
@@ -149,7 +149,7 @@
149 ctx (c-md-ctx-new)]149 ctx (c-md-ctx-new)]
150 (try150 (try
151 (ffi/write-array msg bs)151 (ffi/write-array msg bs)
152- (ffi/write slen :size_t 0 64)152+ (ffi/write slen :size_t 64)
153 (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey))153 (when (and (= 1 (c-sign-init ctx ffi/null ffi/null ffi/null pkey))
154 (= 1 (c-sign ctx sig slen msg n)))154 (= 1 (c-sign ctx sig slen msg n)))
155 (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t)))))155 (str "ed25519:" kid ":" (b64url (ffi/read-array sig (ffi/read slen :size_t)))))