• Advertisement
Sign in to follow this  

std::stringstream crash

This topic is 683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello,
i'm using boost serialization to serialize data and send it through the network, i send anything from client, but when i want to receive it, it crashe's the stringstream
this is the code when the crash occurs:

trace_handler("data received from client: "+string(cl.gd.ip_address)+string(" data: ")+string((char *)data));
stringstream ss;
ss.str("");
if(data)
{
ss<<data; //crash is here
text_iarchive ia(ss);
ia>>cl.gd;
}
first, cl.gd is my gamedata struct and the gamedata declaration is like this:
typedef struct gamedata
{
std::string username;
std::string password;
int rank;
bool userpass_incorrect;
bool account_not_exist;
std::string mac_address;
std::string hdd_serial;
std::string ip_address;
int x;
int y;
int z;
int health;
bool is_banned;
bool kicked;
bool notify;
std::string pm_user;
std::string chat_user;
std::string message;
bool came_online;
bool went_offline;
std::string server_message;
std::string motd;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, unsigned int version)
{
ar&username;
ar&password;
ar&rank;
ar&userpass_incorrect;
ar&account_not_exist;
ar&mac_address;
ar&hdd_serial;
ar&ip_address;
ar&x;
ar&y;
ar&z;
ar&health;
ar&is_banned;
ar&kicked;
ar&notify;
ar&pm_user;
ar&chat_user;
ar&message;
ar&came_online;
ar&went_offline;
ar&server_message;
ar&motd;
}

}gamedata;
this is the log trase that i've generated from server app, and i don't know why boost serialization plase these characters inside it:
listening on port 4651
client  connected from 127.0.0.1
data received from client: 127.0.0.1 data: 22 serialization::archive 14 0 0 7 amir.fj 8 t
 0 0 0 0  0  0  0 0 0 0 0 0 0 0  0  0  0 0 0  0 ««««««««þîþ
this is the code from client that initialize's the username and password and send it to server:

g.username=username;
g.password=password;
g.mac_address=get_mac_address();
//check our username and password
if(username==""||password=="")
{
//do stuff
}
//fill our packet data
g.username=username;
g.password=password;
g.mac_address=get_mac_address();
if(g.username==""||g.password=="")
{
//do stuff
}
and when i want to send it to server when it is connected:
stringstream sd;
text_oarchive oa(sd);
oa<<g;
c.send_packet(0, sd.str().c_str(), sd.str().size(), ENET_PACKET_FLAG_RELIABLE);
i'm using eNet networking library (with enetpp that i've modified it), but it has no problem
when i receive the data from server:
stringstream ss;
if(data!=nullptr)
{
    ss.str("");
ss<<data;
text_iarchive ia(ss);
ia>>g;
}
this is the code when server send's the data back to the client:
stringstream sd;
text_oarchive oa(sd);
oa<<cl.gd;
server.send_packet_to(cl.uid, 0, sd.str().c_str(), sd.str().size(), ENET_PACKET_FLAG_RELIABLE);
this is the debug log of server:

Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: F:\projects\cpp\missiontime-server\
Adding source dir: F:\projects\cpp\missiontime-server\
Adding file: F:\projects\cpp\missiontime-server\bin\Debug\mtserver.exe
Changing directory to: F:/projects/cpp/missiontime-server/bin/Debug
Set variable: PATH=.;C:\Dev-Cpp\bin;C:\Dev-Cpp;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Skype\Phone;C:\Program Files\CMake\bin;C:\Program Files\Heroku\bin;C:\Program Files\Git\cmd;C:\php;C:\ProgramData\ComposerSetup\bin;C:\Users\brightening-eyes\AppData\Roaming\Composer\vendor\bin

[debug]Command-line: C:\Dev-Cpp\bin\gdb.exe -fullname -quiet  -args F:/projects/cpp/missiontime-server/bin/Debug/mtserver.exe
[debug]Working dir : F:\projects\cpp\missiontime-server\bin\Debug

