Skip to content

Commit 6ab8cd2

Browse files
committed
Defer SNI insertion and validate decrypt input size
- Move SNI arg insertion to after option parsing so -noservername works regardless of argument order relative to -connect - Validate input file is large enough for salt+IV before computing lastLoopFlag to prevent negative values on truncated files
1 parent ad92c23 commit 6ab8cd2

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/client/clu_client_setup.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ int wolfCLU_Client(int argc, char** argv)
198198
}
199199
}
200200

201-
/* Set SNI hostname so modern servers accept the connection.
202-
* Matches openssl s_client default; use -noservername to disable. */
203-
if (ret == WOLFCLU_SUCCESS && host != NULL && !noservername) {
204-
ret = _addClientArg(clientArgv, sniFlag, &clientArgc);
205-
if (ret == WOLFCLU_SUCCESS) {
206-
ret = _addClientArg(clientArgv, host, &clientArgc);
207-
}
208-
}
209201
break;
210202

211203
case WOLFCLU_STARTTLS:
@@ -256,6 +248,17 @@ int wolfCLU_Client(int argc, char** argv)
256248
}
257249
}
258250

251+
/* Set SNI hostname so modern servers accept the connection.
252+
* Matches openssl s_client default; use -noservername to disable.
253+
* Deferred until after option parsing so -noservername works
254+
* regardless of argument order. */
255+
if (ret == WOLFCLU_SUCCESS && host != NULL && !noservername) {
256+
ret = _addClientArg(clientArgv, sniFlag, &clientArgc);
257+
if (ret == WOLFCLU_SUCCESS) {
258+
ret = _addClientArg(clientArgv, host, &clientArgc);
259+
}
260+
}
261+
259262
if (ret == WOLFCLU_SUCCESS && !verify) {
260263
ret = _addClientArg(clientArgv, noVerifyFlag, &clientArgc);
261264

src/crypto/clu_decrypt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ int wolfCLU_decrypt(int alg, char* mode, byte* pwdKey, byte* key, int size,
7777
length = (int)XFTELL(inFile);
7878
XFSEEK(inFile, 0, SEEK_SET);
7979

80+
/* Validate file is large enough for salt + IV header */
81+
if (length < saltAndIvSize) {
82+
wolfCLU_LogError("Input file too small (missing salt/IV).");
83+
XFCLOSE(inFile);
84+
return DECRYPT_ERROR;
85+
}
86+
8087
/* Compute loop count from the encrypted payload size (excluding the
8188
* salt and IV that are read separately before the loop). */
8289
if ((length - saltAndIvSize) % MAX_LEN > 0) {

0 commit comments

Comments
 (0)