Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
oic: device_id string was leaking
Browse files Browse the repository at this point in the history
As device_id is a fixed size string, we don't even need to allocate it
in the heap

One way to check this bahaviour is running the light-server +
light-scan/light-client-scan sample located in src/samples/flow/oic/.
Use client scan to connect to different servers. Do it several times.
After that closes the client.

Leak information from compiler sanitizer:

Direct leak of 64 byte(s) in 4 object(s) allocated from:
    #0 0x7fd5bbecf93a in __interceptor_malloc /build/gcc-multilib/src/gcc-5.2.0/libsanitizer/asan/asan_malloc_linux.cc:38
    #1 0x7fd59dfa0a29 in hex_ascii_to_binary (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0x8a29)
    #2 0x7fd59dfa0bed in client_connect (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0x8bed)
    #3 0x7fd59dfa32df in device_id_process (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0xb2df)
    #4 0x7fd5bb51b2ca in dispatch_process (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a42ca)
    #5 0x7fd5bb51d282 in flow_send_do (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a6282)
    #6 0x7fd5bb51d7e1 in flow_send_idle (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a67e1)
    #7 0x7fd5bb494a46 in sol_mainloop_common_timeout_process (/home/otavio/local/soletta/lib/libsoletta.so.0+0x11da46)
    #8 0x7fd5bb499244 in sol_mainloop_impl_iter (/home/otavio/local/soletta/lib/libsoletta.so.0+0x122244)
    #9 0x7fd5bb496022 in sol_mainloop_impl_run (/home/otavio/local/soletta/lib/libsoletta.so.0+0x11f022)
    #10 0x7fd5bb499b74 in sol_run (/home/otavio/local/soletta/lib/libsoletta.so.0+0x122b74)
    #11 0x403a7a in main (/home/otavio/local/soletta/bin/sol-fbp-runner+0x403a7a)
    #12 0x7fd5b7df360f in __libc_start_main (/usr/lib/libc.so.6+0x2060f)

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7fd5bbecf93a in __interceptor_malloc /build/gcc-multilib/src/gcc-5.2.0/libsanitizer/asan/asan_malloc_linux.cc:38
    #1 0x7fd59dfa0a29 in hex_ascii_to_binary (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0x8a29)
    #2 0x7fd59dfa0bed in client_connect (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0x8bed)
    #3 0x7fd59dfa32df in device_id_process (//home/otavio/local/soletta/lib/soletta/modules//flow//oic.so+0xb2df)
    #4 0x7fd5bb51b2ca in dispatch_process (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a42ca)
    #5 0x7fd5bb51d282 in flow_send_do (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a6282)
    #6 0x7fd5bb51d7e1 in flow_send_idle (/home/otavio/local/soletta/lib/libsoletta.so.0+0x1a67e1)
    #7 0x7fd5bb494a46 in sol_mainloop_common_timeout_process (/home/otavio/local/soletta/lib/libsoletta.so.0+0x11da46)
    #8 0x7fd5bb494e13 in sol_mainloop_common_idler_process (/home/otavio/local/soletta/lib/libsoletta.so.0+0x11de13)
    #9 0x7fd5bb499258 in sol_mainloop_impl_iter (/home/otavio/local/soletta/lib/libsoletta.so.0+0x122258)
    #10 0x7fd5bb496022 in sol_mainloop_impl_run (/home/otavio/local/soletta/lib/libsoletta.so.0+0x11f022)
    #11 0x7fd5bb499b74 in sol_run (/home/otavio/local/soletta/lib/libsoletta.so.0+0x122b74)
    #12 0x403a7a in main (/home/otavio/local/soletta/bin/sol-fbp-runner+0x403a7a)
    #13 0x7fd5b7df360f in __libc_start_main (/usr/lib/libc.so.6+0x2060f)

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
  • Loading branch information
Otavio Pontes committed Dec 2, 2015
1 parent 39a60de commit 413f46a
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions data/scripts/sol-oic-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ def master_c_as_string(generated, oic_gen_c, oic_gen_h):
struct sol_oic_client client;
const char *rt;
char *device_id;
char device_id[DEVICE_ID_LEN];
struct sol_ptr_vector scanned_ids;
};
Expand Down Expand Up @@ -1416,20 +1416,14 @@ def master_c_as_string(generated, oic_gen_c, oic_gen_h):
return 0;
}
static char *
hex_ascii_to_binary(const char *ascii)
static void
hex_ascii_to_binary(const char *ascii, char *binary)
{
char *binary = malloc(DEVICE_ID_LEN);
if (likely(binary)) {
const char *p;
size_t i;
for (p = ascii, i = 0; i < DEVICE_ID_LEN; i++, p += 2)
binary[i] = as_nibble(*p) << 4 | as_nibble(*(p + 1));
}
const char *p;
size_t i;
return binary;
for (p = ascii, i = 0; i < DEVICE_ID_LEN; i++, p += 2)
binary[i] = as_nibble(*p) << 4 | as_nibble(*(p + 1));
}
static int
Expand All @@ -1440,7 +1434,7 @@ def master_c_as_string(generated, oic_gen_c, oic_gen_h):
return 0;
}
resource->device_id = hex_ascii_to_binary(device_id);
hex_ascii_to_binary(device_id, resource->device_id);
SOL_NULL_CHECK(resource->device_id, -ENOMEM);
if (resource->find_timeout)
Expand Down Expand Up @@ -1497,7 +1491,6 @@ def master_c_as_string(generated, oic_gen_c, oic_gen_h):
sol_ptr_vector_init(&resource->scanned_ids);
resource->node = node;
resource->find_timeout = NULL;
resource->device_id = NULL;
resource->update_schedule_timeout = NULL;
resource->resource = NULL;
resource->funcs = funcs;
Expand All @@ -1513,8 +1506,6 @@ def master_c_as_string(generated, oic_gen_c, oic_gen_h):
static void
client_resource_close(struct client_resource *resource)
{
free(resource->device_id);
if (resource->find_timeout)
sol_timeout_del(resource->find_timeout);
if (resource->update_schedule_timeout)
Expand Down

0 comments on commit 413f46a

Please sign in to comment.