Starting debugger: C:\Dev-Cpp\bin\gdb.exe -fullname -quiet  -args F:/projects/cpp/missiontime-server/bin/Debug/mtserver.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from F:/projects/cpp/missiontime-server/bin/Debug/mtserver.exe...
[debug]done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.10.1
[debug]Copyright (C) 2015 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-w64-mingw32".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.10.1

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory F:/projects/cpp/missiontime-server/
[debug]Source directories searched: F:/projects/cpp/missiontime-server;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: F:\projects\cpp\missiontime-server\bin\Debug\mtserver.exe

Child process PID: 65280

[debug][New Thread 65280.0xf9a4]
[debug][New Thread 65280.0xfab4]
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x752d43f9 in strlen () from C:\Windows\system32\msvcrt.dll
[debug]>>>>>>cb_gdb:

Program received signal SIGSEGV, Segmentation fault.
In strlen () (C:\Windows\system32\msvcrt.dll)

[debug]> bt 30
[debug]#0  0x752d43f9 in strlen () from C:\Windows\system32\msvcrt.dll
[debug]>>>>>>cb_gdb:
[debug]> info registers
[debug]eax            0x0    0
[debug]ecx            0x0    0
[debug]edx            0x0    0
[debug]ebx            0x8fab00    9415424
[debug]esp            0x22f3ec    0x22f3ec
[debug]ebp            0x0    0x0
[debug]esi            0x0    0
[debug]edi            0x8fabc0    9415616
[debug]eip            0x752d43f9    0x752d43f9 <strlen+38>
[debug]eflags         0x10246    [ PF ZF IF RF ]
[debug]cs             0x1b    27
[debug]ss             0x23    35
[debug]ds             0x23    35
[debug]es             0x23    35
[debug]fs             0x3b    59
[debug]gs             0x0    0
[debug]>>>>>>cb_gdb:
[debug]> if 1
disassemble 0x752d43f9
info frame
end
[debug] > > >
[debug]Dump of assembler code for function strlen:
[debug]   0x752d43d3 <+0>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d43d7 <+4>:    test   ecx,0x3
[debug]   0x752d43dd <+10>:    je     0x752d43f9 <strlen+38>
[debug]   0x752d43df <+12>:    mov    al,BYTE PTR [ecx]
[debug]   0x752d43e1 <+14>:    add    ecx,0x1
[debug]   0x752d43e4 <+17>:    test   al,al
[debug]   0x752d43e6 <+19>:    je     0x752d4434 <strlen+97>
[debug]   0x752d43e8 <+21>:    test   ecx,0x3
[debug]   0x752d43ee <+27>:    jne    0x752d43df <strlen+12>
[debug]   0x752d43f0 <+29>:    add    eax,0x0
[debug]   0x752d43f3 <+32>:    lea    esp,[esp]
[debug]   0x752d43f6 <+35>:    lea    esp,[esp]
[debug]=> 0x752d43f9 <+38>:    mov    eax,DWORD PTR [ecx]
[debug]   0x752d43fb <+40>:    mov    edx,0x7efefeff
[debug]   0x752d4400 <+45>:    add    edx,eax
[debug]   0x752d4402 <+47>:    xor    eax,0xffffffff
[debug]   0x752d4405 <+50>:    xor    eax,edx
[debug]   0x752d4407 <+52>:    add    ecx,0x4
[debug]   0x752d440a <+55>:    test   eax,0x81010100
[debug]   0x752d440f <+60>:    je     0x752d43f9 <strlen+38>
[debug]   0x752d4411 <+62>:    mov    eax,DWORD PTR [ecx-0x4]
[debug]   0x752d4414 <+65>:    test   al,al
[debug]   0x752d4416 <+67>:    je     0x752d443e <strlen+107>
[debug]   0x752d4418 <+69>:    test   ah,ah
[debug]   0x752d441a <+71>:    je     0x752d4448 <strlen+117>
[debug]   0x752d441c <+73>:    test   eax,0xff0000
[debug]   0x752d4421 <+78>:    jne    0x752d442d <strlen+90>
[debug]   0x752d4423 <+80>:    lea    eax,[ecx-0x2]
[debug]   0x752d4426 <+83>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d442a <+87>:    sub    eax,ecx
[debug]   0x752d442c <+89>:    ret    
[debug]   0x752d442d <+90>:    test   eax,0xff000000
[debug]   0x752d4432 <+95>:    jne    0x752d43f9 <strlen+38>
[debug]   0x752d4434 <+97>:    lea    eax,[ecx-0x1]
[debug]   0x752d4437 <+100>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d443b <+104>:    sub    eax,ecx
[debug]   0x752d443d <+106>:    ret    
[debug]   0x752d443e <+107>:    lea    eax,[ecx-0x4]
[debug]   0x752d4441 <+110>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d4445 <+114>:    sub    eax,ecx
[debug]   0x752d4447 <+116>:    ret    
[debug]   0x752d4448 <+117>:    lea    eax,[ecx-0x3]
[debug]   0x752d444b <+120>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d444f <+124>:    sub    eax,ecx
[debug]   0x752d4451 <+126>:    ret    
[debug]   0x752d4452 <+127>:    mov    eax,DWORD PTR [edi]
[debug]   0x752d4454 <+129>:    test   BYTE PTR [ebx+eax*1+0x4],0x80
[debug]   0x752d4459 <+134>:    je     0x752d400d <msvcrt!fprintf+525>
[debug]   0x752d445f <+140>:    call   0x752ca5ce <msvcrt!_errno+22>
[debug]   0x752d4464 <+145>:    mov    eax,DWORD PTR [eax+0x6c]
[debug]   0x752d4467 <+148>:    xor    ecx,ecx
[debug]   0x752d4469 <+150>:    cmp    DWORD PTR [eax+0x14],ecx
[debug]   0x752d446c <+153>:    lea    eax,[ebp-0x58c]
[debug]   0x752d4472 <+159>:    sete   cl
[debug]   0x752d4475 <+162>:    push   eax
[debug]   0x752d4476 <+163>:    mov    eax,DWORD PTR [edi]
[debug]   0x752d4478 <+165>:    push   DWORD PTR [eax+ebx*1]
[debug]   0x752d447b <+168>:    mov    esi,ecx
[debug]   0x752d447d <+170>:    call   DWORD PTR ds:0x752c102c
[debug]   0x752d4483 <+176>:    test   eax,eax
[debug]   0x752d4485 <+178>:    je     0x752d400d <msvcrt!fprintf+525>
[debug]   0x752d448b <+184>:    test   esi,esi
[debug]   0x752d448d <+186>:    jne    0x752e5e7e <wprintf+155>
[debug]   0x752d4493 <+192>:    call   DWORD PTR ds:0x752c1014
[debug]   0x752d4499 <+198>:    and    DWORD PTR [ebp-0x584],0x0
[debug]   0x752d44a0 <+205>:    cmp    DWORD PTR [ebp+0x10],0x0
[debug]   0x752d44a4 <+209>:    mov    esi,DWORD PTR [ebp-0x574]
[debug]   0x752d44aa <+215>:    mov    DWORD PTR [ebp-0x594],eax
[debug]   0x752d44b0 <+221>:    mov    DWORD PTR [ebp-0x590],esi
[debug]   0x752d44b6 <+227>:    jbe    0x75306098 <msvcrt!_ftol2_sse_excpt+82653>
[debug]   0x752d44bc <+233>:    and    DWORD PTR [ebp-0x568],0x0
[debug]   0x752d44c3 <+240>:    jmp    0x752d77e5 <msvcrt!fwrite+313>
[debug]   0x752d44c8 <+245>:    nop
[debug]   0x752d44c9 <+246>:    nop
[debug]   0x752d44ca <+247>:    nop
[debug]   0x752d44cb <+248>:    nop
[debug]   0x752d44cc <+249>:    nop
[debug]End of assembler dump.
[debug]Stack level 0, frame at 0x0:
[debug] eip = 0x752d43f9 in strlen; saved eip = 0x752d43f9
[debug] Outermost frame: outermost
[debug] Arglist at unknown address.
[debug] Locals at unknown address, Previous frame's sp in esp
[debug]>>>>>>cb_gdb:
[debug]> disassemble 0x752d43f9
[debug]Dump of assembler code for function strlen:
[debug]   0x752d43d3 <+0>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d43d7 <+4>:    test   ecx,0x3
[debug]   0x752d43dd <+10>:    je     0x752d43f9 <strlen+38>
[debug]   0x752d43df <+12>:    mov    al,BYTE PTR [ecx]
[debug]   0x752d43e1 <+14>:    add    ecx,0x1
[debug]   0x752d43e4 <+17>:    test   al,al
[debug]   0x752d43e6 <+19>:    je     0x752d4434 <strlen+97>
[debug]   0x752d43e8 <+21>:    test   ecx,0x3
[debug]   0x752d43ee <+27>:    jne    0x752d43df <strlen+12>
[debug]   0x752d43f0 <+29>:    add    eax,0x0
[debug]   0x752d43f3 <+32>:    lea    esp,[esp]
[debug]   0x752d43f6 <+35>:    lea    esp,[esp]
[debug]=> 0x752d43f9 <+38>:    mov    eax,DWORD PTR [ecx]
[debug]   0x752d43fb <+40>:    mov    edx,0x7efefeff
[debug]   0x752d4400 <+45>:    add    edx,eax
[debug]   0x752d4402 <+47>:    xor    eax,0xffffffff
[debug]   0x752d4405 <+50>:    xor    eax,edx
[debug]   0x752d4407 <+52>:    add    ecx,0x4
[debug]   0x752d440a <+55>:    test   eax,0x81010100
[debug]   0x752d440f <+60>:    je     0x752d43f9 <strlen+38>
[debug]   0x752d4411 <+62>:    mov    eax,DWORD PTR [ecx-0x4]
[debug]   0x752d4414 <+65>:    test   al,al
[debug]   0x752d4416 <+67>:    je     0x752d443e <strlen+107>
[debug]   0x752d4418 <+69>:    test   ah,ah
[debug]   0x752d441a <+71>:    je     0x752d4448 <strlen+117>
[debug]   0x752d441c <+73>:    test   eax,0xff0000
[debug]   0x752d4421 <+78>:    jne    0x752d442d <strlen+90>
[debug]   0x752d4423 <+80>:    lea    eax,[ecx-0x2]
[debug]   0x752d4426 <+83>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d442a <+87>:    sub    eax,ecx
[debug]   0x752d442c <+89>:    ret    
[debug]   0x752d442d <+90>:    test   eax,0xff000000
[debug]   0x752d4432 <+95>:    jne    0x752d43f9 <strlen+38>
[debug]   0x752d4434 <+97>:    lea    eax,[ecx-0x1]
[debug]   0x752d4437 <+100>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d443b <+104>:    sub    eax,ecx
[debug]   0x752d443d <+106>:    ret    
[debug]   0x752d443e <+107>:    lea    eax,[ecx-0x4]
[debug]   0x752d4441 <+110>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d4445 <+114>:    sub    eax,ecx
[debug]   0x752d4447 <+116>:    ret    
[debug]   0x752d4448 <+117>:    lea    eax,[ecx-0x3]
[debug]   0x752d444b <+120>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d444f <+124>:    sub    eax,ecx
[debug]   0x752d4451 <+126>:    ret    
[debug]   0x752d4452 <+127>:    mov    eax,DWORD PTR [edi]
[debug]   0x752d4454 <+129>:    test   BYTE PTR [ebx+eax*1+0x4],0x80
[debug]   0x752d4459 <+134>:    je     0x752d400d <msvcrt!fprintf+525>
[debug]   0x752d445f <+140>:    call   0x752ca5ce <msvcrt!_errno+22>
[debug]   0x752d4464 <+145>:    mov    eax,DWORD PTR [eax+0x6c]
[debug]   0x752d4467 <+148>:    xor    ecx,ecx
[debug]   0x752d4469 <+150>:    cmp    DWORD PTR [eax+0x14],ecx
[debug]   0x752d446c <+153>:    lea    eax,[ebp-0x58c]
[debug]   0x752d4472 <+159>:    sete   cl
[debug]   0x752d4475 <+162>:    push   eax
[debug]   0x752d4476 <+163>:    mov    eax,DWORD PTR [edi]
[debug]   0x752d4478 <+165>:    push   DWORD PTR [eax+ebx*1]
[debug]   0x752d447b <+168>:    mov    esi,ecx
[debug]   0x752d447d <+170>:    call   DWORD PTR ds:0x752c102c
[debug]   0x752d4483 <+176>:    test   eax,eax
[debug]   0x752d4485 <+178>:    je     0x752d400d <msvcrt!fprintf+525>
[debug]   0x752d448b <+184>:    test   esi,esi
[debug]   0x752d448d <+186>:    jne    0x752e5e7e <wprintf+155>
[debug]   0x752d4493 <+192>:    call   DWORD PTR ds:0x752c1014
[debug]   0x752d4499 <+198>:    and    DWORD PTR [ebp-0x584],0x0
[debug]   0x752d44a0 <+205>:    cmp    DWORD PTR [ebp+0x10],0x0
[debug]   0x752d44a4 <+209>:    mov    esi,DWORD PTR [ebp-0x574]
[debug]   0x752d44aa <+215>:    mov    DWORD PTR [ebp-0x594],eax
[debug]   0x752d44b0 <+221>:    mov    DWORD PTR [ebp-0x590],esi
[debug]   0x752d44b6 <+227>:    jbe    0x75306098 <msvcrt!_ftol2_sse_excpt+82653>
[debug]   0x752d44bc <+233>:    and    DWORD PTR [ebp-0x568],0x0
[debug]   0x752d44c3 <+240>:    jmp    0x752d77e5 <msvcrt!fwrite+313>
[debug]   0x752d44c8 <+245>:    nop
[debug]   0x752d44c9 <+246>:    nop
[debug]   0x752d44ca <+247>:    nop
[debug]   0x752d44cb <+248>:    nop
[debug]   0x752d44cc <+249>:    nop
[debug]End of assembler dump.
[debug]>>>>>>cb_gdb:
[debug]> x/32xb 0x0
[debug]Cannot access memory at address 0x0
[debug]0x0:    >>>>>>cb_gdb:
[debug]> info threads
[debug]  Id   Target Id         Frame
[debug]  2    Thread 65280.0xfab4 0x76fe6bf4 in ntdll!KiFastSystemCallRet () from C:\Windows\SYSTEM32\ntdll.dll
[debug]* 1    Thread 65280.0xf9a4 0x752d43f9 in strlen () from C:\Windows\system32\msvcrt.dll
[debug]>>>>>>cb_gdb:
[debug]> info locals
[debug]No symbol table info available.
[debug]>>>>>>cb_gdb:
[debug]> info args
[debug]No symbol table info available.
[debug]>>>>>>cb_gdb:
[/coede]
compiler: gcc 5.3.0 with code::blocks 16.11 win7 32 bit ultimate boost 1.60 and with -std=gnu++14
i saw many examples that don't crash, but i'm really mixed up what i did in a wrong way
thanks

