Skip to content

Commit 670082f

Browse files
authored
Fix/bad varlena size (#46)
* Add cassert and debug/gdb flags for test image builder. * all the fixes for bad varhdrz usage, and switch all _P to _PP macros * fix oversized base64 decoding bug. * Add vscode include path
1 parent a8aea8e commit 670082f

24 files changed

+621
-396
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dockerfile
2+
test.sh
3+
psql.sh
4+
.dockerignore
5+
.git
6+
.cache

.vscode/c_cpp_properties.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/usr/include/postgresql/**"
8+
],
9+
"defines": [],
10+
"compilerPath": "/usr/bin/clang",
11+
"cStandard": "c17",
12+
"cppStandard": "c++14",
13+
"intelliSenseMode": "linux-clang-x64"
14+
}
15+
],
16+
"version": 4
17+
}

Dockerfile

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1+
FROM ubuntu:latest
12
ARG version
2-
FROM postgres:${version}
3-
ARG version
4-
5-
RUN apt-get update && apt-get install -y make git postgresql-server-dev-${version} curl build-essential libreadline-dev zile
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
# install base dependences
6+
RUN apt-get update && \
7+
apt-get install -y make cmake git curl build-essential m4 sudo gdbserver \
8+
gdb libreadline-dev bison flex zlib1g-dev tmux zile zip vim gawk wget
9+
10+
# add postgres user and make data dir
11+
RUN groupadd -r postgres && useradd --no-log-init -r -m -s /bin/bash -g postgres -G sudo postgres
12+
ENV PGDATA /home/postgres/data
13+
RUN /bin/rm -Rf "$PGDATA" && mkdir "$PGDATA"
14+
WORKDIR "/home/postgres"
15+
16+
# get postgres source and compile with debug and no optimization
17+
RUN git clone --branch REL_${version}_STABLE https://github.com/postgres/postgres.git --depth=1 && \
18+
cd postgres && ./configure \
19+
--prefix=/usr/ \
20+
--enable-debug \
21+
--enable-depend --enable-cassert --enable-profiling \
22+
CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" \
23+
# CFLAGS="-O3" \
24+
&& make -j 4 && make install
25+
26+
RUN chown postgres:postgres /home/postgres
27+
628
RUN curl -s -L https://github.com/theory/pgtap/archive/v1.1.0.tar.gz | tar zxvf - && cd pgtap-1.1.0 && make && make install
7-
RUN curl -s -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz | tar zxvf - && cd libsodium-1.0.18 && ./configure && make check && make install
29+
RUN curl -s -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz | tar zxvf - && cd libsodium-1.0.18 && ./configure && make check && make -j 4 install
830
RUN cpan App::cpanminus && cpan TAP::Parser::SourceHandler::pgTAP
9-
RUN mkdir "/pgsodium"
10-
WORKDIR "/pgsodium"
31+
RUN mkdir "/home/postgres/pgsodium"
32+
WORKDIR "/home/postgres/pgsodium"
1133
COPY . .
1234
RUN make -j 4 && make install
1335
RUN ldconfig
@@ -16,3 +38,17 @@ RUN cp getkey_scripts/pgsodium_getkey_urandom.sh `pg_config --sharedir`/extensio
1638
RUN sed -i 's/exit//g' `pg_config --sharedir`/extension/pgsodium_getkey
1739
RUN chmod +x `pg_config --sharedir`/extension/pgsodium_getkey
1840
RUN cp `pg_config --sharedir`/extension/pgsodium_getkey /getkey
41+
42+
# chown just pggraphblas
43+
RUN chown -R postgres:postgres /home/postgres/pgsodium
44+
RUN chown -R postgres:postgres /home/postgres/data
45+
46+
# make postgres a sudoer
47+
RUN echo "postgres ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user && \
48+
chmod 0440 /etc/sudoers.d/user
49+
50+
# start the database
51+
USER postgres
52+
RUN initdb -D "$PGDATA"
53+
EXPOSE 5432
54+
CMD ["/usr/bin/postgres"]

pgsodium.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pgsodium extension
22
comment = 'Postgres extension for libsodium functions'
3-
default_version = '3.0.7'
3+
default_version = '3.0.8'
44
relocatable = false
55
schema = pgsodium

psql.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ docker run \
1717
-p $EXPORT:5432 \
1818
-v `pwd`/example:/pgsodium/example \
1919
-e POSTGRES_HOST_AUTH_METHOD=trust \
20-
-d --name "$DB_HOST" $TAG $CONFIG
20+
-d --name "$DB_HOST" $TAG postgres $CONFIG
2121

2222
echo waiting for database to accept connections
2323
until

sql/pgsodium--1.0.0--1.1.0.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ RETURNS bytea
6262
AS '$libdir/pgsodium', 'pgsodium_randombytes_buf_deterministic'
6363
LANGUAGE C IMMUTABLE STRICT;
6464

65-
66-
-- Marc's hacks follow
67-
6865
CREATE FUNCTION crypto_sign_init()
6966
RETURNS bytea
7067
AS '$libdir/pgsodium', 'pgsodium_crypto_sign_init'

sql/pgsodium--3.0.7--3.0.8.sql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CREATE OR REPLACE FUNCTION pgsodium.crypto_sign_update_agg1(state bytea, message bytea)
2+
RETURNS bytea
3+
AS
4+
$$
5+
SELECT pgsodium.crypto_sign_update(COALESCE(state, pgsodium.crypto_sign_init()), message);
6+
$$
7+
LANGUAGE SQL IMMUTABLE;
8+
9+
COMMENT ON FUNCTION pgsodium.crypto_sign_update_agg1(bytea, bytea) IS
10+
'Internal helper function for crypto_sign_update_agg(bytea). This
11+
initializes state if it has not already been initialized.';
12+
13+
CREATE OR REPLACE FUNCTION pgsodium.crypto_sign_update_agg2(cur_state bytea,
14+
initial_state bytea,
15+
message bytea)
16+
RETURNS bytea
17+
as
18+
$$
19+
SELECT pgsodium.crypto_sign_update(
20+
COALESCE(cur_state, initial_state),
21+
message)
22+
$$
23+
LANGUAGE SQL IMMUTABLE;
24+
25+
COMMENT ON FUNCTION pgsodium.crypto_sign_update_agg2(bytea, bytea, bytea) IS
26+
'Internal helper function for crypto_sign_update_agg(bytea, bytea). This
27+
initializes state to the state passed to the aggregate as a parameter,
28+
if it has not already been initialized.';
29+
30+
CREATE OR REPLACE AGGREGATE pgsodium.crypto_sign_update_agg(message bytea)
31+
(
32+
SFUNC = pgsodium.crypto_sign_update_agg1,
33+
STYPE = bytea,
34+
PARALLEL = unsafe);
35+
36+
COMMENT ON AGGREGATE pgsodium.crypto_sign_update_agg(bytea) IS
37+
'Multi-part message signing aggregate that returns a state which can
38+
then be finalised using crypto_sign_final() or to which other parts
39+
can be added crypto_sign_update() or another message signing aggregate
40+
function.
41+
42+
Note that when signing mutli-part messages using aggregates, the order
43+
in which message parts is processed is critical. You *must* ensure
44+
that the order of messages passed to the aggregate is invariant.';
45+
46+
CREATE OR REPLACE AGGREGATE pgsodium.crypto_sign_update_agg(state bytea, message bytea)
47+
(
48+
SFUNC = pgsodium.crypto_sign_update_agg2,
49+
STYPE = bytea,
50+
PARALLEL = unsafe);
51+
52+
COMMENT ON AGGREGATE pgsodium.crypto_sign_update_agg(bytea, bytea) IS
53+
'Multi-part message signing aggregate that returns a state which can
54+
then be finalised using crypto_sign_final() or to which other parts
55+
can be added crypto_sign_update() or another message signing aggregate
56+
function.
57+
58+
The first argument to this aggregate is the input state. This may be
59+
the result of a previous crypto_sign_update_agg(), a previous
60+
crypto_sign_update().
61+
62+
Note that when signing mutli-part messages using aggregates, the order
63+
in which message parts is processed is critical. You *must* ensure
64+
that the order of messages passed to the aggregate is invariant.';
65+

0 commit comments

Comments
 (0)