Fix Asan Issue buffer overflow
The following bt was obtained on running asan tool on libdbuspolicy before patch fix:
sh-3.2# cat asan.log.nagsam-daemon.599
=================================================================
==nagsam-daemon==599==ERROR: AddressSanitizer: stack-buffer-overflow on address 0xbe4a5720 at pc 0xb6266535 bp 0xbe4a4900 sp 0xbe4a4948
READ of size 1083 at 0xbe4a5720 thread T0
#0 0xb6266533 in printf_common(void*, char const*, std::__va_list) (/usr/lib/libasan.so+0x6f533)
#1 0xb6267cd3 in vsnprintf (/usr/lib/libasan.so+0x70cd3)
#2 0xb6267f49 in __snprintf_chk (/usr/lib/libasan.so+0x70f49)
#3 0xb581c9fd in dbuspolicy1_init (/lib/libdbuspolicy1.so.1+0x89fd)
#4 0x41abead3 in _dbus_transport_open_kdbus (/lib/libdbus-1.so.3+0x41abead3)
#5 0x41aabf8b in _dbus_transport_open (/lib/libdbus-1.so.3+0x41aabf8b)
#6 0x41a93e63 in _dbus_connection_open_internal (/lib/libdbus-1.so.3+0x41a93e63)
#7 0x41a8eb73 in internal_bus_get (/lib/libdbus-1.so.3+0x41a8eb73)
#8 0x4488a195 in TCIPCConnection::m_CreateConnection() (/lib/libtvs-api-ipc.so+0x4488a195)
#9 0x4488a25b in TCIPCConnection::m_Connect(bool) (/lib/libtvs-api-ipc.so+0x4488a25b)
#10 0x4488a48b in TCIPCConnection::TCIPCConnection(std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool) (/lib/libtvs-api-ipc.so+0x4488a48b)
#11 0x4488a59f in IPCConnection__Create (/lib/libtvs-api-ipc.so+0x4488a59f)
#12 0x445282c1 in TVServiceAPIConnection::TVServiceAPIConnection(std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool) (/lib/libtvs-api.so+0x445282c1)
#13 0x444e3f5f in TVServiceAPI::CreateSOSpecApp(EProfile, int, ISOSpecApp**) (/lib/libtvs-api.so+0x444e3f5f)
#14 0xb6090889 in NAGSAM_MW::CSystemInfo::CSystemInfo() (/lib/libnagsam-mw.so+0x301889)
#15 0xb6097053 in NAGSAM_MW::ISystemInfo::Instance() (/lib/libnagsam-mw.so+0x308053)
#16 0xb60c34ed in NAGSAM_MW::TizenSupportManager::TizenSupportManager() (/lib/libnagsam-mw.so+0x3344ed)
#17 0xb60c4c05 in NAGSAM_MW::ISupportManager::Instance() (/lib/libnagsam-mw.so+0x335c05)
#18 0xb60c4c53 in NAGSAM_MW::MainEntryPoint() (/lib/libnagsam-mw.so+0x335c53)
#19 0x111f3 in main (/usr/bin/nagsam-daemon+0x111f3)
#20 0x41096867 in __libc_start_main (/lib/libc.so.6+0x41096867)
Address 0xbe4a5720 is located in stack of thread T0 at offset 1184 in frame
#0 0xb581c35f in dbuspolicy1_init (/lib/libdbuspolicy1.so.1+0x835f)
This frame has 4 object(s):
[32, 64) 'cmd_free'
[96, 106) 'user_suffix'
[160, 1184) 'buf'
[1216, 5312) 'resolved_path' <== Memory access at offset 1184 partially underflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions are supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (/usr/lib/libasan.so+0x6f533) in printf_common(void*, char const*, std::__va_list)
Shadow bytes around the buggy address:
0x37c94a90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94aa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94ab0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94ac0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94ad0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x37c94ae0: 00 00 00 00[f2]f2 f2 f2 00 00 00 00 00 00 00 00
0x37c94af0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94b00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94b10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94b20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x37c94b30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Command: /usr/bin/nagsam-daemon
#################################################################
No such issues were reported after NULL terminating the buffer.
Change-Id: I7afccaab7448119621fdd36bd5a354da96eb9a4a
Signed-off-by: Kushagra K <kushagra.k@samsung.com>