summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2015-08-31 14:23:08 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2015-08-31 14:23:15 +0300
commit602fdd84f95c0882c186299ceafd393dd732bb88 (patch)
tree271d10d8a223b534ce7c67b4fd09c3de02a0189f
parent19477e5363d7ea4c0dd74b21f2b4b73a587fea96 (diff)
Fix crash when objects list requested
-rw-r--r--src/bin/cli.c15
-rw-r--r--src/lib/debug_common.c4
-rw-r--r--src/lib/debug_common.h2
-rw-r--r--src/lib/debug_eo.c2
-rw-r--r--src/lib/edbg_preload.c4
-rw-r--r--src/lib/network.c4
-rw-r--r--src/lib/network.h2
7 files changed, 21 insertions, 12 deletions
diff --git a/src/bin/cli.c b/src/bin/cli.c
index 2a61dce..cbe1966 100644
--- a/src/bin/cli.c
+++ b/src/bin/cli.c
@@ -1,4 +1,5 @@
1#include <sys/epoll.h> 1#include <sys/epoll.h>
2#include <sys/socket.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <termios.h> 4#include <termios.h>
4 5
@@ -171,7 +172,7 @@ _function_break(Lexer *l)
171} 172}
172 173
173static Eina_Bool 174static Eina_Bool
174_function_unbreak(Lexer *l) 175_function_unbreak(Lexer *l EINA_UNUSED)
175{ 176{
176 Eina_Bool ret = EINA_TRUE; 177 Eina_Bool ret = EINA_TRUE;
177 int size, size2; 178 int size, size2;
@@ -430,13 +431,21 @@ _thread_start(void *arg EINA_UNUSED)
430{ 431{
431 while (EINA_TRUE) 432 while (EINA_TRUE)
432 { 433 {
433 int nbBytes = network_receive(-1, buffer, MAX_BUF); 434 unsigned int len = 0;
435 int nbBytes = network_receive(-1, &len, sizeof(unsigned int), MSG_PEEK);
434 if (nbBytes <= 0) return EINA_FALSE; 436 if (nbBytes <= 0) return EINA_FALSE;
435 else 437 else
436 { 438 {
439 int i = 0;
437 void *buf_ret = NULL; 440 void *buf_ret = NULL;
438 int size_ret = 0; 441 int size_ret = 0;
439 if (debug_unpack(buffer, nbBytes, &buf_ret, &size_ret)) 442 while (len)
443 {
444 nbBytes = network_receive(-1, buffer + i, len, 0);
445 len -= nbBytes;
446 i += nbBytes;
447 }
448 if (debug_unpack(buffer, &buf_ret, &size_ret))
440 { 449 {
441 if (size_ret) network_send(-1, buf_ret, size_ret); 450 if (size_ret) network_send(-1, buf_ret, size_ret);
442 } 451 }
diff --git a/src/lib/debug_common.c b/src/lib/debug_common.c
index 6582eb5..cfe71dc 100644
--- a/src/lib/debug_common.c
+++ b/src/lib/debug_common.c
@@ -41,7 +41,7 @@ debug_pack(const char *opcode, const char *opcode_resp, void *buf, int size, voi
41} 41}
42 42
43Eina_Bool 43Eina_Bool
44debug_unpack(const void *buf, int size, void *buf_ret, int *size_ret) 44debug_unpack(const void *buf, void *buf_ret, int *size_ret)
45{ 45{
46 const _Eo_Request *r = buf; 46 const _Eo_Request *r = buf;
47 printf("Opcode %s\n", r->opcode_req); 47 printf("Opcode %s\n", r->opcode_req);
@@ -50,7 +50,7 @@ debug_unpack(const void *buf, int size, void *buf_ret, int *size_ret)
50 { 50 {
51 void *hbuf = NULL; 51 void *hbuf = NULL;
52 int hsize = 0; 52 int hsize = 0;
53 handler((char *)buf + sizeof(*r), size - sizeof(*r), &hbuf, &hsize); 53 handler((char *)buf + sizeof(*r), r->len - sizeof(*r), &hbuf, &hsize);
54 if (hsize) debug_pack(r->opcode_resp, "", hbuf, hsize, buf_ret, size_ret); 54 if (hsize) debug_pack(r->opcode_resp, "", hbuf, hsize, buf_ret, size_ret);
55 free(hbuf); 55 free(hbuf);
56 } 56 }
diff --git a/src/lib/debug_common.h b/src/lib/debug_common.h
index ed019ca..e810ff8 100644
--- a/src/lib/debug_common.h
+++ b/src/lib/debug_common.h
@@ -7,7 +7,7 @@ void debug_common_init();
7 7
8Eina_Bool debug_pack(const char *opcode, const char *opcode_resp, void *buf, int size, void **buf_ret, int *size_ret); 8Eina_Bool debug_pack(const char *opcode, const char *opcode_resp, void *buf, int size, void **buf_ret, int *size_ret);
9 9
10Eina_Bool debug_unpack(const void *buf, int size, void *buf_ret, int *size_ret); 10Eina_Bool debug_unpack(const void *buf, void *buf_ret, int *size_ret);
11 11
12void debug_opcode_register(const char *opcode, Debug_Handler_Cb handler); 12void debug_opcode_register(const char *opcode, Debug_Handler_Cb handler);
13 13
diff --git a/src/lib/debug_eo.c b/src/lib/debug_eo.c
index 866e46c..caf65de 100644
--- a/src/lib/debug_eo.c
+++ b/src/lib/debug_eo.c
@@ -44,7 +44,7 @@ Eina_List *
44debug_eo_objects_list(const void *buf, int size) 44debug_eo_objects_list(const void *buf, int size)
45{ 45{
46 _List_Response *r = eet_data_descriptor_decode(_list_resp_edd, buf, size); 46 _List_Response *r = eet_data_descriptor_decode(_list_resp_edd, buf, size);
47 Eina_List *ret = r->objs; 47 Eina_List *ret = r?r->objs:NULL;
48 free(r); 48 free(r);
49 return ret; 49 return ret;
50} 50}
diff --git a/src/lib/edbg_preload.c b/src/lib/edbg_preload.c
index d0c8948..7052bcf 100644
--- a/src/lib/edbg_preload.c
+++ b/src/lib/edbg_preload.c
@@ -18,13 +18,13 @@ static char *buffer = NULL;
18static Eina_Bool 18static Eina_Bool
19_buffer_recv(int fd) 19_buffer_recv(int fd)
20{ 20{
21 int nbBytes = network_receive(fd, buffer, MAX_BUF); 21 int nbBytes = network_receive(fd, buffer, MAX_BUF, 0);
22 if (nbBytes <= 0) return EINA_FALSE; 22 if (nbBytes <= 0) return EINA_FALSE;
23 else 23 else
24 { 24 {
25 void *buf_ret = NULL; 25 void *buf_ret = NULL;
26 int size_ret = 0; 26 int size_ret = 0;
27 if (debug_unpack(buffer, nbBytes, &buf_ret, &size_ret)) 27 if (debug_unpack(buffer, &buf_ret, &size_ret))
28 { 28 {
29 if (size_ret) network_send(fd, buf_ret, size_ret); 29 if (size_ret) network_send(fd, buf_ret, size_ret);
30 } 30 }
diff --git a/src/lib/network.c b/src/lib/network.c
index 503acff..00e3433 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -101,9 +101,9 @@ network_broadcast(const void *buffer, int len)
101} 101}
102 102
103int 103int
104network_receive(int fd, void *buffer, unsigned int max_len) 104network_receive(int fd, void *buffer, unsigned int max_len, int flags)
105{ 105{
106 return recv(fd == -1 ? mainfd : fd, buffer, max_len, 0); 106 return recv(fd == -1 ? mainfd : fd, buffer, max_len, flags);
107} 107}
108 108
109void 109void
diff --git a/src/lib/network.h b/src/lib/network.h
index 9f93f6b..cb0031f 100644
--- a/src/lib/network.h
+++ b/src/lib/network.h
@@ -24,7 +24,7 @@ void
24network_broadcast(const void *buffer, int len); 24network_broadcast(const void *buffer, int len);
25 25
26int 26int
27network_receive(int fd, void *buffer, unsigned int max_len); 27network_receive(int fd, void *buffer, unsigned int max_len, int flags);
28 28
29void 29void
30network_close(int fd); 30network_close(int fd);