| index a6308de..04cef30 100755 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | |
| 29 | 29 | SLUG="hello" |
| 30 | 30 | ID="plugin_hello" |
| 31 | -VERSION="1.1.2" | |
| 31 | +VERSION="1.1.3" | |
| 32 | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | |
| 34 | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| index 23f26e5..5579d61 100644 | ||
| --- a/src/plugin_hello.c | ||
| +++ b/src/plugin_hello.c | ||
| @@ -27,6 +27,19 @@ | ||
| 27 | 27 | #if defined(_WIN32) |
| 28 | 28 | # define WIN32_LEAN_AND_MEAN |
| 29 | 29 | # include <windows.h> |
| 30 | +# include <io.h> | |
| 31 | +# include <fcntl.h> | |
| 32 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | |
| 33 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | |
| 34 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | |
| 35 | + * header/body separator, and the entire reply (headers included) is served as | |
| 36 | + * a body. Force binary stdio before main() runs — same constructor the | |
| 37 | + * scorpiox-bot-api handlers use (sx_shell.h). */ | |
| 38 | +__attribute__((constructor)) | |
| 39 | +static void sx_plugin_binary_stdio(void) { | |
| 40 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 41 | + _setmode(_fileno(stdin), _O_BINARY); | |
| 42 | +} | |
| 30 | 43 | #else |
| 31 | 44 | # include <unistd.h> |
| 32 | 45 | # include <sys/utsname.h> |
| @@ -36,7 +49,7 @@ | ||
| 36 | 49 | |
| 37 | 50 | #define PLUGIN_SLUG "hello" |
| 38 | 51 | #define PLUGIN_ID "plugin_hello" |
| 39 | -#define PLUGIN_VER "1.1.2" | |
| 52 | +#define PLUGIN_VER "1.1.3" | |
| 40 | 53 | |
| 41 | 54 | /* ------------------------------------------------------------------ */ |
| 42 | 55 | /* Query string helpers */ |
| index 92b10dd..e70fb50 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -62,7 +62,31 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 62 | 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 65 | -check "--version prints version" '1.1.2' "$("$BIN" --version)" | |
| 65 | +check "--version prints version" '1.1.3' "$("$BIN" --version)" | |
| 66 | + | |
| 67 | +# ------------------------------------------------- CGI framing (Windows trap) | |
| 68 | +# MinGW/MSVC CRT stdout defaults to TEXT mode, which rewrites every \n into | |
| 69 | +# \r\n. A CGI header block must end with exactly CRLF CRLF; text mode turns it | |
| 70 | +# into CR CR LF CR CR LF, scorpiox-server cannot find the header/body separator, | |
| 71 | +# and the reply comes back mangled (headers inside the body, wrong Content-Type, | |
| 72 | +# truncated body, curl "Header without colon"). Live-confirmed on a real Windows | |
| 73 | +# NTFS node (2026-11-12) with the shipped 1.1.2 windows-x86_64 artifact. | |
| 74 | +section "CGI header framing (no CR CR LF)" | |
| 75 | +FRAMETMP=$(mktemp) | |
| 76 | +cgi_hex() { od -An -tx1 "$1" | tr -s ' \t\n' ' '; } | |
| 77 | +cgi_frame_check() { # cgi_frame_check <desc> <query> | |
| 78 | + BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING="$2" "$BIN" > "$FRAMETMP" | |
| 79 | + H=$(cgi_hex "$FRAMETMP") | |
| 80 | + case " $H " in *" 0d 0d 0a "*) fail "$1: found CR CR LF (text-mode stdout)"; return;; esac | |
| 81 | + case " $H " in *" 0d 0a 0d 0a "*) pass "$1: exact CRLF CRLF header separator";; | |
| 82 | + *) fail "$1: no CRLF CRLF separator found";; | |
| 83 | + esac | |
| 84 | +} | |
| 85 | +cgi_frame_check "html mode framing" "" | |
| 86 | +cgi_frame_check "embed mode framing" "embed=1" | |
| 87 | +cgi_frame_check "json mode framing" "action=info" | |
| 88 | +cgi_frame_check "echo action framing" "action=echo&msg=hi" | |
| 89 | +rm -f "$FRAMETMP" | |
| 66 | 90 | |
| 67 | 91 | # ---------------------------------------------------------------- json mode |
| 68 | 92 | section "node auth" |
| @@ -93,7 +117,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | ||
| 93 | 117 | check "info ok:true" '"ok":true' "$BODY" |
| 94 | 118 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 95 | 119 | check "info slug" '"slug":"hello"' "$BODY" |
| 96 | -check "info version" '"version":"1.1.2"' "$BODY" | |
| 120 | +check "info version" '"version":"1.1.3"' "$BODY" | |
| 97 | 121 | check "info hostname field" '"hostname"' "$BODY" |
| 98 | 122 | check "info os field" '"os"' "$BODY" |
| 99 | 123 | check "info arch field" '"arch"' "$BODY" |
| 100 | 124 |
| index a6308de..04cef30 100755 | index a6308de..04cef30 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="hello" | 29 | SLUG="hello" |
| 30 | ID="plugin_hello" | 30 | ID="plugin_hello" |
| 31 | -VERSION="1.1.2" | 31 | +VERSION="1.1.3" |
| 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | ||
| 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| index 23f26e5..5579d61 100644 | index 23f26e5..5579d61 100644 | ||
| --- a/src/plugin_hello.c | --- a/src/plugin_hello.c | ||
| +++ b/src/plugin_hello.c | +++ b/src/plugin_hello.c | ||
| @@ -27,6 +27,19 @@ | @@ -27,6 +27,19 @@ | ||
| 27 | #if defined(_WIN32) | 27 | #if defined(_WIN32) |
| 28 | # define WIN32_LEAN_AND_MEAN | 28 | # define WIN32_LEAN_AND_MEAN |
| 29 | # include <windows.h> | 29 | # include <windows.h> |
| 30 | +# include <io.h> | ||
| 31 | +# include <fcntl.h> | ||
| 32 | +/* MinGW/MSVC CRT starts stdout in TEXT mode, which rewrites every \n we emit | ||
| 33 | + * into \r\n. A CGI header block must end with exactly CRLF CRLF; text mode | ||
| 34 | + * turns "\r\n\r\n" into "\r\r\n\r\r\n", scorpiox-server cannot find the | ||
| 35 | + * header/body separator, and the entire reply (headers included) is served as | ||
| 36 | + * a body. Force binary stdio before main() runs — same constructor the | ||
| 37 | + * scorpiox-bot-api handlers use (sx_shell.h). */ | ||
| 38 | +__attribute__((constructor)) | ||
| 39 | +static void sx_plugin_binary_stdio(void) { | ||
| 40 | + _setmode(_fileno(stdout), _O_BINARY); | ||
| 41 | + _setmode(_fileno(stdin), _O_BINARY); | ||
| 42 | +} | ||
| 30 | #else | 43 | #else |
| 31 | # include <unistd.h> | 44 | # include <unistd.h> |
| 32 | # include <sys/utsname.h> | 45 | # include <sys/utsname.h> |
| @@ -36,7 +49,7 @@ | @@ -36,7 +49,7 @@ | ||
| 36 | 49 | ||
| 37 | #define PLUGIN_SLUG "hello" | 50 | #define PLUGIN_SLUG "hello" |
| 38 | #define PLUGIN_ID "plugin_hello" | 51 | #define PLUGIN_ID "plugin_hello" |
| 39 | -#define PLUGIN_VER "1.1.2" | 52 | +#define PLUGIN_VER "1.1.3" |
| 40 | 53 | ||
| 41 | /* ------------------------------------------------------------------ */ | 54 | /* ------------------------------------------------------------------ */ |
| 42 | /* Query string helpers */ | 55 | /* Query string helpers */ |
| index 92b10dd..e70fb50 100755 | index 92b10dd..e70fb50 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -62,7 +62,31 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | @@ -62,7 +62,31 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" | 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') | 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" | 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 65 | -check "--version prints version" '1.1.2' "$("$BIN" --version)" | 65 | +check "--version prints version" '1.1.3' "$("$BIN" --version)" |
| 66 | + | ||
| 67 | +# ------------------------------------------------- CGI framing (Windows trap) | ||
| 68 | +# MinGW/MSVC CRT stdout defaults to TEXT mode, which rewrites every \n into | ||
| 69 | +# \r\n. A CGI header block must end with exactly CRLF CRLF; text mode turns it | ||
| 70 | +# into CR CR LF CR CR LF, scorpiox-server cannot find the header/body separator, | ||
| 71 | +# and the reply comes back mangled (headers inside the body, wrong Content-Type, | ||
| 72 | +# truncated body, curl "Header without colon"). Live-confirmed on a real Windows | ||
| 73 | +# NTFS node (2026-11-12) with the shipped 1.1.2 windows-x86_64 artifact. | ||
| 74 | +section "CGI header framing (no CR CR LF)" | ||
| 75 | +FRAMETMP=$(mktemp) | ||
| 76 | +cgi_hex() { od -An -tx1 "$1" | tr -s ' \t\n' ' '; } | ||
| 77 | +cgi_frame_check() { # cgi_frame_check <desc> <query> | ||
| 78 | + BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING="$2" "$BIN" > "$FRAMETMP" | ||
| 79 | + H=$(cgi_hex "$FRAMETMP") | ||
| 80 | + case " $H " in *" 0d 0d 0a "*) fail "$1: found CR CR LF (text-mode stdout)"; return;; esac | ||
| 81 | + case " $H " in *" 0d 0a 0d 0a "*) pass "$1: exact CRLF CRLF header separator";; | ||
| 82 | + *) fail "$1: no CRLF CRLF separator found";; | ||
| 83 | + esac | ||
| 84 | +} | ||
| 85 | +cgi_frame_check "html mode framing" "" | ||
| 86 | +cgi_frame_check "embed mode framing" "embed=1" | ||
| 87 | +cgi_frame_check "json mode framing" "action=info" | ||
| 88 | +cgi_frame_check "echo action framing" "action=echo&msg=hi" | ||
| 89 | +rm -f "$FRAMETMP" | ||
| 66 | 90 | ||
| 67 | # ---------------------------------------------------------------- json mode | 91 | # ---------------------------------------------------------------- json mode |
| 68 | section "node auth" | 92 | section "node auth" |
| @@ -93,7 +117,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | @@ -93,7 +117,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | ||
| 93 | check "info ok:true" '"ok":true' "$BODY" | 117 | check "info ok:true" '"ok":true' "$BODY" |
| 94 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" | 118 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 95 | check "info slug" '"slug":"hello"' "$BODY" | 119 | check "info slug" '"slug":"hello"' "$BODY" |
| 96 | -check "info version" '"version":"1.1.2"' "$BODY" | 120 | +check "info version" '"version":"1.1.3"' "$BODY" |
| 97 | check "info hostname field" '"hostname"' "$BODY" | 121 | check "info hostname field" '"hostname"' "$BODY" |
| 98 | check "info os field" '"os"' "$BODY" | 122 | check "info os field" '"os"' "$BODY" |
| 99 | check "info arch field" '"arch"' "$BODY" | 123 | check "info arch field" '"arch"' "$BODY" |
| 100 | 124 |