diff options
author | Gihun Chang <gihun.chang@samsung.com> | 2016-10-13 01:54:19 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2016-10-13 01:54:19 -0700 |
commit | 16ea946ac9018e0d934a4b3ed6575550cb027f2a (patch) | |
tree | ca982f72334873561666e166f68c49dc583e156c | |
parent | f6552447b6b4e8d19ac4482345edccd7db573cfe (diff) | |
parent | 30b8c8be15c797e1aa5096783e0db6a6b9935039 (diff) | |
download | ttrace-16ea946ac9018e0d934a4b3ed6575550cb027f2a.tar.gz ttrace-16ea946ac9018e0d934a4b3ed6575550cb027f2a.tar.bz2 ttrace-16ea946ac9018e0d934a4b3ed6575550cb027f2a.zip |
Merge "Add defence codes to prevent unexpected behavior" into tizensubmit/tizen_3.0/20161028.092423submit/tizen_3.0/20161028.062323submit/tizen/20161026.042356submit/tizen/20161023.232219submit/tizen/20161013.085632accepted/tizen/wearable/20161014.022418accepted/tizen/tv/20161014.022325accepted/tizen/mobile/20161014.022535accepted/tizen/ivi/20161014.022408accepted/tizen/common/20161013.160625accepted/tizen/3.0/wearable/20161028.150809accepted/tizen/3.0/tv/20161028.143439accepted/tizen/3.0/mobile/20161028.143207accepted/tizen/3.0/ivi/20161028.151232
-rwxr-xr-x | src/ttrace.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/ttrace.c b/src/ttrace.c index 8bb50df..16b27ca 100755 --- a/src/ttrace.c +++ b/src/ttrace.c @@ -120,6 +120,16 @@ static inline uint64_t isTagEnabled(uint64_t cur_tag) return (cur_tag & *cur_enabled_tag); } +int check_params(int fd, char* buf, int len, const char* func) +{ + if (fd <= 0 || buf == NULL || len < 0) { + fprintf(stderr, "Currupted arguments, fd: %d, buf: %p, len: %d at %s.\n", + fd, buf, len, func); + return -1; + } + return 0; +} + /* * Tracing API for synchronous events: traceBegin()/traceEnd() * - tag: the tracing tag @@ -141,11 +151,15 @@ void traceBegin(uint64_t tag, const char *name, ...) if (len > MAX_LEN) len = MAX_LEN - 1; + if (check_params(g_trace_handle_fd, buf, len, __func__) < 0) + return; + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len); else ret = write(g_trace_handle_fd, buf, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceBegin.\n", len, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceBegin.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG @@ -159,14 +173,19 @@ void traceEnd(uint64_t tag) { if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) { int ret = 0; + int len = 1; char end = 'E'; TTRACE_LOG("traceEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag); - if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write("E", 1); - else ret = write(g_trace_handle_fd, &end, 1); + if (check_params(g_trace_handle_fd, &end, len, __func__) < 0) + return; + + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(&end, len); + else ret = write(g_trace_handle_fd, &end, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceEnd.\n", 1, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceEnd.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG @@ -204,11 +223,15 @@ void traceAsyncBegin(uint64_t tag, int32_t cookie, const char *name, ...) len = MAX_LEN - 1; } + if (check_params(g_trace_handle_fd, buf, len, __func__) < 0) + return; + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len); else ret = write(g_trace_handle_fd, buf, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncBegin.\n", len, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncBegin.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG @@ -239,12 +262,15 @@ void traceAsyncEnd(uint64_t tag, int32_t cookie, const char *name, ...) len = MAX_LEN - 1; } + if (check_params(g_trace_handle_fd, buf, len, __func__) < 0) + return; if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len); else ret = write(g_trace_handle_fd, buf, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncEnd.\n", len, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncEnd.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG @@ -275,19 +301,27 @@ void traceMark(uint64_t tag, const char *name, ...) if (len > MAX_LEN) len = MAX_LEN - 1; + if (check_params(g_trace_handle_fd, buf, len, __func__) < 0) + return; + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len); else ret = write(g_trace_handle_fd, buf, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", len, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", + len, ret, errno); #endif + len = 1; + if (check_params(g_trace_handle_fd, &end, len, __func__) < 0) + return; - if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write("E", 1); - else ret = write(g_trace_handle_fd, &end, 1); + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(&end, len); + else ret = write(g_trace_handle_fd, &end, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", 1, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG @@ -325,11 +359,15 @@ void traceCounter(uint64_t tag, int32_t value, const char *name, ...) len = MAX_LEN - 1; } + if (check_params(g_trace_handle_fd, buf, len, __func__) < 0) + return; + if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len); else ret = write(g_trace_handle_fd, buf, len); #ifdef TTRACE_DEBUG if (ret < 0) - fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceCounter.\n", len, ret, errno); + fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceCounter.\n", + len, ret, errno); #endif } #ifdef TTRACE_DEBUG |