Fix double free 99/36599/1 accepted/tizen_3.0.2015.q1_common sandbox/zabramowska/cynara tizen_3.0.2015.q1_common accepted/tizen/3.0.2015.q1/common/20150323.084220 accepted/tizen/common/20150312.084919 accepted/tizen/mobile/20150312.111133 accepted/tizen/mobile/20150313.083936 accepted/tizen/tv/20150313.083817 accepted/tizen/tv/20150316.010838 accepted/tizen/wearable/20150312.110731 accepted/tizen/wearable/20150313.083848 submit/tizen/20150311.160406 submit/tizen_3.0.2015.q1_common/20150320.000000 submit/tizen_mobile/20150313.022842 submit/tizen_tv/20150313.022842 submit/tizen_wearable/20150313.022842
authorSuchang Woo <suchang.woo@samsung.com>
Tue, 10 Mar 2015 12:00:16 +0000 (21:00 +0900)
committerSuchang Woo <suchang.woo@samsung.com>
Tue, 10 Mar 2015 12:20:24 +0000 (21:20 +0900)
When buxton_check_smack_access() in buxton_direct_get_value_for_layer() returns
false, data_label->value is freed but the value is not cleared. and, it is
freed again in get_label() when buxton_direct_get_value() returns error.

valgrind result is as follows:

==4232== Invalid free() / delete / delete[] / realloc()
==4232==    at 0x483FF80: free (vg_replace_malloc.c:473)
==4232==    by 0x14551: get_label (daemon.c:853)
==4232==    by 0x14975: buxtond_handle_message (daemon.c:279)
==4232==    by 0x1514D: handle_client (daemon.c:1303)
==4232==    by 0x13AF3: main (main.c:363)
==4232==  Address 0x4b4cfa0 is 0 bytes inside a block of size 7 free'd
==4232==    at 0x483FF80: free (vg_replace_malloc.c:473)
==4232==    by 0x15DE5: buxton_direct_get_value_for_layer (direct.c:181)
==4232==    by 0x15E07: buxton_direct_get_value (direct.c:59)
==4232==    by 0x14515: get_label (daemon.c:835)
==4232==    by 0x14975: buxtond_handle_message (daemon.c:279)
==4232==    by 0x1514D: handle_client (daemon.c:1303)
==4232==    by 0x13AF3: main (main.c:363)
==4232==

Signed-off-by: Suchang Woo <suchang.woo@samsung.com>
Change-Id: Idbcaa80b60711969a285782e56a849145559283a

src/shared/direct.c

index cfc99a7..b330658 100644 (file)
@@ -179,6 +179,7 @@ int buxton_direct_get_value_for_layer(BuxtonControl *control,
                    !buxton_check_smack_access(client_label, data_label, ACCESS_READ)) {
                        /* Client lacks permission to read the value */
                        free(data_label->value);
+                       data_label->value = NULL;
                        ret = EPERM;
                        goto fail;
                }