StoreReference::parse("./store") eats the leading dot, yielding /store (what!) and baffling errors for relative paths in --store #479

Open
opened 2024-08-20 19:48:47 +00:00 by jade · 0 comments
Owner

Fun way of breaking Lix (and CppNix 2.24 and probably other versions) just dropped:

Step 1: Start a daemon with an apparently-illegally non-absolute store path:

NIX_DAEMON_SOCKET_PATH=$(pwd)/daemon-socket nix daemon --store ./store

Step 2: Connect to it

nix --store unix://$(pwd)/daemon-socket store ping
Store URL: unix:///home/jade/lix/devenv-haunting/daemon-socket
error:
       error: cannot open connection to remote store 'unix:///home/jade/lix/devenv-haunting/daemon-socket': error:
              error: reading from file: Connection reset by peer

Step 3: Daemon fails to make a directory it should have never been making in the first place and explodes:

unexpected Nix daemon error: error: creating directory '/store/nix/store': Permission denied

Why? It appears that StoreReference::parse returns incorrect results for ./store as a url. Note the storeURI.variant has the wrong authority, so I think the URI parser is returning garbage.

(rr) up
#13 operator() (g=..., __closure=0x7ffd42784f28) at src/libstore/store-api.cc:1324
1324	                    return implem.create(g.scheme, g.authority, params);
(rr) p g.authority
$2 = "/store"

(rr) f 20
#20 0x000075b2e6e63192 in nix::openStore (uri=..., extraParams=std::map with 1 element = {...}) at src/libstore/store-api.cc:1281
1281	    return openStore(StoreReference::parse(uri, extraParams));
(rr) f 19
#19 nix::openStore (storeURI=...) at src/libstore/store-api.cc:1328
1328	    }, storeURI.variant);
(rr) list
1323	                if (implem.uriSchemes.count(g.scheme))
1324	                    return implem.create(g.scheme, g.authority, params);
1325	
1326	            throw Error("don't know how to open Nix store with scheme '%s'", g.scheme);
1327	        },
1328	    }, storeURI.variant);
1329	
1330	    experimentalFeatureSettings.require(store->experimentalFeature());
1331	    store->warnUnknownSettings();
1332	    store->init();
(rr) p g
No symbol "g" in current context.
(rr) p storeURI.variant
$3 = std::variant<nix::StoreReference::Auto, nix::StoreReference::Specified> [index 1] = {{scheme = "local", authority = "/store"}}

Note: none of those line numbers are going to be cromulent for Lix, and maybe not even the stack trace. I did this on Nix 2.24.3, but Lix has the same bug in nix (Lix, like Nix) 2.92.0-dev-pre20240818-007211e, I just haven't bothered grabbing stacks for it.

Fun way of breaking Lix (and CppNix 2.24 and probably other versions) just dropped: Step 1: Start a daemon with an apparently-illegally non-absolute store path: ``` NIX_DAEMON_SOCKET_PATH=$(pwd)/daemon-socket nix daemon --store ./store ``` Step 2: Connect to it ``` nix --store unix://$(pwd)/daemon-socket store ping Store URL: unix:///home/jade/lix/devenv-haunting/daemon-socket error: error: cannot open connection to remote store 'unix:///home/jade/lix/devenv-haunting/daemon-socket': error: error: reading from file: Connection reset by peer ``` Step 3: Daemon fails to make a directory it should have never been making in the first place and explodes: ``` unexpected Nix daemon error: error: creating directory '/store/nix/store': Permission denied ``` Why? It appears that StoreReference::parse returns incorrect results for `./store` as a url. Note the storeURI.variant has the wrong authority, so I think the URI parser is returning garbage. ``` (rr) up #13 operator() (g=..., __closure=0x7ffd42784f28) at src/libstore/store-api.cc:1324 1324 return implem.create(g.scheme, g.authority, params); (rr) p g.authority $2 = "/store" (rr) f 20 #20 0x000075b2e6e63192 in nix::openStore (uri=..., extraParams=std::map with 1 element = {...}) at src/libstore/store-api.cc:1281 1281 return openStore(StoreReference::parse(uri, extraParams)); (rr) f 19 #19 nix::openStore (storeURI=...) at src/libstore/store-api.cc:1328 1328 }, storeURI.variant); (rr) list 1323 if (implem.uriSchemes.count(g.scheme)) 1324 return implem.create(g.scheme, g.authority, params); 1325 1326 throw Error("don't know how to open Nix store with scheme '%s'", g.scheme); 1327 }, 1328 }, storeURI.variant); 1329 1330 experimentalFeatureSettings.require(store->experimentalFeature()); 1331 store->warnUnknownSettings(); 1332 store->init(); (rr) p g No symbol "g" in current context. (rr) p storeURI.variant $3 = std::variant<nix::StoreReference::Auto, nix::StoreReference::Specified> [index 1] = {{scheme = "local", authority = "/store"}} ``` Note: none of those line numbers are going to be cromulent for Lix, and maybe not even the stack trace. I did this on Nix 2.24.3, but Lix has the same bug in `nix (Lix, like Nix) 2.92.0-dev-pre20240818-007211e`, I just haven't bothered grabbing stacks for it.
jade added the
bug
E/help wanted
labels 2024-08-20 19:48:47 +00:00
jade added the
E/reproducible
label 2024-09-26 00:41:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#479
No description provided.