From fae2d76b7740305153aa5b07c0bd29c8716980b9 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Thu, 7 Aug 2014 13:56:21 +0900 Subject: [PATCH] tethering: improve error cases. - null pointer dereferences - control flow issues - integer handling issues Change-Id: I9338e0997f86f62e014df972404320277c42a31b Signed-off-by: Kitae Kim --- tizen/src/tethering/common.c | 8 +++++--- tizen/src/tethering/encode_fb.c | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tizen/src/tethering/common.c b/tizen/src/tethering/common.c index 6e11e76..a17c941 100644 --- a/tizen/src/tethering/common.c +++ b/tizen/src/tethering/common.c @@ -162,6 +162,7 @@ bool send_msg_to_controller(void *msg) if (errno == EAGAIN) { fd_set writefds; struct timeval timeout; + int result = 0; FD_ZERO(&writefds); FD_SET(sockfd, &writefds); @@ -169,9 +170,10 @@ bool send_msg_to_controller(void *msg) timeout.tv_sec = 1; timeout.tv_usec = 0; - ret = select(sockfd + 1, NULL, &writefds, NULL, &timeout); - if (ret < 0) { + result = select(sockfd + 1, NULL, &writefds, NULL, &timeout); + if (result < 0) { LOG_INFO("not possible to send data\n"); + ret = false; break; } LOG_TRACE("possible to send data\n"); @@ -634,7 +636,7 @@ static int start_tethering_socket(const char *ipaddress, int port) } } - if (ret < 0 && ret != -EISCONN) { + if (ret < 0) { if (ret == -ECONNREFUSED) { LOG_INFO("socket connection is refused\n"); set_tethering_connection_status(CONNREFUSED); diff --git a/tizen/src/tethering/encode_fb.c b/tizen/src/tethering/encode_fb.c index 8f4f717..139fcb1 100644 --- a/tizen/src/tethering/encode_fb.c +++ b/tizen/src/tethering/encode_fb.c @@ -104,10 +104,10 @@ static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t len) if (!p->buffer) { LOG_SEVERE("failed to allocate \n"); + } else { + memcpy(p->buffer + p->length, data, len); + p->length += len; } - - memcpy(p->buffer + p->length, data, len); - p->length += len; } static void user_flush_data(png_structp png_ptr) @@ -162,7 +162,7 @@ static void *encode_png(void) LOG_TRACE("png_create_info_struct\n"); info_ptr = png_create_info_struct(png_ptr); - if (!png_ptr) { + if (!info_ptr) { LOG_SEVERE("png_create_info_struct failure\n"); g_free(surface); png_destroy_write_struct(&png_ptr, &info_ptr); -- 2.7.4