mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
Fixes with load_file helper to make sure return code is set correctly and args are initialized.
This commit is contained in:
@@ -1104,12 +1104,21 @@ static INLINE unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
|
|||||||
/* reads file size, allocates buffer, reads into buffer, returns buffer */
|
/* reads file size, allocates buffer, reads into buffer, returns buffer */
|
||||||
static INLINE int load_file(const char* fname, byte** buf, size_t* bufLen)
|
static INLINE int load_file(const char* fname, byte** buf, size_t* bufLen)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret;
|
||||||
FILE* file = fopen(fname, "rb");
|
FILE* file;
|
||||||
|
|
||||||
|
if (fname == NULL || buf == NULL || bufLen == NULL)
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
/* set defaults */
|
||||||
|
*buf = NULL;
|
||||||
|
*bufLen = 0;
|
||||||
|
|
||||||
|
/* open file (read-only binary) */
|
||||||
|
file = fopen(fname, "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
printf("Error loading %s\n", fname);
|
printf("Error loading %s\n", fname);
|
||||||
return -1;
|
return BAD_PATH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
@@ -1128,6 +1137,9 @@ static INLINE unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
|
|||||||
ret = (readLen > 0) ? 0 : -1;
|
ret = (readLen > 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ret = BUFFER_E;
|
||||||
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user