upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-09-02 16:55:03 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-09-02 16:55:03 +0000
commit098074193b7a3147f4ad0e0424618b52fe370026 (patch)
tree44015e2cf890210f5352314d4840e2f85128176a
parentfcd0e6697038e5959df733e389124f6ccfa4a6d5 (diff)
build: quote the RandomX path so the guard cannot be stepped around
The marker guard added in fd627b1 used $(RANDOMX_DIR) unquoted, so an operator-supplied value that expands to anything other than one word walked straight past it. With a glob matching two directories, `[ -d $(RANDOMX_DIR) ]` became a two-argument test, died with "unexpected operator" rather than answering, and short-circuited the && before the marker was ever looked for -- leaving `rm -rf` to run against every match. A value holding a space or a `&&` broke the outer test the same way and reported "already built", and an apostrophe made the recipe unparseable. So the commit's claim to refuse any directory lacking the marker was falsifiable. Quote every use, and reject up front the values that cannot name one directory: empty and / now refuse deliberately rather than by way of the one-argument `[ -d ]` quirk that happened to catch them, and whitespace and glob characters are refused outright because src/Makefile interpolates the same value into -I and -L unquoted, where neither survives. A relative value is refused too: it named a different directory here than in src/, and cd'ing into it made the later mkdir -p resolve against the new cwd, so the build landed in randomx-build/randomx-build/build and cmake found nothing. Verified against the recipe text as make expands it, with rm replaced by an echo, over empty, /, globs matching one and two directories, spaces, tabs, relative paths, symlinks, apostrophes, semicolons, backticks and newlines, under both dash and bash: every run either refuses with a message or passes rm exactly one argument, identical to the path the guard tested.
-rw-r--r--Makefile40
1 files changed, 32 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 602c154..c891001 100644
--- a/Makefile
+++ b/Makefile
@@ -67,6 +67,21 @@ APPIMAGETOOL_SHA256 := ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3c
67# RANDOMX_DIR=... explicitly; the recipe below will still never delete a 67# RANDOMX_DIR=... explicitly; the recipe below will still never delete a
68# directory that lacks the marker file this build writes after a successful 68# directory that lacks the marker file this build writes after a successful
69# build. Exported so src/Makefile's own RANDOMX_DIR ?= picks the same tree. 69# build. Exported so src/Makefile's own RANDOMX_DIR ?= picks the same tree.
70#
71# Every use of it below is quoted, and the recipe rejects a value that cannot
72# name exactly one directory before it reaches anything destructive. Unquoted,
73# the marker guard could be stepped around: a value holding a glob that matches
74# two directories made `[ -d $(RANDOMX_DIR) ]` a two-argument test, which dies
75# with "unexpected operator" instead of answering, so the && short-circuited,
76# the guard was skipped, and the rm -rf below ran against every match. A value
77# holding a space or a `&&` broke the outer test the same way and reported
78# "already built". Whitespace and glob characters are refused outright rather
79# than merely quoted, because src/Makefile interpolates this same value into
80# -I$(RANDOMX_DIR)/src and -L$(RANDOMX_DIR)/build unquoted, where neither can
81# survive. A relative value is refused rather than silently made absolute: it
82# would mean two different directories to this Makefile and to src/Makefile,
83# whose cwd is src/, and a command-line assignment reaches the sub-make through
84# MAKEFLAGS, where it outranks anything exported from here.
70RANDOMX_DIR ?= $(ROOT)/randomx-build 85RANDOMX_DIR ?= $(ROOT)/randomx-build
71export RANDOMX_DIR 86export RANDOMX_DIR
72 87
@@ -126,25 +141,34 @@ deps-secp256k1:
126 fi 141 fi
127 142
128deps-randomx: 143deps-randomx:
129 @if [ ! -f $(RANDOMX_DIR)/build/librandomx.a ]; then \ 144 @ws="$$(printf ' \t')"; \
130 if [ -d $(RANDOMX_DIR) ] && [ ! -f $(RANDOMX_DIR)/.bitflash-built ]; then \ 145 case "$(RANDOMX_DIR)" in \
146 "") echo "ERROR: RANDOMX_DIR is empty"; exit 1 ;; \
147 /) echo "ERROR: RANDOMX_DIR is /, refusing"; exit 1 ;; \
148 *[$$ws]*) echo "ERROR: RANDOMX_DIR contains whitespace: $(RANDOMX_DIR)"; exit 1 ;; \
149 *[*?[]*) echo "ERROR: RANDOMX_DIR contains a glob character: $(RANDOMX_DIR)"; exit 1 ;; \
150 /*) ;; \
151 *) echo "ERROR: RANDOMX_DIR must be an absolute path: $(RANDOMX_DIR)"; exit 1 ;; \
152 esac
153 @if [ ! -f "$(RANDOMX_DIR)/build/librandomx.a" ]; then \
154 if [ -d "$(RANDOMX_DIR)" ] && [ ! -f "$(RANDOMX_DIR)/.bitflash-built" ]; then \
131 echo "ERROR: $(RANDOMX_DIR) exists but was not created by this build"; \ 155 echo "ERROR: $(RANDOMX_DIR) exists but was not created by this build"; \
132 echo " refusing to rm -rf it -- remove it yourself or set RANDOMX_DIR"; \ 156 echo " refusing to rm -rf it -- remove it yourself or set RANDOMX_DIR"; \
133 exit 1; \ 157 exit 1; \
134 fi; \ 158 fi; \
135 echo "==> building RandomX"; \ 159 echo "==> building RandomX"; \
136 rm -rf $(RANDOMX_DIR); \ 160 rm -rf "$(RANDOMX_DIR)" && \
137 git init -q $(RANDOMX_DIR); \ 161 git init -q "$(RANDOMX_DIR)" && \
138 cd $(RANDOMX_DIR) && \ 162 cd "$(RANDOMX_DIR)" && \
139 git remote add origin $(RANDOMX_REPO) && \ 163 git remote add origin $(RANDOMX_REPO) && \
140 git fetch -q --depth 1 origin $(RANDOMX_COMMIT) && \ 164 git fetch -q --depth 1 origin $(RANDOMX_COMMIT) && \
141 git checkout -q --detach FETCH_HEAD && \ 165 git checkout -q --detach FETCH_HEAD && \
142 test "$$(git rev-parse HEAD)" = "$(RANDOMX_COMMIT)" && \ 166 test "$$(git rev-parse HEAD)" = "$(RANDOMX_COMMIT)" && \
143 echo "==> RandomX pinned at $(RANDOMX_COMMIT)" && \ 167 echo "==> RandomX pinned at $(RANDOMX_COMMIT)" && \
144 mkdir -p $(RANDOMX_DIR)/build && \ 168 mkdir -p "$(RANDOMX_DIR)/build" && \
145 cd $(RANDOMX_DIR)/build && cmake .. -DCMAKE_BUILD_TYPE=Release && \ 169 cd "$(RANDOMX_DIR)/build" && cmake .. -DCMAKE_BUILD_TYPE=Release && \
146 make -j$(NPROC) randomx && \ 170 make -j$(NPROC) randomx && \
147 touch $(RANDOMX_DIR)/.bitflash-built && \ 171 touch "$(RANDOMX_DIR)/.bitflash-built" && \
148 echo "==> RandomX done"; \ 172 echo "==> RandomX done"; \
149 else \ 173 else \
150 echo "==> RandomX already built"; \ 174 echo "==> RandomX already built"; \