summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/message-port.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/message-port.c b/src/message-port.c
index b5a0364..dacd5ae 100755
--- a/src/message-port.c
+++ b/src/message-port.c
@@ -94,13 +94,13 @@ typedef struct message_port_pkt {
int remote_port_name_len;
char *remote_port_name;
bool is_bidirection;
+ bool is_trusted;
int data_len;
unsigned char *data;
} message_port_pkt_s;
typedef struct message_port_callback_info {
messageport_message_cb callback;
- bool is_trusted;
int local_id;
char *remote_app_id;
GIOChannel *gio_read;
@@ -602,6 +602,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
close(fd);
return NULL;
}
+
if (__read_string_from_socket(fd, (char **)&pkt->remote_port_name, &pkt->remote_port_name_len) != MESSAGEPORT_ERROR_NONE) {
LOGE("read socket fail: port_name");
free(pkt->remote_port_name);
@@ -609,6 +610,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
close(fd);
return NULL;
}
+
if (__read_socket(fd, (char *)&pkt->is_bidirection, sizeof(pkt->is_bidirection), &nb) != MESSAGEPORT_ERROR_NONE) {
LOGE("read socket fail: is_bidirection");
free(pkt->remote_port_name);
@@ -616,6 +618,15 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
close(fd);
return NULL;
}
+
+ if (__read_socket(fd, (char *)&pkt->is_trusted, sizeof(pkt->is_trusted), &nb) != MESSAGEPORT_ERROR_NONE) {
+ LOGE("read socket fail: is_trusted");
+ free(pkt->remote_port_name);
+ free(pkt);
+ close(fd);
+ return NULL;
+ }
+
if (__read_string_from_socket(fd, (char **)&pkt->data, &pkt->data_len) != MESSAGEPORT_ERROR_NONE) {
LOGE("read socket fail: data");
free(pkt->remote_port_name);
@@ -623,6 +634,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
close(fd);
return NULL;
}
+
return pkt;
}
@@ -671,9 +683,9 @@ static gboolean __socket_request_handler(GIOChannel *gio,
kb = bundle_decode(pkt->data, pkt->data_len);
if (pkt->is_bidirection)
- mi->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, mi->is_trusted, kb, NULL);
+ mi->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, pkt->is_trusted, kb, NULL);
else
- mi->callback(mi->local_id, mi->remote_app_id, NULL, mi->is_trusted, kb, NULL);
+ mi->callback(mi->local_id, mi->remote_app_id, NULL, pkt->is_trusted, kb, NULL);
if (pkt) {
if (pkt->remote_port_name)
@@ -762,7 +774,6 @@ static bool send_message(GVariant *parameters, GDBusMethodInvocation *invocation
callback_info->local_id = mi->local_id;
callback_info->remote_app_id = strdup(local_appid);
callback_info->callback = mi->callback;
- callback_info->is_trusted = local_trusted;
GError *error = NULL;
GDBusMessage *msg = g_dbus_method_invocation_get_message(invocation);
@@ -1232,17 +1243,24 @@ int __message_port_send_async(int sockfd, bundle *kb, const char *local_port,
_LOGE("write local_port fail");
return MESSAGEPORT_ERROR_IO_ERROR;
}
+
if (__write_socket(sockfd, (char *)&is_bidirection, sizeof(is_bidirection), &nb) != MESSAGEPORT_ERROR_NONE) {
_LOGE("write is_bidirection fail");
return MESSAGEPORT_ERROR_IO_ERROR;
}
+ if (__write_socket(sockfd, (char *)&local_trusted, sizeof(local_trusted), &nb) != MESSAGEPORT_ERROR_NONE) {
+ _LOGE("write local_trusted fail");
+ return MESSAGEPORT_ERROR_IO_ERROR;
+ }
+
bundle_encode(kb, &kb_data, &data_len);
if (kb_data == NULL) {
_LOGE("bundle encode fail");
ret = MESSAGEPORT_ERROR_IO_ERROR;
goto out;
}
+
if (data_len > MAX_MESSAGE_SIZE) {
_LOGE("bigger than max size\n");
ret = MESSAGEPORT_ERROR_MAX_EXCEEDED;