Share this post


Link to post
Share on other sites
Advertisement
Is there any way to reproduce the problem with a small self-contained program that you can post here in its entirety?

Share this post


Link to post
Share on other sites

hi again,
this is a sample test app that i've written, but it doesn't crash

//a test app that allow's me to test my gamedata struct with stringstream in order to serialize it
#include <iostream>
#include <string>
#include <sstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/serialization.hpp>
#include "gamedata.hpp"

//uses
using namespace std;
using namespace boost;
using namespace boost::archive;
using namespace boost::serialization;

int main(int argc, char** argv)
{
gamedata gd; //i want to serialize this
gd.username="test";
gd.password="test";
gd.rank=3;
gd.userpass_incorrect=false;
gd.account_not_exist=true;
gd.mac_address="00:00:00:00";
gd.hdd_serial="0x8FE00";
gd.ip_address="127.0.0.1";
gd.x=500;
gd.y=800;
gd.z=0;
gd.health=100;
gd.is_banned=false;
gd.kicked=false;
gd.notify=true;
gd.pm_user="test_pm";
gd.chat_user="test_chat";
gd.message="this is a test message";
gd.came_online=false;
gd.went_offline=false;
gd.server_message="server\'s message";
gd.motd="message of the day";
stringstream st; //this is needed for serializing the struct
text_oarchive oa(st);
oa<<gd;
cout<<"serialized data: "<<st.str()<<std::endl;
system("pause");
return 0;
}
i don't know what make's my app to crash
i've initialized all the variables in my gamedata structure

