fix(3p/nix/libstore): use exception instead of assertion when storepath is malformed
Previously the nix-daemon would crash if a user fed it invalid store paths for drv files. The crash was due to the changed assertion triggering. Whenever that assertion would hit the nix-daemon process along with all it's current childs (running builds from all users) would be interrupted. Before this patch: $ nix-store --realise /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.drv don't know how to build these paths: /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.drv error: unexpected end-of-file < nix-daemon terminates > With this patch: $ nix-store --realise /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.drv don't know how to build these paths: /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.drv error: path '/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.drv' is not a valid store path < nix-daemon does *NOT* terminate > Change-Id: I01c5048c8a43a8b9154bdeb781d05b7744869ec0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/981 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
		
							parent
							
								
									d06237707b
								
							
						
					
					
						commit
						1937bc8624
					
				
					 1 changed files with 11 additions and 2 deletions
				
			
		
							
								
								
									
										13
									
								
								third_party/nix/src/libstore/store-api.cc
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								third_party/nix/src/libstore/store-api.cc
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -66,8 +66,17 @@ Path Store::followLinksToStorePath(const Path& path) const {
 | 
			
		|||
 | 
			
		||||
std::string storePathToName(const Path& path) {
 | 
			
		||||
  auto base = baseNameOf(path);
 | 
			
		||||
  assert(base.size() == storePathHashLen ||
 | 
			
		||||
         (base.size() > storePathHashLen && base[storePathHashLen] == '-'));
 | 
			
		||||
 | 
			
		||||
  // The base name of the store path must be `storePathHashLen` characters long,
 | 
			
		||||
  // if it is not `storePathHashLen` long then the next character, following
 | 
			
		||||
  // the hash part, MUST be a dash (`-`).
 | 
			
		||||
  const bool hasLengthMismatch = base.size() != storePathHashLen;
 | 
			
		||||
  const bool hasInvalidSuffix =
 | 
			
		||||
      base.size() > storePathHashLen && base[storePathHashLen] != '-';
 | 
			
		||||
  if (hasLengthMismatch && hasInvalidSuffix) {
 | 
			
		||||
    throw Error(format("path '%1%' is not a valid store path") % path);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return base.size() == storePathHashLen
 | 
			
		||||
             ? ""
 | 
			
		||||
             : std::string(base, storePathHashLen + 1);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue