commit 360daa99554be2386ca5389c631281bac42eb1de
parent 15a2dc79c34c2a9d6634f1a92b12d44f4b62bbcd
Author: Louis Burda <quent.burda@gmail.com>
Date: Wed, 2 Jun 2021 00:05:56 +0200
apply patches through PATCHED=1 env var during cleansrc
Diffstat:
5 files changed, 25 insertions(+), 47 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,4 +0,0 @@
-data/*
-!data/.keep
-.cleansrc
-src/.safebuild
diff --git a/do.sh b/do.sh
@@ -1,14 +1,15 @@
#!/bin/sh
+REPOROOT="$(git rev-parse --show-toplevel)"
SCRIPTPATH="$(dirname $(readlink -f "$0"))"
cd "$SCRIPTPATH"
makefile="
-all: .cleansrc
+all: service/.copyts
-.cleansrc: src/*
+service/.copyts: src/*
bash do.sh cleansrc src service/src
- touch .cleansrc
+ touch service/.copyts
"
shopt -s expand_aliases
@@ -51,40 +52,23 @@ elif [ "$1" == "cleansrc" ]; then
fi
fi
done
+
+ # apply patches if requested
+ if [ ! -z "$PATCHED" ]; then
+ pushd "$dst"
+ git apply "$REPOROOT/src/patches/"*.diff
+ popd
+ fi
elif [ "$1" == "test" ]; then
SRCDIR="$PWD/src" DATADIR="$PWD/service/data" bash "tests/test.sh" ${@:2}
elif [ "$1" == "make" ]; then
- # build a normal version
- pushd src
- if [ -e ".safebuild" ]; then
- make clean
- rm ".safebuild"
- fi
- make
- popd
-elif [ "$1" == "make-safe" ]; then
- # build a 'safe' version with flagstore patches
-
- pushd src
- make clean
- touch ".safebuild"
-
- for f in $(ls | grep '\.[ch]$'); do
- cp "$f" "safe_$f"
- done
-
- git apply patches/flagstore1.diff
- git apply patches/flagstore2.diff
-
- PREFIX="safe_" make
-
- rm safe_*
- popd
+ make -C src
else
- echo "USAGE: do.sh (compose) [args..]"
+ echo "USAGE: do.sh (compose|test|cleansrc) [args..]"
echo "EXAMPLES:"
- echo " do.sh compose up --build # starts the docker container"
- echo " do.sh cleansrc <src> <dst> # post-process source files for release"
- echo " do.sh make-safe # create patched version of binary"
- echo " do.sh test <cmd> # run a test on the binary"
+ echo " do.sh compose up --build # setup src and start the container"
+ echo " do.sh test stl-upload test.stl # test the upload of STL files"
+ echo " do.sh make # build local binary in src"
+ echo " do.sh cleansrc <src> <dst> # post-process source files for release"
+ echo " # if \$PATCHED is set, patches are applied"
fi
diff --git a/service/.gitignore b/service/.gitignore
@@ -1,2 +1,3 @@
data/*
!data/.keep
+.copyts
diff --git a/src/patches/flagstore1.diff b/src/patches/flagstore1.diff
@@ -1,14 +1,11 @@
---- a/service/src/safe_util.c
-+++ b/service/src/safe_util.c
-@@ -78,13 +78,12 @@ void
+--- a/service/src/util.c
++++ b/service/src/util.c
+@@ -78,10 +78,9 @@ void
freadstr(FILE *f, char **dst)
{
size_t start, len, tmp;
- char c;
- /* VULN #1: BAD CAST */
- /* see documentation/README.md for more details */
-
start = ftell(f);
- for (len = 0; (c = fgetc(f)) != EOF && c; len++);
+ for (len = 0; fgetc(f) > 0; len++);
diff --git a/src/patches/flagstore2.diff b/src/patches/flagstore2.diff
@@ -1,8 +1,8 @@
---- a/service/src/safe_util.c
-+++ b/service/src/safe_util.c
+--- a/service/src/util.c
++++ b/service/src/util.c
@@ -58,7 +58,7 @@ mhash(const char *str, int len)
- srand(v);
+ srand(v);
for (bp = buf, i = 0; i < MHASHLEN / 2; i++)
- bp += sprintf(bp, "%02x", str[i % len] ^ (rand() % 256));
+ bp += sprintf(bp, "%02x", (unsigned char) str[i % len] ^ (rand() % 256));