X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ab494c1e3eafc27c84c8cf0eb5e5ad8ef37389bc..cad325f5f0516da6b1d1d44c509ce194e2f08f46:/stglibs/crypto.lib/blowfish.c

diff --git a/stglibs/crypto.lib/blowfish.c b/stglibs/crypto.lib/blowfish.c
index e11bb1a2..951f4816 100644
--- a/stglibs/crypto.lib/blowfish.c
+++ b/stglibs/crypto.lib/blowfish.c
@@ -8,7 +8,7 @@
 #include <string.h>
 
 #include "stg/const.h"
-#include "blowfish.h"
+#include "stg/blowfish.h"
 
 #define ENCRYPT 0
 #define DECRYPT 1
@@ -16,6 +16,8 @@
 #define endianBig ((unsigned char) 0x45)
 #define endianLittle ((unsigned char) 0x54)
 
+#define MIN(a,b) ((a) < (b) ? a : b)
+
 #ifdef WIN32 /* Win32 doesn't have random() or lstat */
     #define random() rand()
     #define initstate(x,y,z) srand(x)
@@ -27,7 +29,7 @@
 #endif
 
 
-#define N               16
+#define N 16
 
 static uint32_t F(BLOWFISH_CTX *ctx, uint32_t x);
 static const uint32_t ORIG_P[16 + 2] = {
@@ -435,13 +437,13 @@ for (i = 0; i < 4; ++i)
     }
 }
 //-----------------------------------------------------------------------------
-void EnDecodeInit(const char * passwd, int length, BLOWFISH_CTX *ctx)
+void EnDecodeInit(const char * passwd, size_t length, BLOWFISH_CTX *ctx)
 {
 unsigned char keyL[PASSWD_LEN];
 
 memset(keyL, 0, PASSWD_LEN);
 
-strncpy((char *)keyL, passwd, PASSWD_LEN);
+strncpy((char *)keyL, passwd, MIN(length, PASSWD_LEN));
 
 Blowfish_Init(ctx, keyL, PASSWD_LEN);
 }