Topic: Possible #define bugs

Hey, I'm not sure if this is the right place to post bugs and such, but I've had a few issues while using WolfSSL.



The first one is defined in line 150 of wolfio.h

    #define close(s) closesocket(s)

It defines close as closesockets, which in turn causes compilation issues when I'm using std::ofstream::close for closing down files in projects which use WolfSSL. The preprocessor makes it std::ofstream::closesockets, which doesn't exist.

I could of course undefine it, but it would be preferred to have this implemented in another way, or maybe I'm just using it wrong?




The 2nd thing I've noticed is while using Hmac. Running the code below will crash for me:

//#Define WOLFSSL_SHA512

#include <wolfssl/wolfcrypt/hmac.h>

void Sha256()
{
    Hmac        hmac;

    byte        key[24];

    byte        buffer[2048];

    byte        hmacDigest[SHA256_DIGEST_SIZE];

    wc_HmacSetKey(&hmac, SHA256, key, sizeof(key));
    wc_HmacUpdate(&hmac, buffer, sizeof(buffer));

    wc_HmacFinal(&hmac, hmacDigest);

    return;
}

int main()
{
    Sha256();

    return 0;
}

It crashes with the error: "Run time check failure #2 - Stack around the variable 'hmac' was corrupted".

However if I uncomment the "#Define WOLFSSL_SHA512" the code will run perfectly fine, which I find odd since I wouldn't think i had to define for Sha512 to be able to run Sha256.

If it makes any difference I'm compiling this on windows 10 using Visual Studio 2017, and Version 3.13.0 of WolfSSL.

Share

Re: Possible #define bugs

Hi Yolojohn,

#define close(s) closesocket(s)

The only time that define should occur is when USE_WINDOWS_API is defined and that is the correct API call for the .NET framework. Are you working on windows but not using the windows c++ standard library which implements closesocket?

Could you tell us a little more about your build environment and setup, what your end goals are for the project etc so we can provide a good solution to this issue?

As for the crash it looks like you have not included the same settings as used to build the library (I only see hmac.h being included).

Our default examples use the header <wolfssl-root>/IDE/WIN/user_settings.h to control the setup of our library and in the project we add the include path C:\path-to\<wolfssl-root>/IDE/WIN and the pre-processor macro "WOLFSSL_USER_SETTINGS" so that the <wolfssl-root>/wolfcrypt/settings/settings.h will pull in the user_settings automatically. All the same pre-processor macros set in the wolfssl-library project and any customer user_settings.h should also be included in the application. A mismatch in settings will very often cause crashes of the nature you reported.

Warm Regards,


Kaleb