From 7fccd5de96ebf039f0098170d0db830bdaee22f2 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Fri, 3 Jan 2020 22:47:59 -0500 Subject: [PATCH] Windows requires stdin/stdout to be explicitly set to binary to avoid mangled bytes --- pegh.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pegh.c b/pegh.c index 759741f..aa57cc8 100644 --- a/pegh.c +++ b/pegh.c @@ -25,6 +25,17 @@ #include #include +#ifdef _WIN32 + +#include +#include +#include + +#define STDIN 0 +#define STDOUT 1 + +#endif + /* default of OpenSSL for now... */ #if !defined(PEGH_OPENSSL) && !defined(PEGH_LIBSODIUM) #define PEGH_OPENSSL 1 @@ -1234,6 +1245,13 @@ int main(int argc, char **argv) return exit_code; } } +#ifdef _WIN32 + else { + /* windows in/out is text and mangles certain bytes by default... */ + setmode(STDIN, O_BINARY); + } +#endif + if(NULL != out_filename) { out = fopen(out_filename, append ? "ab" : "wb"); if(!out) { @@ -1243,6 +1261,13 @@ int main(int argc, char **argv) return exit_code; } } +#ifdef _WIN32 + else { + /* windows in/out is text and mangles certain bytes by default... */ + setmode(STDOUT, O_BINARY); + } +#endif + if(decrypt) exit_code = pegh_decrypt(password, password_len, scrypt_max_mem, buffer_size, in, out, err);