Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1ab36f9 authored by repo sync's avatar repo sync
Browse files

Fix network order for marshalling in keystore interface.

This will fix the endian issue for heterogeneous architectures in keystore marshalling interface.
parent 0f0767d4
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -242,6 +242,7 @@ static int set_read_timeout(int socket)
{
{
    struct timeval tv;
    struct timeval tv;
    tv.tv_sec = READ_TIMEOUT;
    tv.tv_sec = READ_TIMEOUT;
    tv.tv_usec = 0;
    if (setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,  sizeof tv))
    if (setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,  sizeof tv))
    {
    {
        LOGE("setsockopt failed");
        LOGE("setsockopt failed");
+7 −1
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#define __NETKEYSTORE_H__
#define __NETKEYSTORE_H__


#include <stdio.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <cutils/sockets.h>
#include <cutils/sockets.h>
#include <cutils/log.h>
#include <cutils/log.h>


@@ -68,6 +69,8 @@ static inline int read_marshal(int s, LPC_MARSHAL *cmd)
        LOGE("failed to read header\n");
        LOGE("failed to read header\n");
        return -1;
        return -1;
    }
    }
    cmd->len = ntohl(cmd->len);
    cmd->opcode = ntohl(cmd->opcode);
    if (cmd->len > BUFFER_MAX) {
    if (cmd->len > BUFFER_MAX) {
        LOGE("invalid size %d\n", cmd->len);
        LOGE("invalid size %d\n", cmd->len);
        return -1;
        return -1;
@@ -82,11 +85,14 @@ static inline int read_marshal(int s, LPC_MARSHAL *cmd)


static inline int write_marshal(int s, LPC_MARSHAL *cmd)
static inline int write_marshal(int s, LPC_MARSHAL *cmd)
{
{
    int len = cmd->len;
    cmd->len = htonl(cmd->len);
    cmd->opcode = htonl(cmd->opcode);
    if (writex(s, cmd, 2 * sizeof(uint32_t))) {
    if (writex(s, cmd, 2 * sizeof(uint32_t))) {
        LOGE("failed to write marshal header\n");
        LOGE("failed to write marshal header\n");
        return -1;
        return -1;
    }
    }
    if (writex(s, cmd->data, cmd->len)) {
    if (writex(s, cmd->data, len)) {
        LOGE("failed to write marshal data\n");
        LOGE("failed to write marshal data\n");
        return -1;
        return -1;
    }
    }
+16 −15
Original line number Original line Diff line number Diff line
@@ -121,15 +121,16 @@ public class ServiceCommand {
        Reply reply = new Reply();
        Reply reply = new Reply();


        if (!readBytes(buf, 4)) return null;
        if (!readBytes(buf, 4)) return null;
        reply.len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8) |
        reply.len = ((((int) buf[0]) & 0xff) << 24) |
                ((((int) buf[2]) & 0xff) << 16) |
                ((((int) buf[1]) & 0xff) << 16) |
                ((((int) buf[3]) & 0xff) << 24);
                ((((int) buf[2]) & 0xff) << 8) |
                (((int) buf[3]) & 0xff);


        if (!readBytes(buf, 4)) return null;
        if (!readBytes(buf, 4)) return null;
        reply.returnCode = (((int) buf[0]) & 0xff) |
        reply.returnCode = ((((int) buf[0]) & 0xff) << 24) |
                ((((int) buf[1]) & 0xff) << 8) |
                ((((int) buf[1]) & 0xff) << 16) |
                ((((int) buf[2]) & 0xff) << 16) |
                ((((int) buf[2]) & 0xff) << 8) |
                ((((int) buf[3]) & 0xff) << 24);
                (((int) buf[3]) & 0xff);


        if (reply.len > BUFFER_LENGTH) {
        if (reply.len > BUFFER_LENGTH) {
            Log.e(mTag,"invalid reply length (" + reply.len + ")");
            Log.e(mTag,"invalid reply length (" + reply.len + ")");
@@ -145,15 +146,15 @@ public class ServiceCommand {
        byte[] data = (_data == null) ? new byte[0] : _data.getBytes();
        byte[] data = (_data == null) ? new byte[0] : _data.getBytes();
        int len = data.length;
        int len = data.length;
        // the length of data
        // the length of data
        buf[0] = (byte) (len & 0xff);
        buf[0] = (byte) ((len >> 24) & 0xff);
        buf[1] = (byte) ((len >> 8) & 0xff);
        buf[1] = (byte) ((len >> 16) & 0xff);
        buf[2] = (byte) ((len >> 16) & 0xff);
        buf[2] = (byte) ((len >> 8) & 0xff);
        buf[3] = (byte) ((len >> 24) & 0xff);
        buf[3] = (byte) (len & 0xff);
        // the opcode of the command
        // the opcode of the command
        buf[4] = (byte) (cmd & 0xff);
        buf[4] = (byte) ((cmd >> 24) & 0xff);
        buf[5] = (byte) ((cmd >> 8) & 0xff);
        buf[5] = (byte) ((cmd >> 16) & 0xff);
        buf[6] = (byte) ((cmd >> 16) & 0xff);
        buf[6] = (byte) ((cmd >> 8) & 0xff);
        buf[7] = (byte) ((cmd >> 24) & 0xff);
        buf[7] = (byte) (cmd & 0xff);
        try {
        try {
            mOut.write(buf, 0, 8);
            mOut.write(buf, 0, 8);
            mOut.write(data, 0, len);
            mOut.write(data, 0, len);