Projects STRLCPY criu Commits 02dff551
🤬
  • ■ ■ ■ ■ ■ ■
    cr-service.c
    skipped 6 lines
    7 7  #include <stdlib.h>
    8 8  #include <errno.h>
    9 9  #include <string.h>
     10 +#include <alloca.h>
    10 11  #include <sys/types.h>
    11 12  #include <sys/socket.h>
    12 13  #include <sys/un.h>
    skipped 23 lines
    36 37   
    37 38  unsigned int service_sk_ino = -1;
    38 39   
    39  -static int recv_criu_msg(int socket_fd, CriuReq **msg)
     40 +static int recv_criu_msg(int socket_fd, CriuReq **req)
    40 41  {
    41  - unsigned char buf[CR_MAX_MSG_SIZE];
     42 + unsigned char *buf;
    42 43   int len;
    43 44   
    44  - len = read(socket_fd, buf, CR_MAX_MSG_SIZE);
     45 + len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);
     46 + if (len == -1) {
     47 + pr_perror("Can't read request");
     48 + return -1;
     49 + }
     50 + 
     51 + buf = alloca(len);
     52 + 
     53 + len = recv(socket_fd, buf, len, MSG_TRUNC);
    45 54   if (len == -1) {
    46 55   pr_perror("Can't read request");
    47 56   return -1;
    skipped 5 lines
    53 62   return -1;
    54 63   }
    55 64   
    56  - *msg = criu_req__unpack(NULL, len, buf);
    57  - if (!*msg) {
     65 + *req = criu_req__unpack(NULL, len, buf);
     66 + if (!*req) {
    58 67   pr_perror("Failed unpacking request");
    59 68   return -1;
    60 69   }
    skipped 3 lines
    64 73   
    65 74  static int send_criu_msg(int socket_fd, CriuResp *msg)
    66 75  {
    67  - unsigned char buf[CR_MAX_MSG_SIZE];
     76 + unsigned char *buf;
    68 77   int len;
    69 78   
    70 79   len = criu_resp__get_packed_size(msg);
     80 + 
     81 + buf = alloca(len);
    71 82   
    72 83   if (criu_resp__pack(msg, buf) != len) {
    73 84   pr_perror("Failed packing response");
    skipped 840 lines
  • ■ ■ ■ ■ ■
    include/cr-service-const.h
    1 1  #ifndef __CR_SERVICE_CONST_H__
    2 2  #define __CR_SERVICE_CONST_H__
    3 3   
    4  -#define CR_MAX_MSG_SIZE 1024
    5 4  #define CR_DEFAULT_SERVICE_ADDRESS "/var/run/criu_service.socket"
    6 5   
    7 6  #endif /* __CR_SERVICE_CONST_H__ */
    skipped 1 lines
  • ■ ■ ■ ■ ■
    lib/criu.c
    skipped 9 lines
    10 10  #include <stdlib.h>
    11 11  #include <errno.h>
    12 12  #include <signal.h>
     13 +#include <alloca.h>
    13 14   
    14 15  #include "criu.h"
    15 16  #include "rpc.pb-c.h"
    skipped 295 lines
    311 312   
    312 313  static CriuResp *recv_resp(int socket_fd)
    313 314  {
    314  - unsigned char buf[CR_MAX_MSG_SIZE];
     315 + unsigned char *buf;
    315 316   int len;
    316 317   CriuResp *msg = 0;
    317 318   
    318  - len = read(socket_fd, buf, CR_MAX_MSG_SIZE);
     319 + len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);
    319 320   if (len == -1) {
    320  - perror("Can't read response");
     321 + perror("Can't read request");
     322 + goto err;
     323 + }
     324 + 
     325 + buf = alloca(len);
     326 + 
     327 + len = recv(socket_fd, buf, len, MSG_TRUNC);
     328 + if (len == -1) {
     329 + perror("Can't read request");
    321 330   goto err;
    322 331   }
    323 332   
    skipped 11 lines
    335 344   
    336 345  static int send_req(int socket_fd, CriuReq *req)
    337 346  {
    338  - unsigned char buf[CR_MAX_MSG_SIZE];
     347 + unsigned char *buf;
    339 348   int len;
    340 349   
    341 350   len = criu_req__get_packed_size(req);
     351 + 
     352 + buf = alloca(len);
    342 353   
    343 354   if (criu_req__pack(req, buf) != len) {
    344 355   perror("Failed packing request");
    skipped 350 lines
Please wait...
Page is in error, reload to recover