supremainc / BioStar2_device_SDK

36 stars 25 forks source link

SDK library crashes when BS2_DisconnectDevice(..) is called #2

Closed vadim-perco closed 4 years ago

vadim-perco commented 5 years ago
BS2_DEVICE_ID nID_BS2 = 0;
int nRet = BS2_ConnectDeviceViaIP(pSDKContext,strIPAddress.c_str(), BS2_TCP_DEVICE_PORT_DEFAULT, &nID_BS2);
if (nRet==BS_SDK_SUCCESS && nID_BS2>0) {

    // This function caused crash for SDK version 2.6.3.5 or higher
    // For SDK version 2.6.2.5 or lower it works correctly

    BS2_DisconnectDevice(g_pSDKContext, nID_BS2);

}

Error message: buffer overflow detected My platform is Linux Ubuntu 18.04 I use 64-bit version of library from BioStar2_device_SDK/Lib/Linux/lib/x64/libBS_SDK_V2.so

liepauls commented 4 years ago

Same issue here

AndroidGorny commented 4 years ago

Actually, the buffer overflow happens in many SDK functions, when using library on Ubuntu 18.04 64 bit platform.

System: OS: Ubuntu 18.04.3 LTS OS type: 64-bit Memory: 8GB

Biostar SDK library version: 2.6.3.16 (have also tried 2.6.3.13 an 2.6.3.19 beta release) - results are always the same

Few examples:

Test case No.1 =============================================

void* _pBiostarContext = NULL;

int main(){

    printf("Application started!\n");

    _pBiostarContext = BS2_AllocateContext();

    if(_pBiostarContext != NULL){

        int nResult = BS2_Initialize(_pBiostarContext);

        if(nResult != BS_SDK_SUCCESS){
            printf("Failed to initialize context!\n");
                        BS2_ReleaseContext(_pBiostarContext);
            return EXIT_FAILURE;
        }

        printf("Using Biostar library version %s\n", BS2_Version());

    } 
    else{
        printf("Failed to allocate context!\n");
        return EXIT_FAILURE;
    }

    BS2_ReleaseContext(_pBiostarContext); // <-- Can not get past this

    printf("Application finished!\n");
    return EXIT_SUCCESS;
}

Expected output:

Application started! Using Biostar library version 2.6.3.16 Application finished!

Actual output:

Application started! Using Biostar library version 2.6.3.16 buffer overflow detected

Test case No.2 (failed reader connection) =============================================

void* _pBiostarContext = NULL;
const char* _cHost = "<Invalid reader IP here>";
int _nPort = 51211;.
int _nbiostarDeviceId = 0;

int main(){

    printf("Application started!\n");

    _pBiostarContext = BS2_AllocateContext();

    if(_pBiostarContext != NULL){

        int nResult = BS2_Initialize(_pBiostarContext);

        if(nResult != BS_SDK_SUCCESS){
            printf("Failed to initialize context!\n");
                        BS2_ReleaseContext(_pBiostarContext);
            return EXIT_FAILURE;
        }

        printf("Using Biostar library version %s\n", BS2_Version());

    } 
    else{
        printf("Failed to allocate context!\n");
        return EXIT_FAILURE;
    }

    printf("Connecting to reader\n");

    while(BS_SDK_SUCCESS != BS2_ConnectDeviceViaIP(_pBiostarContext, 
        _cHost, _nPort, &_nBiostarDeviceId)) // <-- Buffer overflow if the connection does not succeed
    {
        printf("Retrying reader connection\n"); // <-- Never gets here
    }

    printf("Connected to reader\n");
    /*Rest of the application code
    ..........  
    */
    BS2_ReleaseContext(_pBiostarContext);
    printf("Application finished!\n");
    return EXIT_SUCCESS;
}

Expected output:

Application started! Using Biostar library version 2.6.3.16 Connecting to reader! Retrying reader connection Retrying reader connection And so on....

Actual output:

Using Biostar library version 2.6.3.16 Connecting to reader buffer overflow detected

vadim-perco commented 4 years ago

This problem solved in SDK 2.6.3.23