summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Aksenov <a.aksenov@samsung.com>2017-03-23 14:13:28 +0300
committerAlexander Aksenov <a.aksenov@samsung.com>2017-03-23 14:13:28 +0300
commitdbde7839216dd997dd8b5403e275923387f4affc (patch)
treece0b0780fa460e1af5da17d4adb13e1e7412ece3
parent4820b196ceeb6f96a4aafc392eedc3b04a451969 (diff)
downloadswap-manager-dbde7839216dd997dd8b5403e275923387f4affc.tar.gz
swap-manager-dbde7839216dd997dd8b5403e275923387f4affc.tar.bz2
swap-manager-dbde7839216dd997dd8b5403e275923387f4affc.zip
Replace variable assignment with memcpy for parse
When message arrived, its packed, so depending on compiler it may lead to unaligned memory access. Change-Id: Ic9976904ad70a9610bb8b5f00886ec1474a7bee1 Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
-rw-r--r--daemon/da_protocol.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c
index d811c03..bc11137 100644
--- a/daemon/da_protocol.c
+++ b/daemon/da_protocol.c
@@ -301,7 +301,9 @@ int parse_int32(struct msg_buf_t *msg, uint32_t *val)
parse_deb("size = %d\n", get_avail_msg_size(msg));
if (get_avail_msg_size(msg) < sizeof(*val))
return 0;
- *val = *(uint32_t *)msg->cur_pos;
+ /* Use memcpy, because when parsing incoming message memory is unaligned
+ * in general */
+ memcpy(val, msg->cur_pos, sizeof(*val));
msg->cur_pos += sizeof(uint32_t);
@@ -316,7 +318,9 @@ int parse_int64(struct msg_buf_t *msg, uint64_t *val)
if (get_avail_msg_size(msg) < sizeof(*val))
return 0;
- *val = *(uint64_t *)msg->cur_pos;
+ /* Use memcpy, because when parsing incoming message memory is unaligned
+ * in general */
+ memcpy(val, msg->cur_pos, sizeof(*val));
parse_deb("<%llu><0x%016llX>\n", *val, *val);
msg->cur_pos += sizeof(uint64_t);