jsoncpp icon indicating copy to clipboard operation
jsoncpp copied to clipboard

Crash after use copy

Open kolobok55 opened this issue 9 years ago • 4 comments

Simple example:

int main(int argc, char* argv[])
{
	Json::Value some_array;

	some_array.append( "text1" );
	some_array.append( "text2" );
	some_array.append( "text3" );

	{
		Json::Value al1, al2;
		al1.copy( some_array );
		al2.copy( some_array );
	}
	// Crash here
}

In older version (from sourceforge) works fine. If copy replace with "=", some_array become nullValue

kolobok55 avatar Nov 28 '17 15:11 kolobok55

I don't have time to reproduce this right now. Can you post a stack-trace from a debugger? Or maybe try valgrind?

What commit-SHA1 are you using?

cdunn2001 avatar Dec 03 '17 16:12 cdunn2001

Reproduced as double free (e6a588a2461f6c7cc7af37604363dd67757ccae1):

#0  0x00007ffff71a1428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff71a302a in __GI_abort () at abort.c:89
#2  0x00007ffff71e37ea in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff72fce98 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff71ec37a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=0x7ffff72fcf60 "double free or corruption (fasttop)", action=3) at malloc.c:5006
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3867
#5  0x00007ffff71f053c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968
#6  0x000000000043ae37 in Json::Value::~Value (this=0x7fffffffd290, __in_chrg=<optimized out>) at jsoncpp.cpp:2979
#7  0x000000000042f72a in main (argc=1, argv=0x7fffffffd3e8) at jsp_test.cpp:12

Source lines:

  • jsp_test.cpp:12 from the example above: Json::Value al1, al2;
  • jsoncpp.cpp:2979 from Value::~Value(): delete value_.map_;

Value::value_ is copied byte-to-byte without any type check in Value::copyPayload(const Value& other) and that's quite scary. I think Value::copy(const Value& other) should call Value::Value(Value const& other) instead of copyPayload(). And then it's better to drop copyPayload() as potentially dangerous (and maybe useless).

okodron avatar Dec 04 '17 07:12 okodron

I won't have time to look at this until this weekend, but maybe someone else can reproduce this and fix it sooner. Thanks for the details.

cdunn2001 avatar Dec 04 '17 19:12 cdunn2001

Still haven't looked at this. Just released 1.8.4. Is this still an issue?

cdunn2001 avatar Dec 20 '17 21:12 cdunn2001