<div dir="ltr">Tested this and it seems to fix my communication issue. Thanks.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 6:45 AM, Andrey Vagin <span dir="ltr"><<a href="mailto:avagin@openvz.org" target="_blank">avagin@openvz.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently we use a static buffer, but it is too small.<br>
<br>
Error (cr-service.c:58): Failed unpacking request: Success<br>
Error (cr-service.c:694): Can't recv request: Success<br>
data too short after length-prefix of 1217<br>
<br>
v2: use recv instead on recvmsg<br>
<br>
Reported-by: Ross Boucher <<a href="mailto:rboucher@gmail.com">rboucher@gmail.com</a>><br>
Cc: Ross Boucher <<a href="mailto:rboucher@gmail.com">rboucher@gmail.com</a>><br>
Signed-off-by: Andrey Vagin <<a href="mailto:avagin@openvz.org">avagin@openvz.org</a>><br>
---<br>
cr-service.c | 23 +++++++++++++++++------<br>
include/cr-service-const.h | 1 -<br>
lib/criu.c | 19 +++++++++++++++----<br>
3 files changed, 32 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/cr-service.c b/cr-service.c<br>
index 0f0e2e2..2173376 100644<br>
--- a/cr-service.c<br>
+++ b/cr-service.c<br>
@@ -7,6 +7,7 @@<br>
#include <stdlib.h><br>
#include <errno.h><br>
#include <string.h><br>
+#include <alloca.h><br>
#include <sys/types.h><br>
#include <sys/socket.h><br>
#include <sys/un.h><br>
@@ -36,12 +37,20 @@<br>
<br>
unsigned int service_sk_ino = -1;<br>
<br>
-static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
+static int recv_criu_msg(int socket_fd, CriuReq **req)<br>
{<br>
- unsigned char buf[CR_MAX_MSG_SIZE];<br>
+ unsigned char *buf;<br>
int len;<br>
<br>
- len = read(socket_fd, buf, CR_MAX_MSG_SIZE);<br>
+ len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);<br>
+ if (len == -1) {<br>
+ pr_perror("Can't read request");<br>
+ return -1;<br>
+ }<br>
+<br>
+ buf = alloca(len);<br>
+<br>
+ len = recv(socket_fd, buf, len, MSG_TRUNC);<br>
if (len == -1) {<br>
pr_perror("Can't read request");<br>
return -1;<br>
@@ -53,8 +62,8 @@ static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
return -1;<br>
}<br>
<br>
- *msg = criu_req__unpack(NULL, len, buf);<br>
- if (!*msg) {<br>
+ *req = criu_req__unpack(NULL, len, buf);<br>
+ if (!*req) {<br>
pr_perror("Failed unpacking request");<br>
return -1;<br>
}<br>
@@ -64,11 +73,13 @@ static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
<br>
static int send_criu_msg(int socket_fd, CriuResp *msg)<br>
{<br>
- unsigned char buf[CR_MAX_MSG_SIZE];<br>
+ unsigned char *buf;<br>
int len;<br>
<br>
len = criu_resp__get_packed_size(msg);<br>
<br>
+ buf = alloca(len);<br>
+<br>
if (criu_resp__pack(msg, buf) != len) {<br>
pr_perror("Failed packing response");<br>
return -1;<br>
diff --git a/include/cr-service-const.h b/include/cr-service-const.h<br>
index 668882b..b8827f4 100644<br>
--- a/include/cr-service-const.h<br>
+++ b/include/cr-service-const.h<br>
@@ -1,7 +1,6 @@<br>
#ifndef __CR_SERVICE_CONST_H__<br>
#define __CR_SERVICE_CONST_H__<br>
<br>
-#define CR_MAX_MSG_SIZE 1024<br>
#define CR_DEFAULT_SERVICE_ADDRESS "/var/run/criu_service.socket"<br>
<br>
#endif /* __CR_SERVICE_CONST_H__ */<br>
diff --git a/lib/criu.c b/lib/criu.c<br>
index 9308250..ff7e400 100644<br>
--- a/lib/criu.c<br>
+++ b/lib/criu.c<br>
@@ -10,6 +10,7 @@<br>
#include <stdlib.h><br>
#include <errno.h><br>
#include <signal.h><br>
+#include <alloca.h><br>
<br>
#include "criu.h"<br>
#include "rpc.pb-c.h"<br>
@@ -311,13 +312,21 @@ er:<br>
<br>
static CriuResp *recv_resp(int socket_fd)<br>
{<br>
- unsigned char buf[CR_MAX_MSG_SIZE];<br>
+ unsigned char *buf;<br>
int len;<br>
CriuResp *msg = 0;<br>
<br>
- len = read(socket_fd, buf, CR_MAX_MSG_SIZE);<br>
+ len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);<br>
if (len == -1) {<br>
- perror("Can't read response");<br>
+ perror("Can't read request");<br>
+ goto err;<br>
+ }<br>
+<br>
+ buf = alloca(len);<br>
+<br>
+ len = recv(socket_fd, buf, len, MSG_TRUNC);<br>
+ if (len == -1) {<br>
+ perror("Can't read request");<br>
goto err;<br>
}<br>
<br>
@@ -335,11 +344,13 @@ err:<br>
<br>
static int send_req(int socket_fd, CriuReq *req)<br>
{<br>
- unsigned char buf[CR_MAX_MSG_SIZE];<br>
+ unsigned char *buf;<br>
int len;<br>
<br>
len = criu_req__get_packed_size(req);<br>
<br>
+ buf = alloca(len);<br>
+<br>
if (criu_req__pack(req, buf) != len) {<br>
perror("Failed packing request");<br>
goto err;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0<br>
<br>
</font></span></blockquote></div><br></div>