Skip to content

SIGSEGV with libpq and rust:alpine3.13, but not alpine:3.13 #85

@kpcyrd

Description

@kpcyrd

I found a segfault when using postgres on the rust docker images that I can't reproduce with rustc from the official alpine images:

Binary built on alpine:* images (3.13 and edge):

foo_1  | [*] Trying to cause segfault
foo_1  | [+] No segfault! Result is: ERR (but that's ok)

Binary built on rust:alpine3.13 image:

foo_1  | [*] Trying to cause segfault
alpine-pq-repro_foo_1 exited with code 139

The debian based rust container and compiling/running it on Arch Linux works fine.

I have a minimal reproducer, to reproduce it run docker-compose up --build, the required files are:

Dockerfile

#FROM alpine:edge # works
#FROM alpine:3.13 # works
FROM rust:alpine3.13

RUN apk add cargo postgresql-dev
WORKDIR /app
COPY . .
RUN cargo build --release
ENTRYPOINT ["/app/target/release/alpine-pq-sigsegv-repro"]

src/main.rs

use diesel::PgConnection;
use diesel::Connection;

fn main() {
    println!("[*] Trying to cause segfault");
    let r = PgConnection::establish("postgres://postgres:postgres@127.0.0.1/asdf");
    println!("[+] No segfault! Result is: {}", if r.is_ok() { "OK" } else { "ERR (but that's ok)" });
}

Cargo.toml

[package]
name = "alpine-pq-sigsegv-repro"
version = "0.1.0"
authors = ["user"]
edition = "2018"

[dependencies]
diesel = { version = "1.4", features = ["postgres"] }

docker-compose.yml

---
version: "3.9"
services:
  foo:
    build: .

Cargo.lock (optional)

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "alpine-pq-sigsegv-repro"
version = "0.1.0"
dependencies = [
 "diesel",
]

[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"

[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"

[[package]]
name = "diesel"
version = "1.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "047bfc4d5c3bd2ef6ca6f981941046113524b9a9f9a7cbdfdd7ff40f58e6f542"
dependencies = [
 "bitflags",
 "byteorder",
 "diesel_derives",
 "pq-sys",
]

[[package]]
name = "diesel_derives"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "pq-sys"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
dependencies = [
 "vcpkg",
]

[[package]]
name = "proc-macro2"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
 "unicode-xid",
]

[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "syn"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-xid",
]

[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

[[package]]
name = "vcpkg"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions