Skip to content

Commit

Permalink
[infra] use $SWITCH_UID if it is defined (fixes #30)
Browse files Browse the repository at this point in the history
If #SWITCH_UID is defined, then compile script will create a user
with a given UID and switch to it prior to calling project's build.sh.
  • Loading branch information
mikea committed Dec 21, 2016
1 parent b57371a commit bbaf389
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions infra/base-images/base-libfuzzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Build configuration is performed through following environment variables:
| `$SANITIZER ("address")` | Specifies sanitizer configuration to use. `address` or `undefined`.
| `$SANITIZER_FLAGS` | Specify compiler sanitizer flags directly. Overrides `$SANITIZER`.
| `$COVERAGE_FLAGS` | Specify compiler flags to use for fuzzer feedback coverage.
| `$SWITCH_UID` | User id to use while building fuzzers.

# Examples

Expand Down
10 changes: 9 additions & 1 deletion infra/base-images/base-libfuzzer/compile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ echo "CXXFLAGS=$CXXFLAGS"

echo "---------------------------------------------------------------"

bash -x $SRC/build.sh
BUILD_CMD="bash -x $SRC/build.sh"
if [ -z "${SWITCH_UID+}" ]; then
adduser -u $SWITCH_UID --disabled-password --no-create-home --gecos '' ossfuzz
chown -R ossfuzz /src
chown ossfuzz /out
su -c "$BUILD_CMD" ossfuzz
else
$BUILD_CMD
fi
8 changes: 4 additions & 4 deletions infra/libfuzzer-pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def call(body) {
body()

def project = new groovy.json.JsonSlurperClassic().parseText(config["project_json"])
def uid = sh(returnStdout: true, script: 'id -u $USER').trim()

// Project configuration.
def projectName = project["name"] ?: env.JOB_BASE_NAME
Expand All @@ -38,15 +39,14 @@ def call(body) {
def dockerGit = dockerfileConfig["git"]
def dockerContextDir = dockerfileConfig["context"] ?: ""
def dockerTag = "ossfuzz/$projectName"
def dockerUid = 0 // TODO: try to make $USER to work
def dockerRunOptions = "--user $dockerUid --cap-add SYS_PTRACE"
def dockerUid = $uid
def dockerRunOptions = "-e SWITCH_UID=$dockerUid --cap-add SYS_PTRACE"

def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm")
.format(java.time.LocalDateTime.now())

node {
def workspace = pwd()
// def uid = sh(returnStdout: true, script: 'id -u $USER').trim()
echo "using uid $dockerUid"

def srcmapFile = "$workspace/srcmap.json"
Expand Down

0 comments on commit bbaf389

Please sign in to comment.