Re: Non-compliant SASLprep implementation for ASCII characters - Mailing list pgsql-hackers
| From | Alexander Lakhin |
|---|---|
| Subject | Re: Non-compliant SASLprep implementation for ASCII characters |
| Date | |
| Msg-id | 09df9d75-13e7-45fe-89af-33fe118e797b@gmail.com Whole thread Raw |
| In response to | Re: Non-compliant SASLprep implementation for ASCII characters (Michael Paquier <michael@paquier.xyz>) |
| Responses |
Re: Non-compliant SASLprep implementation for ASCII characters
|
| List | pgsql-hackers |
Hello Michael,
19.03.2026 06:25, Michael Paquier wrote:
19.03.2026 06:25, Michael Paquier wrote:
Applied the result for the module, to have at least the coverage part. The last piece is refreshed, and attached for now. --
When running make check for src/test/modules/test_saslprep under Valgrind,
I've discovered:
# --- /pgtest/postgresql.git/src/test/modules/test_saslprep/expected/test_saslprep.out 2026-04-12 07:44:47.090517505 +0300
# +++ /pgtest/postgresql.git/src/test/modules/test_saslprep/results/test_saslprep.out 2026-04-12 08:03:29.353348951 +0300
# @@ -2,151 +2,7 @@
# CREATE EXTENSION test_saslprep;
# -- Incomplete UTF-8 sequence.
# SELECT test_saslprep('\xef');
# - test_saslprep
# ------------------
# - (,INVALID_UTF8)
# -(1 row)
# -
...
-
-DROP EXTENSION test_saslprep;
+server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+connection to server was lost
src/test/modules/test_saslprep/log/postmaster.log
2026-04-12 08:03:26.064 EEST postmaster[1043298] LOG: database system is ready to accept connections
2026-04-12 08:03:26.078 EEST dead-end client backend[1043325] [unknown] FATAL: the database system is starting up
==00:00:00:04.413 1043360== Invalid read of size 1
==00:00:00:04.413 1043360== at 0x484F234: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:00:04.413 1043360== by 0x5277C6F: strlcpy (strlcpy.c:24)
==00:00:00:04.413 1043360== by 0x48648CF: test_saslprep (test_saslprep.c:87)
==00:00:00:04.413 1043360== by 0x541A45: ExecInterpExpr (execExprInterp.c:979)
==00:00:00:04.413 1043360== by 0x5446A1: ExecInterpExprStillValid (execExprInterp.c:2301)
==00:00:00:04.413 1043360== by 0x5AD1FD: ExecEvalExprNoReturn (executor.h:433)
==00:00:00:04.413 1043360== by 0x5AD2BB: ExecEvalExprNoReturnSwitchContext (executor.h:474)
==00:00:00:04.413 1043360== by 0x5AD31C: ExecProject (executor.h:506)
==00:00:00:04.413 1043360== by 0x5AD53F: ExecResult (nodeResult.c:135)
==00:00:00:04.413 1043360== by 0x55F5E4: ExecProcNodeFirst (execProcnode.c:469)
==00:00:00:04.413 1043360== by 0x55108F: ExecProcNode (executor.h:327)
==00:00:00:04.413 1043360== by 0x554149: ExecutePlan (execMain.c:1736)
==00:00:00:04.413 1043360== Address 0x7439295 is 6,917 bytes inside a block of size 8,192 alloc'd
==00:00:00:04.413 1043360== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:00:04.413 1043360== by 0xADBE27: AllocSetContextCreateInternal (aset.c:444)
==00:00:00:04.413 1043360== by 0x762E31: PostmasterMain (postmaster.c:534)
==00:00:00:04.413 1043360== by 0x5E9543: main (main.c:231)
==00:00:00:04.413 1043360==
...
==00:00:00:04.413 1043360==
==00:00:00:04.414 1043360== Exit program on first error (--exit-on-first-error=yes)
2026-04-12 08:03:29.349 EEST postmaster[1043298] LOG: client backend (PID 1043360) exited with exit code 1
2026-04-12 08:03:29.349 EEST postmaster[1043298] DETAIL: Failed process was running: SELECT test_saslprep('\xef');
The corresponding code:
src_len = VARSIZE_ANY_EXHDR(string);
src = VARDATA_ANY(string);
/*
* Copy the input given, to make SASLprep() act on a sanitized string.
*/
input_data = palloc0(src_len + 1);
strlcpy(input_data, src, src_len + 1);
That is, strlcpy() tries to evaluate strlen() for src, which contains only
one byte without null terminator.
skink tests this module successfully [1] by some reason:
================================== 151/394 ===================================
test: test_saslprep - postgresql:test_saslprep/regress
start time: 13:26:00
duration: 8.04s
result: exit status 0
command: ...
----------------------------------- stdout -----------------------------------
# executing test in /home/bf/bf-build/skink-master/HEAD/pgsql.build/testrun/test_saslprep/regress group test_saslprep test regress
# initializing database system by copying initdb template
# using temp instance on port 40096 with PID 3982971
ok 1 - test_saslprep 1971 ms
1..1
# All 1 tests passed.
# test succeeded
[1] https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=skink&dt=2026-04-11%2011%3A31%3A01&stg=misc-check
Best regards,
Alexander
pgsql-hackers by date: