Skip to content

Commit ac5caba

Browse files
committed
fixes for USE_WINDOWS_API && !NO_FILESYSTEM && !NO_WOLFSSL_DIR:
* in wc_port.h, add XWRITE and XREAD definitions and include <io.h>; * in wolfSSL_BIO_read(), implement Windows support for XREAD and XWRITE; * in wolfSSL_BIO_write_filename(), add 'b' flag to XFOPEN flags; * in wolfSSL_RAND_file_name(), add support for XALTHOMEVARNAME, and add Windows definition for it to wc_port.h alongside XWRITE and XREAD. fixes test_wolfSSL_BIO, test_wolfSSL_X509_print, test_wolfSSL_RAND, test_wolfSSL_RSA_print in cross-mingw-all-crypto scenario.
1 parent 71db561 commit ac5caba

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/bio.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
312312
ret = (int)XFREAD(buf, 1, (size_t)len, (XFILE)bio->ptr);
313313
}
314314
else {
315-
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
315+
#if defined(XREAD) && !defined(NO_WOLFSSL_DIR) && \
316316
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
317317
ret = (int)XREAD(bio->num, buf, (size_t)len);
318318
#else
@@ -682,7 +682,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
682682
ret = (int)XFWRITE(data, 1, (size_t)len, (XFILE)bio->ptr);
683683
}
684684
else {
685-
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
685+
#if defined(XWRITE) && !defined(NO_WOLFSSL_DIR) && \
686686
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
687687
ret = (int)XWRITE(bio->num, data, (size_t)len);
688688
#else
@@ -1617,7 +1617,12 @@ int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name)
16171617
XFCLOSE((XFILE)bio->ptr);
16181618
}
16191619

1620-
bio->ptr = XFOPEN(name, "w");
1620+
/* 'b' flag is ignored on POSIX targets, but on Windows it assures
1621+
* inhibition of LF<->CRLF rewriting, so that there is consistency
1622+
* between the size and contents of the representation in memory and on
1623+
* disk.
1624+
*/
1625+
bio->ptr = XFOPEN(name, "wb");
16211626
if (((XFILE)bio->ptr) == XBADFILE) {
16221627
return WOLFSSL_FAILURE;
16231628
}

src/ssl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23701,9 +23701,18 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2370123701
const char ap[] = "/.rnd";
2370223702

2370323703
WOLFSSL_MSG("Environment variable RANDFILE not set");
23704+
2370423705
if ((rt = XGETENV("HOME")) == NULL) {
23706+
#ifdef XALTHOMEVARNAME
23707+
if ((rt = XGETENV(XALTHOMEVARNAME)) == NULL) {
23708+
WOLFSSL_MSG("Environment variable HOME and " XALTHOMEVARNAME
23709+
" not set");
23710+
return NULL;
23711+
}
23712+
#else
2370523713
WOLFSSL_MSG("Environment variable HOME not set");
2370623714
return NULL;
23715+
#endif
2370723716
}
2370823717

2370923718
if (len > XSTRLEN(rt) + XSTRLEN(ap)) {
@@ -23713,7 +23722,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2371323722
return fname;
2371423723
}
2371523724
else {
23716-
WOLFSSL_MSG("HOME too large for buffer");
23725+
WOLFSSL_MSG("Path too large for buffer");
2371723726
return NULL;
2371823727
}
2371923728
}

wolfssl/wolfcrypt/wc_port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,16 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
716716
#if !defined(NO_WOLFSSL_DIR)\
717717
&& !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
718718
#if defined(USE_WINDOWS_API)
719+
#include <io.h>
719720
#include <sys/stat.h>
720721
#ifndef XSTAT
721722
#define XSTAT _stat
722723
#endif
723724
#define XS_ISREG(s) (s & _S_IFREG)
724725
#define SEPARATOR_CHAR ';'
726+
#define XWRITE _write
727+
#define XREAD _read
728+
#define XALTHOMEVARNAME "USERPROFILE"
725729

726730
#elif defined(ARDUINO)
727731
#ifndef XSTAT

0 commit comments

Comments
 (0)