Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e594de784657
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 23a97b0079cf
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Feb 17, 2021

  1. Use Boost's regex implementation instead of libstdc++'s

    The latter runs in unbounded stack space so it crashes on large
    inputs.
    
    Fixes #4550.
    edolstra committed Feb 17, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    shlevy Shea Levy
    Copy the full SHA
    23a97b0 View commit details
Showing with 18 additions and 13 deletions.
  1. +1 −1 flake.nix
  2. +6 −0 src/libutil/regex.hh
  3. +10 −11 src/nix/develop.cc
  4. +1 −1 src/nix/local.mk
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@
# Copy libboost_context so we don't get all of Boost in our closure.
# https://github.com/NixOS/nixpkgs/issues/45462
mkdir -p $out/lib
cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*,libboost_regex*} $out/lib
rm -f $out/lib/*.a
${lib.optionalString stdenv.isLinux ''
chmod u+w $out/lib/*.so.*
6 changes: 6 additions & 0 deletions src/libutil/regex.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <boost/regex.hpp>

namespace regex = boost;

21 changes: 10 additions & 11 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
@@ -6,8 +6,7 @@
#include "derivations.hh"
#include "affinity.hh"
#include "progress-bar.hh"

#include <regex>
#include "regex.hh"

using namespace nix;

@@ -64,42 +63,42 @@ BuildEnvironment readEnvironment(const Path & path)
static std::string indexedArrayRegex =
R"re((?:\(( *\[[0-9]+\]="(?:[^"\\]|\\.)*")*\)))re";

static std::regex declareRegex(
static regex::regex declareRegex(
"^declare -a?x (" + varNameRegex + ")(=(" +
dquotedStringRegex + "|" + indexedArrayRegex + "))?\n");

static std::regex varRegex(
static regex::regex varRegex(
"^(" + varNameRegex + ")=(" + simpleStringRegex + "|" + squotedStringRegex + "|" + indexedArrayRegex + ")\n");

/* Note: we distinguish between an indexed and associative array
using the space before the closing parenthesis. Will
undoubtedly regret this some day. */
static std::regex assocArrayRegex(
static regex::regex assocArrayRegex(
"^(" + varNameRegex + ")=" + R"re((?:\(( *\[[^\]]+\]="(?:[^"\\]|\\.)*")* *\)))re" + "\n");

static std::regex functionRegex(
static regex::regex functionRegex(
"^" + varNameRegex + " \\(\\) *\n");

while (pos != file.end()) {

std::smatch match;
regex::smatch match;

if (std::regex_search(pos, file.cend(), match, declareRegex, std::regex_constants::match_continuous)) {
if (regex::regex_search(pos, file.cend(), match, declareRegex, regex::regex_constants::match_continuous)) {
pos = match[0].second;
exported.insert(match[1]);
}

else if (std::regex_search(pos, file.cend(), match, varRegex, std::regex_constants::match_continuous)) {
else if (regex::regex_search(pos, file.cend(), match, varRegex, regex::regex_constants::match_continuous)) {
pos = match[0].second;
res.env.insert({match[1], Var { .exported = exported.count(match[1]) > 0, .quoted = match[2] }});
}

else if (std::regex_search(pos, file.cend(), match, assocArrayRegex, std::regex_constants::match_continuous)) {
else if (regex::regex_search(pos, file.cend(), match, assocArrayRegex, regex::regex_constants::match_continuous)) {
pos = match[0].second;
res.env.insert({match[1], Var { .associative = true, .quoted = match[2] }});
}

else if (std::regex_search(pos, file.cend(), match, functionRegex, std::regex_constants::match_continuous)) {
else if (regex::regex_search(pos, file.cend(), match, functionRegex, regex::regex_constants::match_continuous)) {
res.bashFunctions = std::string(pos, file.cend());
break;
}
2 changes: 1 addition & 1 deletion src/nix/local.mk
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libexpr

nix_LIBS = libexpr libmain libfetchers libstore libutil libcmd

nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -llowdown
nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -llowdown -lboost_regex

$(foreach name, \
nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-hash nix-instantiate nix-prefetch-url nix-shell nix-store, \