| index 36a4b4b..7db68de 100755 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | |
| 29 | 29 | SLUG="sqlite" |
| 30 | 30 | ID="plugin_sqlite" |
| 31 | -VERSION="1.0.2" | |
| 31 | +VERSION="1.0.3" | |
| 32 | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | |
| 34 | 34 | # Compile flags for the vendored SQLite amalgamation. |
| index 3e0d49b..bae1882 100644 | ||
| --- a/src/plugin_sqlite.c | ||
| +++ b/src/plugin_sqlite.c | ||
| @@ -49,6 +49,30 @@ | ||
| 49 | 49 | # include <windows.h> |
| 50 | 50 | # include <direct.h> |
| 51 | 51 | # include <io.h> |
| 52 | +# include <fcntl.h> | |
| 53 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | |
| 54 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | |
| 55 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | |
| 56 | + * header/body separator, and the whole reply (headers included) is served as a | |
| 57 | + * body with Content-Type: text/html. Force binary stdio before main() runs — | |
| 58 | + * the same constructor scorpiox-bot-api handlers use (sx_shell.h). */ | |
| 59 | +__attribute__((constructor)) | |
| 60 | +static void sx_plugin_binary_stdio(void) { | |
| 61 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 62 | + _setmode(_fileno(stdin), _O_BINARY); | |
| 63 | +} | |
| 64 | +# include <fcntl.h> | |
| 65 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | |
| 66 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | |
| 67 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | |
| 68 | + * header/body separator, and the whole reply (headers included) is served as a | |
| 69 | + * body with Content-Type: text/html. Force binary stdio before main() runs — | |
| 70 | + * the same constructor scorpiox-bot-api handlers use (sx_shell.h). */ | |
| 71 | +__attribute__((constructor)) | |
| 72 | +static void sx_plugin_binary_stdio(void) { | |
| 73 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 74 | + _setmode(_fileno(stdin), _O_BINARY); | |
| 75 | +} | |
| 52 | 76 | # include <sys/stat.h> |
| 53 | 77 | # define SX_STAT struct _stat64 |
| 54 | 78 | # define sx_stat(p,s) _stat64((p),(s)) |
| @@ -73,7 +97,7 @@ | ||
| 73 | 97 | |
| 74 | 98 | #define PLUGIN_SLUG "sqlite" |
| 75 | 99 | #define PLUGIN_ID "plugin_sqlite" |
| 76 | -#define PLUGIN_VER "1.0.2" | |
| 100 | +#define PLUGIN_VER "1.0.3" | |
| 77 | 101 | |
| 78 | 102 | #define MAX_NAME 256 |
| 79 | 103 | /* glibc's fortified realpath() demands a PATH_MAX-sized buffer. */ |
| index cf5f2a5..d782f7b 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -108,7 +108,29 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 108 | 108 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 109 | 109 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 110 | 110 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 111 | -check "--version prints version" '1.0.2' "$("$BIN" --version)" | |
| 111 | +check "--version prints version" '1.0.3' "$("$BIN" --version)" | |
| 112 | + | |
| 113 | +# ------------------------------------------------- CGI framing (Windows trap) | |
| 114 | +# MinGW/MSVC CRT stdout defaults to TEXT mode, rewriting every \n into \r\n. | |
| 115 | +# A CGI header block must end with exactly CRLF CRLF; text mode yields | |
| 116 | +# CR CR LF CR CR LF, scorpiox-server cannot find the header/body separator and | |
| 117 | +# the reply comes back mangled. Live-confirmed on a Windows NTFS node | |
| 118 | +# (2026-11-12) with the shipped 1.0.2 windows-x86_64 artifact. | |
| 119 | +section "CGI header framing (no CR CR LF)" | |
| 120 | +FRAMETMP=$(mktemp) | |
| 121 | +cgi_hex() { od -An -tx1 "$1" | tr -s ' \t\n' ' '; } | |
| 122 | +cgi_frame_check() { # cgi_frame_check <desc> <query> | |
| 123 | + BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING="$2" "$BIN" > "$FRAMETMP" | |
| 124 | + H=$(cgi_hex "$FRAMETMP") | |
| 125 | + case " $H " in *" 0d 0d 0a "*) fail "$1: found CR CR LF (text-mode stdout)"; return;; esac | |
| 126 | + case " $H " in *" 0d 0a 0d 0a "*) pass "$1: exact CRLF CRLF header separator";; | |
| 127 | + *) fail "$1: no CRLF CRLF separator found";; | |
| 128 | + esac | |
| 129 | +} | |
| 130 | +cgi_frame_check "html mode framing" "" | |
| 131 | +cgi_frame_check "dbs action framing" "action=dbs" | |
| 132 | +cgi_frame_check "info action framing" "action=info" | |
| 133 | +rm -f "$FRAMETMP" | |
| 112 | 134 | check "--version names the sqlite lib" 'sqlite 3.' "$("$BIN" --version)" |
| 113 | 135 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 114 | 136 | META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta) |
| 115 | 137 |
| index 36a4b4b..7db68de 100755 | index 36a4b4b..7db68de 100755 | ||
| --- a/release-dist.sh | --- a/release-dist.sh | ||
| +++ b/release-dist.sh | +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | ||
| 29 | SLUG="sqlite" | 29 | SLUG="sqlite" |
| 30 | ID="plugin_sqlite" | 30 | ID="plugin_sqlite" |
| 31 | -VERSION="1.0.2" | 31 | +VERSION="1.0.3" |
| 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | ||
| 34 | # Compile flags for the vendored SQLite amalgamation. | 34 | # Compile flags for the vendored SQLite amalgamation. |
| index 3e0d49b..bae1882 100644 | index 3e0d49b..bae1882 100644 | ||
| --- a/src/plugin_sqlite.c | --- a/src/plugin_sqlite.c | ||
| +++ b/src/plugin_sqlite.c | +++ b/src/plugin_sqlite.c | ||
| @@ -49,6 +49,30 @@ | @@ -49,6 +49,30 @@ | ||
| 49 | # include <windows.h> | 49 | # include <windows.h> |
| 50 | # include <direct.h> | 50 | # include <direct.h> |
| 51 | # include <io.h> | 51 | # include <io.h> |
| 52 | +# include <fcntl.h> | ||
| 53 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | ||
| 54 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | ||
| 55 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | ||
| 56 | + * header/body separator, and the whole reply (headers included) is served as a | ||
| 57 | + * body with Content-Type: text/html. Force binary stdio before main() runs — | ||
| 58 | + * the same constructor scorpiox-bot-api handlers use (sx_shell.h). */ | ||
| 59 | +__attribute__((constructor)) | ||
| 60 | +static void sx_plugin_binary_stdio(void) { | ||
| 61 | + _setmode(_fileno(stdout), _O_BINARY); | ||
| 62 | + _setmode(_fileno(stdin), _O_BINARY); | ||
| 63 | +} | ||
| 64 | +# include <fcntl.h> | ||
| 65 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | ||
| 66 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | ||
| 67 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | ||
| 68 | + * header/body separator, and the whole reply (headers included) is served as a | ||
| 69 | + * body with Content-Type: text/html. Force binary stdio before main() runs — | ||
| 70 | + * the same constructor scorpiox-bot-api handlers use (sx_shell.h). */ | ||
| 71 | +__attribute__((constructor)) | ||
| 72 | +static void sx_plugin_binary_stdio(void) { | ||
| 73 | + _setmode(_fileno(stdout), _O_BINARY); | ||
| 74 | + _setmode(_fileno(stdin), _O_BINARY); | ||
| 75 | +} | ||
| 52 | # include <sys/stat.h> | 76 | # include <sys/stat.h> |
| 53 | # define SX_STAT struct _stat64 | 77 | # define SX_STAT struct _stat64 |
| 54 | # define sx_stat(p,s) _stat64((p),(s)) | 78 | # define sx_stat(p,s) _stat64((p),(s)) |
| @@ -73,7 +97,7 @@ | @@ -73,7 +97,7 @@ | ||
| 73 | 97 | ||
| 74 | #define PLUGIN_SLUG "sqlite" | 98 | #define PLUGIN_SLUG "sqlite" |
| 75 | #define PLUGIN_ID "plugin_sqlite" | 99 | #define PLUGIN_ID "plugin_sqlite" |
| 76 | -#define PLUGIN_VER "1.0.2" | 100 | +#define PLUGIN_VER "1.0.3" |
| 77 | 101 | ||
| 78 | #define MAX_NAME 256 | 102 | #define MAX_NAME 256 |
| 79 | /* glibc's fortified realpath() demands a PATH_MAX-sized buffer. */ | 103 | /* glibc's fortified realpath() demands a PATH_MAX-sized buffer. */ |
| index cf5f2a5..d782f7b 100755 | index cf5f2a5..d782f7b 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -108,7 +108,29 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | @@ -108,7 +108,29 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 108 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" | 108 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 109 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') | 109 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 110 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" | 110 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 111 | -check "--version prints version" '1.0.2' "$("$BIN" --version)" | 111 | +check "--version prints version" '1.0.3' "$("$BIN" --version)" |
| 112 | + | ||
| 113 | +# ------------------------------------------------- CGI framing (Windows trap) | ||
| 114 | +# MinGW/MSVC CRT stdout defaults to TEXT mode, rewriting every \n into \r\n. | ||
| 115 | +# A CGI header block must end with exactly CRLF CRLF; text mode yields | ||
| 116 | +# CR CR LF CR CR LF, scorpiox-server cannot find the header/body separator and | ||
| 117 | +# the reply comes back mangled. Live-confirmed on a Windows NTFS node | ||
| 118 | +# (2026-11-12) with the shipped 1.0.2 windows-x86_64 artifact. | ||
| 119 | +section "CGI header framing (no CR CR LF)" | ||
| 120 | +FRAMETMP=$(mktemp) | ||
| 121 | +cgi_hex() { od -An -tx1 "$1" | tr -s ' \t\n' ' '; } | ||
| 122 | +cgi_frame_check() { # cgi_frame_check <desc> <query> | ||
| 123 | + BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING="$2" "$BIN" > "$FRAMETMP" | ||
| 124 | + H=$(cgi_hex "$FRAMETMP") | ||
| 125 | + case " $H " in *" 0d 0d 0a "*) fail "$1: found CR CR LF (text-mode stdout)"; return;; esac | ||
| 126 | + case " $H " in *" 0d 0a 0d 0a "*) pass "$1: exact CRLF CRLF header separator";; | ||
| 127 | + *) fail "$1: no CRLF CRLF separator found";; | ||
| 128 | + esac | ||
| 129 | +} | ||
| 130 | +cgi_frame_check "html mode framing" "" | ||
| 131 | +cgi_frame_check "dbs action framing" "action=dbs" | ||
| 132 | +cgi_frame_check "info action framing" "action=info" | ||
| 133 | +rm -f "$FRAMETMP" | ||
| 112 | check "--version names the sqlite lib" 'sqlite 3.' "$("$BIN" --version)" | 134 | check "--version names the sqlite lib" 'sqlite 3.' "$("$BIN" --version)" |
| 113 | check "--help is available" 'usage:' "$("$BIN" --help)" | 135 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 114 | META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta) | 136 | META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta) |
| 115 | 137 |