1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-08-31 20:37:07 +00:00

Fix variable sizes in named pipe transport.

Should use 32-bit integer to store the length header in transport protocol.
This commit is contained in:
Jonathan Xu
2018-11-15 17:48:13 +08:00
parent d19a3d1a2c
commit 041fd68e1c

View File

@@ -10,6 +10,7 @@
#include <unistd.h>
#endif // !defined(WIN32)
#include <glib.h>
#include <glib/gstdio.h>
#include <jansson.h>
@@ -213,15 +214,15 @@ static void* named_pipe_client_handler(void *arg)
// SearpcNamedPipeServer *server = data->server;
SearpcNamedPipe connfd = data->connfd;
size_t len;
size_t bufsize = 4096;
guint32 len;
guint32 bufsize = 4096;
char *buf = g_malloc(bufsize);
g_debug ("start to serve on pipe client\n");
while (1) {
len = 0;
if (pipe_read_n(connfd, &len, sizeof(uint32_t)) < 0) {
if (pipe_read_n(connfd, &len, sizeof(guint32)) < 0) {
g_warning("failed to read rpc request size: %s", strerror(errno));
break;
}
@@ -247,12 +248,13 @@ static void* named_pipe_client_handler(void *arg)
break;
}
size_t ret_len;
gsize ret_len;
char *ret_str = searpc_server_call_function (service, body, strlen(body), &ret_len);
g_free (service);
g_free (body);
if (pipe_write_n(connfd, &ret_len, sizeof(uint32_t)) < 0) {
len = (guint32)ret_len;
if (pipe_write_n(connfd, &len, sizeof(guint32)) < 0) {
g_warning("failed to send rpc response(%s): %s", ret_str, strerror(errno));
g_free (ret_str);
break;
@@ -344,16 +346,15 @@ char *searpc_named_pipe_send(void *arg, const gchar *fcall_str,
SearpcNamedPipeClient *client = data->client;
char *json_str = request_to_json(data->service, fcall_str, fcall_len);
size_t json_len = strlen(json_str);
guint32 len = (guint32)strlen(json_str);
uint32_t len = json_len;
if (pipe_write_n(client->pipe_fd, &len, sizeof(uint32_t)) < 0) {
if (pipe_write_n(client->pipe_fd, &len, sizeof(guint32)) < 0) {
g_warning("failed to send rpc call: %s", strerror(errno));
free (json_str);
return NULL;
}
if (pipe_write_n(client->pipe_fd, json_str, json_len) < 0) {
if (pipe_write_n(client->pipe_fd, json_str, len) < 0) {
g_warning("failed to send rpc call: %s", strerror(errno));
free (json_str);
return NULL;
@@ -361,7 +362,7 @@ char *searpc_named_pipe_send(void *arg, const gchar *fcall_str,
free (json_str);
if (pipe_read_n(client->pipe_fd, &len, sizeof(uint32_t)) < 0) {
if (pipe_read_n(client->pipe_fd, &len, sizeof(guint32)) < 0) {
g_warning("failed to read rpc response: %s", strerror(errno));
return NULL;
}