mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-03 13:54:57 +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:
@@ -10,6 +10,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif // !defined(WIN32)
|
#endif // !defined(WIN32)
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
@@ -213,15 +214,15 @@ static void* named_pipe_client_handler(void *arg)
|
|||||||
// SearpcNamedPipeServer *server = data->server;
|
// SearpcNamedPipeServer *server = data->server;
|
||||||
SearpcNamedPipe connfd = data->connfd;
|
SearpcNamedPipe connfd = data->connfd;
|
||||||
|
|
||||||
size_t len;
|
guint32 len;
|
||||||
size_t bufsize = 4096;
|
guint32 bufsize = 4096;
|
||||||
char *buf = g_malloc(bufsize);
|
char *buf = g_malloc(bufsize);
|
||||||
|
|
||||||
g_debug ("start to serve on pipe client\n");
|
g_debug ("start to serve on pipe client\n");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
len = 0;
|
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));
|
g_warning("failed to read rpc request size: %s", strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -247,12 +248,13 @@ static void* named_pipe_client_handler(void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ret_len;
|
gsize ret_len;
|
||||||
char *ret_str = searpc_server_call_function (service, body, strlen(body), &ret_len);
|
char *ret_str = searpc_server_call_function (service, body, strlen(body), &ret_len);
|
||||||
g_free (service);
|
g_free (service);
|
||||||
g_free (body);
|
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_warning("failed to send rpc response(%s): %s", ret_str, strerror(errno));
|
||||||
g_free (ret_str);
|
g_free (ret_str);
|
||||||
break;
|
break;
|
||||||
@@ -344,16 +346,15 @@ char *searpc_named_pipe_send(void *arg, const gchar *fcall_str,
|
|||||||
SearpcNamedPipeClient *client = data->client;
|
SearpcNamedPipeClient *client = data->client;
|
||||||
|
|
||||||
char *json_str = request_to_json(data->service, fcall_str, fcall_len);
|
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(guint32)) < 0) {
|
||||||
if (pipe_write_n(client->pipe_fd, &len, sizeof(uint32_t)) < 0) {
|
|
||||||
g_warning("failed to send rpc call: %s", strerror(errno));
|
g_warning("failed to send rpc call: %s", strerror(errno));
|
||||||
free (json_str);
|
free (json_str);
|
||||||
return NULL;
|
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));
|
g_warning("failed to send rpc call: %s", strerror(errno));
|
||||||
free (json_str);
|
free (json_str);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -361,7 +362,7 @@ char *searpc_named_pipe_send(void *arg, const gchar *fcall_str,
|
|||||||
|
|
||||||
free (json_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));
|
g_warning("failed to read rpc response: %s", strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user