Share this post


Link to post
Share on other sites
In the code that crashes, is "data" a pointer? The code that doesn't crash doesn't appear to pass a pointer to the stringstream, while the code that crashes appears to be testing for nullptr.

What happens if you change ss<<data to ss << *data? Edited by Oberon_Command

Share this post


Link to post
Share on other sites

this is a sample test app that i've written, but it doesn't crash


I can write non-crashing code myself, but then I can't help you with your problem. :)

Can you take the original program and start removing anything that doesn't seem relevant, testing often, until whatever you remove makes the bug disappear? There is a decent chance you'll discover the problem yourself in that process. And if you don't, you'll have a neat little program to post here so we can help you.

Share this post


Link to post
Share on other sites

That GDB output is showing that something has called strlen(NULL). Firstly, note that GDB shows that ecx is 0 at the time of the crash:

 

[debug]ecx            0x0    0

 

Here's some of your disassembly, highlighted to show what happened. You can see that ecx was loaded from the stack as the input parameter to strlen(). I'm thinking that parameter to strlen() probably comes from the "data" variable.

 

[debug]   0x752d43d3 <+0>:    mov    ecx,DWORD PTR [esp+0x4]
[debug]   0x752d43d7 <+4>:    test   ecx,0x3
[debug]   0x752d43dd <+10>:    je     0x752d43f9 <strlen+38>
[debug]   0x752d43df <+12>:    mov    al,BYTE PTR [ecx]
[debug]   0x752d43e1 <+14>:    add    ecx,0x1
[debug]   0x752d43e4 <+17>:    test   al,al
[debug]   0x752d43e6 <+19>:    je     0x752d4434 <strlen+97>
[debug]   0x752d43e8 <+21>:    test   ecx,0x3
[debug]   0x752d43ee <+27>:    jne    0x752d43df <strlen+12>
[debug]   0x752d43f0 <+29>:    add    eax,0x0
[debug]   0x752d43f3 <+32>:    lea    esp,[esp]
[debug]   0x752d43f6 <+35>:    lea    esp,[esp]
[debug]=> 0x752d43f9 <+38>:    mov    eax,DWORD PTR [ecx]

 

