Skip to content

Non interactive input (pipes) makes binaries crash #52

Description

@nollium

I'm using dockerc for a simple program that takes input via STDIN.
It works well when passing data interactively (i.e: the user entering it directly in their terminal), but when using any non-interactive inputs, the dockerc generated binaries crash instantly.

POC

main.c:

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

Dockerfile:

# Build stage
FROM alpine:latest AS builder
WORKDIR /build
RUN apk add --no-cache gcc musl-dev
COPY main.c .
RUN gcc -O0 -o c-program main.c -no-pie -fno-stack-protector

# Final stage
FROM alpine:latest

WORKDIR /challenge
COPY --from=builder /build/c-program .
ENTRYPOINT ["./c-program"]

build.sh

#!/bin/bash

docker build -t test-image .
dockerc_x86-64  --image "docker-daemon:test-image:latest" --output "dockerc-program"

Output

Launching normally (works):

./dockerc-program 
newuidmap failed, falling back to single user mapping
newgidmap failed, falling back to single group mapping
unknown argument ignored: lazytime
Hello, world!

Launching with non-interactive STDIN:

cat | ./dockerc-program 
newuidmap failed, falling back to single user mapping
newgidmap failed, falling back to single group mapping
unknown argument ignored: lazytime
thread 1032321 panic: failed to run container (status/errno: 25) (-1): tcgetattr

Unwind error at address `exe:0x1083476` (error.InvalidDebugInfo), trace may be incomplete

thread 1032307 panic: container didn't exist normally : 134

Unwind error at address `exe:0x1083476` (error.InvalidDebugInfo), trace may be incomplete


Aborted (core dumped)

For the record, the normal behaviour is well implemented by docker run:

cat | sudo docker run -i test-image
Hello, world!

I havent included actual user input handling in this example to pinpoint the fact that dockerc binaries crash in all cases, but docker run -i handles it correctly too.

This crash prevents using dockerc binaries as regular "UNIX-y" command-line utilities.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions