You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Facade proof: "retains param 0" over-approximates a library storing its own handle in its own state (curl_easy_cleanup reported as retaining the handle it destroys) #3124
Every easy function is refused with "retains param 0 (passed to Curl_eapi_enter ..., Curl_failf ..., trc_write ..., the SSL session cache, stored)". That chain is libcurl recording its own handle in its own structures (tracing, error buffers, a session cache keyed by the handle), not the caller's object outliving its owner. curl_easy_cleanup is reported as retaining the handle it destroys, which is a contradiction the proof should catch, not emit.
Retention matters (Law 4) when the stored pointer can be read after the caller's owner is gone. A pointer to a library-owned handle stored in that handle's own state, or in state that the handle's destroyer clears, cannot outlive it. The proof should distinguish "stored where only this handle's lifetime reaches" from "stored where it escapes" and treat the destroyer's own stores as no retention.
Done when: the easy functions are not refused for this chain; a fixture C library with a self-registering handle is presented; a library that truly retains a caller pointer is still refused.
Root cause, from the report of libcurl 8.23.0 drafted with #3123's change (branch opaque-void-typedef): the chain does not end in a store. It ends at trc_write, which calls data->set.fdebug(data, ...): the handle is passed to the function in the handle's own fdebug field, the program's CURLOPT_DEBUGFUNCTION callback. The drafter reports 'passed through the function pointer field fdebug, which no unit decides' and, by Law 4, treats an undecided callee as one that may keep the pointer.
So this is not an over-approximation the proof can remove by itself: what the callee does is the callback's contract, and nothing in the package states it. The existing mechanism is a field role in the registry facts (field F of R is allocator|reallocator|deallocator, §16.2b.15). A role for a program-supplied callback whose arguments are lent for the call would decide fdebug (and fwrite_func, fread_func, fprogress, ...) by declaration, with the libcurl manual page as its citation. That is a new fact form: spec words and a C-interop safety fact, so it goes to Eric as a brief with the libcurl facts (#3143) as its first user.
curl_easy_cleanup being 'retains' is the same chain reached before its free is proven; its free goes through Curl_close(struct Curl_easy **), a second gap (a destroyer that frees through a pointer to the pointer).
Brief: a function-pointer field that holds the program's callback (#3124)
The gap. Every libcurl easy function is raw as "retains param 0": the handle reaches trc_write, which calls data->set.fdebug(data, …), the program's CURLOPT_DEBUGFUNCTION. The drafter cannot decide a call through a field, so by Law 4 it assumes the callee may keep the pointer. The same field shape decides fwrite_func, fread_func, fprogress and the rest of libcurl's callbacks.
What exists.field F of R is allocator | reallocator | deallocator | context (§31, a stated grant, never drawn from a name). §31.8.5 rule 4 already treats "a function-pointer field or global the contract gives a role" as the program's code, run on the calling thread, but no role says "this field holds the program's callback".
1. What the others do. Nothing comparable: their importers leave the field a raw pointer (from knowledge, not checked in .reference).
2. What the spec says. A callback With passes to C receives its arguments borrowed for the callback's scope (§16.2b.9: "it does not become owned because C passed a pointer, and it cannot escape the callback without stronger evidence"). So a With callback stored in such a field cannot keep the handle it is handed. A C function stored there by raw code can.
3. The proposal. One more role: field F of R is callback. It states that the only values the field holds are callbacks the program registered through a presented operation (a callback param N … clause on the setter), so a call through F lends its arguments for the call and retains none. The retention proof then treats a call through F as it treats a call of a function that keeps nothing.
It is a grant with a citation, like the other roles. Two checks keep it honest:
A function of the package that stores a package function into F contradicts the role (the proof of the store wins, §31.7).
The setter that fills F must itself be presented with a callback clause, or stay raw; a raw setter means raw code may have stored anything, and the role is then refused.
4. Mission fit. The program writes nothing; the registry states one line per callback field with the manual page as its citation. Without it libcurl's whole easy API stays raw however good the proofs get.
Prediction. Yes to the role: 70%. Your likeliest change: requiring the second check to be a proof, not a refusal.
Not covered.curl_easy_cleanup also frees through Curl_close(struct Curl_easy **), a destroyer through a pointer to the pointer. That is a separate proof gap and needs no grammar.
Ruled by Eric, 2026-11-18 (D213): yes to field F of R is callback. A null store and a whole-record copy from the same field do not contradict it; the drafter finds the setters from source and each must carry a callback clause; raw calls under unsafe do not void the role; the role says nothing about threads (the setters' callback_thread does). One fixture is required: perform on the lent handle inside the callback is refused. Implementation follows D211's, on which it builds.
With a facts file for libcurl (the field role for fdebug and curl_easy_setopt's two cases; written, on a local branch, not landed): no function is blocked on the debug-callback field (14 before), and 24 of 100 are presented safely (21 before): curl_easy_reset, curl_easy_upkeep and curl_ws_start_frame are the three.
What holds the facts file. With the role applied the proofs reach curl_easy_perform → Curl_multi_add_handle → multi_xfers_add → Curl_uint32_tbl_add: tbl->rows[key] = entry. That is a real store of the handle, into the handle's own multi (data->multi_easy, easy.c:800-827, freed by curl_easy_cleanup). The libcurl scenario's own contract states lend on curl_easy_perform, so the scenario fails against that proof. This is the question this issue opened with (a handle stored where only its own lifetime reaches), and it is with Eric as a brief: a store into a record the resource owns and its destroyer destroys is not retention.
Next blockers seen for the other functions: the share lock callback field lockfunc (set by curl_share_setopt, which stores its own next variadic argument: handled by a change now in its battery), the dispatch field cntrl, and Curl_share_lock_share.
Second library on the same question (own-state store). expat 2.10.0, read from the pinned source: XML_ParserCreate is raw because parserCreate passes the new parser to dtdCreate (xmlparse.c 8392), which passes it to poolInit and hashTableInit (8396 to 8401); each stores the parser as a back pointer in a pool or table inside the DTD, and the DTD is stored in the parser and freed by XML_ParserFree. With the producer unproven the parser is no resource, and 58 of expat's 80 raw functions say only that (XML_ParserStruct is not a value record).
So the ruling asked for curl_easy_perform (a pointer stored into a record the pointed-to resource owns and its destroyer destroys is not retained) decides expat's parser too. The printf question is the smaller one for expat.
Labelled human attn needed. The question, with two libraries now read from their pinned sources (libcurl's curl_easy_perform, expat's parser): when a library stores its own handle inside state that the same handle owns and frees, is that retention of the caller's argument? The proposed rule says no (nothing outlives the handle); it widens what the proofs accept as not kept, so it is a proof-rule decision (D51, D198), not mine.
A: a proof rule, with a fourth condition. A store of a resource's pointer is not retention when:
the store's target is a field of a record reachable only through a field of the resource's own record;
the resource's destroyer destroys that record;
no function of the package returns that record or a pointer into it, and none stores it anywhere else;
exclusivity: the owned record is held by this resource only: the field is assigned only a fresh allocation, is never copied to another resource, and the old record is destroyed if the field is overwritten.
Run the rule report-only over the 22 libraries before it changes a verdict. Label removed; this is mine.
expat 2.11.0XML_ParserStruct.m_dtd: rejected on Condition 3 (newDtd passed to retaining parserCreate:3 in XML_ExternalEntityParserCreate) and Condition 4 (assigned param:3 — DTD is shared with the parent parser).
libcurl 8.23.0Curl_easy.multi_easy: rejected on Condition 3 (cpool_get_instance returns &data->multi_easy->cpool, a pointer into multi_easy).
libevent 2.1.12evhttp_connection.bufev: rejected on Condition 2 (evhttp_connection_free does not always free it), Condition 3 (evhttp_connection_get_bufferevent returns it), and Condition 4 (assigned param:2 — caller-supplied).
libxml2 2.15.4_xmlTextReader.{ctxt, rngValidCtxt, xsdValidCtxt, xincctxt}: rejected on Conditions 3 and/or 4 (caller-supplied or escaped).
Verdict flips across the 23 libraries:0 (6170 functions, 1571 presented safely, 4599 raw — unchanged). Proceeding to land the 4-condition rule with full positive and negative unit coverage (conan_facade_self_owned_store_test.with).
Activity
ehartford commentedon Nov 11, 2026
Root cause, from the report of libcurl 8.23.0 drafted with #3123's change (branch
opaque-void-typedef): the chain does not end in a store. It ends attrc_write, which callsdata->set.fdebug(data, ...): the handle is passed to the function in the handle's ownfdebugfield, the program's CURLOPT_DEBUGFUNCTION callback. The drafter reports 'passed through the function pointer field fdebug, which no unit decides' and, by Law 4, treats an undecided callee as one that may keep the pointer.So this is not an over-approximation the proof can remove by itself: what the callee does is the callback's contract, and nothing in the package states it. The existing mechanism is a field role in the registry facts (
field F of R is allocator|reallocator|deallocator, §16.2b.15). A role for a program-supplied callback whose arguments are lent for the call would decidefdebug(andfwrite_func,fread_func,fprogress, ...) by declaration, with the libcurl manual page as its citation. That is a new fact form: spec words and a C-interop safety fact, so it goes to Eric as a brief with the libcurl facts (#3143) as its first user.curl_easy_cleanupbeing 'retains' is the same chain reached before its free is proven; its free goes throughCurl_close(struct Curl_easy **), a second gap (a destroyer that frees through a pointer to the pointer).ehartford commentedon Nov 18, 2026
Brief: a function-pointer field that holds the program's callback (#3124)
The gap. Every libcurl easy function is raw as "retains param 0": the handle reaches
trc_write, which callsdata->set.fdebug(data, …), the program'sCURLOPT_DEBUGFUNCTION. The drafter cannot decide a call through a field, so by Law 4 it assumes the callee may keep the pointer. The same field shape decidesfwrite_func,fread_func,fprogressand the rest of libcurl's callbacks.What exists.
field F of R is allocator | reallocator | deallocator | context(§31, a stated grant, never drawn from a name). §31.8.5 rule 4 already treats "a function-pointer field or global the contract gives a role" as the program's code, run on the calling thread, but no role says "this field holds the program's callback".1. What the others do. Nothing comparable: their importers leave the field a raw pointer (from knowledge, not checked in
.reference).2. What the spec says. A callback With passes to C receives its arguments borrowed for the callback's scope (§16.2b.9: "it does not become owned because C passed a pointer, and it cannot escape the callback without stronger evidence"). So a With callback stored in such a field cannot keep the handle it is handed. A C function stored there by raw code can.
3. The proposal. One more role:
field F of R is callback. It states that the only values the field holds are callbacks the program registered through a presented operation (acallback param N …clause on the setter), so a call throughFlends its arguments for the call and retains none. The retention proof then treats a call throughFas it treats a call of a function that keeps nothing.It is a grant with a citation, like the other roles. Two checks keep it honest:
Fcontradicts the role (the proof of the store wins, §31.7).Fmust itself be presented with a callback clause, or stay raw; a raw setter means raw code may have stored anything, and the role is then refused.4. Mission fit. The program writes nothing; the registry states one line per callback field with the manual page as its citation. Without it libcurl's whole easy API stays raw however good the proofs get.
Prediction. Yes to the role: 70%. Your likeliest change: requiring the second check to be a proof, not a refusal.
Not covered.
curl_easy_cleanupalso frees throughCurl_close(struct Curl_easy **), a destroyer through a pointer to the pointer. That is a separate proof gap and needs no grammar.ehartford commentedon Nov 18, 2026
Ruled by Eric, 2026-11-18 (D213): yes to
field F of R is callback. A null store and a whole-record copy from the same field do not contradict it; the drafter finds the setters from source and each must carry a callback clause; raw calls underunsafedo not void the role; the role says nothing about threads (the setters'callback_threaddoes). One fixture is required:performon the lent handle inside the callback is refused. Implementation follows D211's, on which it builds.Spec v7.63: 'buffer field P remaining field N' (D210); D213 to D216 r…
field F of R is callback: a field that holds only the program's callb…
A variadic setter's store fits the callback role when it is proven to…
A parameter passed to a call the proofs cannot name is not a proven s…
ehartford commentedon Nov 23, 2026
Progress, 2026-11-23, measured on libcurl 8.23.0 with
with getbuilding it from source (D212).Landed
curltool and the test programs no longer void proofs. "A unit of the package could not be read": 25 report lines to 0.setopt_long'ssetopt_call[i](data, option, arg)had producedcurl_easy_setopt stores 0, which was held against a statedlend.With a facts file for libcurl (the field role for
fdebugandcurl_easy_setopt's two cases; written, on a local branch, not landed): no function is blocked on the debug-callback field (14 before), and 24 of 100 are presented safely (21 before):curl_easy_reset,curl_easy_upkeepandcurl_ws_start_frameare the three.What holds the facts file. With the role applied the proofs reach
curl_easy_perform→Curl_multi_add_handle→multi_xfers_add→Curl_uint32_tbl_add:tbl->rows[key] = entry. That is a real store of the handle, into the handle's own multi (data->multi_easy,easy.c:800-827, freed bycurl_easy_cleanup). The libcurl scenario's own contract stateslendoncurl_easy_perform, so the scenario fails against that proof. This is the question this issue opened with (a handle stored where only its own lifetime reaches), and it is with Eric as a brief: a store into a record the resource owns and its destroyer destroys is not retention.Next blockers seen for the other functions: the share lock callback field
lockfunc(set bycurl_share_setopt, which stores its own next variadic argument: handled by a change now in its battery), the dispatch fieldcntrl, andCurl_share_lock_share.A variadic function that stores its own next argument is where the ar…
ehartford commentedon Nov 23, 2026
Second library on the same question (own-state store). expat 2.10.0, read from the pinned source:
XML_ParserCreateis raw becauseparserCreatepasses the new parser todtdCreate(xmlparse.c 8392), which passes it topoolInitandhashTableInit(8396 to 8401); each stores the parser as a back pointer in a pool or table inside the DTD, and the DTD is stored in the parser and freed byXML_ParserFree. With the producer unproven the parser is no resource, and 58 of expat's 80 raw functions say only that (XML_ParserStructis not a value record).So the ruling asked for
curl_easy_perform(a pointer stored into a record the pointed-to resource owns and its destroyer destroys is not retained) decides expat's parser too. Theprintfquestion is the smaller one for expat.ehartford commentedon Nov 24, 2026
Labelled
human attn needed. The question, with two libraries now read from their pinned sources (libcurl'scurl_easy_perform, expat's parser): when a library stores its own handle inside state that the same handle owns and frees, is that retention of the caller's argument? The proposed rule says no (nothing outlives the handle); it widens what the proofs accept as not kept, so it is a proof-rule decision (D51, D198), not mine.ehartford commentedon Nov 25, 2026
Ruled by Eric, 2026-11-25 (answers to briefs.md).
A: a proof rule, with a fourth condition. A store of a resource's pointer is not retention when:
Run the rule report-only over the 22 libraries before it changes a verdict. Label removed; this is mine.
ehartford commentedon Nov 27, 2026
Report-only run across the 23 buildable libraries on the #3115 list (6,170 functions, 2,500+ record-pointer fields; zero verdicts changed):
Fields passing all 4 strict conditions (
17total,0false positives):libxml2 2.15.4(7):_xmlSchemaValidCtxt.dict,_xmlSchemaValidCtxt.nodeQNames,_xmlSchemaParserCtxt.attrProhibs,_xmlSchemaValidCtxt.value,_xmlSchemaFacet.val,_xmlTextWriter.nodes,_xmlTextWriter.nsstacklibcurl 8.23.0(5):Curl_share.ssl_scache,Curl_multi.resolv_thrdq,Curl_multi.xfer_buf,Curl_multi.xfer_ulbuf,Curl_multi.xfer_sockbufraylib 6.0(5):m3d_t.inlined,m3d_t.voxel,m3d_t.shape,m3d_t.label,m3d_t.actionKey rejected fields (verified sound):
expat 2.11.0XML_ParserStruct.m_dtd: rejected on Condition 3 (newDtdpassed to retainingparserCreate:3inXML_ExternalEntityParserCreate) and Condition 4 (assigned param:3— DTD is shared with the parent parser).libcurl 8.23.0Curl_easy.multi_easy: rejected on Condition 3 (cpool_get_instancereturns&data->multi_easy->cpool, a pointer intomulti_easy).libevent 2.1.12evhttp_connection.bufev: rejected on Condition 2 (evhttp_connection_freedoes not always free it), Condition 3 (evhttp_connection_get_buffereventreturns it), and Condition 4 (assigned param:2— caller-supplied).libxml2 2.15.4_xmlTextReader.{ctxt, rngValidCtxt, xsdValidCtxt, xincctxt}: rejected on Conditions 3 and/or 4 (caller-supplied or escaped).Verdict flips across the 23 libraries:
0(6170functions,1571presented safely,4599raw — unchanged). Proceeding to land the 4-condition rule with full positive and negative unit coverage (conan_facade_self_owned_store_test.with).cimport: exempt stores of a resource pointer into its own exclusively…