I can also see you have two threads around:

 

[debug]> info threads
[debug]  Id   Target Id         Frame
[debug]  2    Thread 65280.0xfab4 0x76fe6bf4 in ntdll!KiFastSystemCallRet () from C:\Windows\SYSTEM32\ntdll.dll
[debug]* 1    Thread 65280.0xf9a4 0x752d43f9 in strlen () from C:\Windows\system32\msvcrt.dll

 

Given that it looks like "data" is ending up as null, after you've compared it with null, my guess would be that one thread has changed the value of "data" while the other one is using it. If that's the case then that would suggest that "data" is a global variable, or a class member, which is being accessed on more than one thread, and that you're not using appropriate synchronization. Does that make sense?

 

There could of course be some other reason for the null pointer. I'm guessing somewhat because things like the declaration / definition of "data" isn't available.

Share this post


Link to post
Share on other sites
Here's another guess.

trace_handler("data received from client: "+string(cl.gd.ip_address)+string(" data: ")+string((char *)data));
stringstream ss;
ss.str("");
if(data)
{
ss<<data; //crash is here
text_iarchive ia(ss);
ia>>cl.gd;
}
You see how you are calling `string((char *)data)' without checking if it's null? If `data' is indeed null, you have invoked undefined behavior, and your crash is perfectly normal.

Share this post


Link to post
Share on other sites

hi,

it has been fixed by changing ss<<data; to ss<<*data;

i don't know why it fixe's the crash, although data somehow refer's to nullptr

and, trace_handler() doesn't do anything with data pointer, it just retrieve's it's contents and put's it into the log file

thank you all again

Share this post


Link to post
Share on other sites

hi,
it has been fixed by changing ss<<data; to ss<<*data;
i don't know why it fixe's the crash, although data somehow refer's to nullptr
and, trace_handler() doesn't do anything with data pointer, it just retrieve's it's contents and put's it into the log file
thank you all again


I would rather have broken code that code that seems to work but I don't know why. At least I can fix the former. :)

Seriously, I wouldn't just let this go. If there is something you don't understand about your code, it will come back to haunt you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement