diff options
author | noname <[email protected]> | 2025-03-02 14:49:56 +1100 |
---|---|---|
committer | noname <[email protected]> | 2025-03-03 22:06:48 +1100 |
commit | 57d00e5eb47576e4c6711547aa1611a2f542c8d9 (patch) | |
tree | 19730c9599ac441fd21b21ef6315f51cfaf4dc1c /lib/sway | |
parent | 287959a2fbe4149c4bfda23fc8bc188e5ad5deff (diff) |
null terminate before converting to string
Diffstat (limited to 'lib/sway')
-rw-r--r-- | lib/sway/ipc.vala | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/sway/ipc.vala b/lib/sway/ipc.vala index 5818883..719a2d0 100644 --- a/lib/sway/ipc.vala +++ b/lib/sway/ipc.vala @@ -28,7 +28,7 @@ namespace AstalSway { EVENT_INPUT = 0x80000015, } - private struct IpcReply { + private struct IpcReponse { public PayloadType type; public string payload; } @@ -73,32 +73,39 @@ namespace AstalSway { stream.write(message.data); } - internal IpcReply? receive(InputStream stream) { + internal IpcReponse? receive(InputStream stream) { var header = stream.read_bytes(14); - uint8 *data = header.get_data(); + uint8 data[14] = header.get_data(); if (data == null) { return null; } uint32 pl_length = *(uint32 *)&data[IPC_MAGIC.length]; PayloadType pl_type = *(uint32 *)&data[IPC_MAGIC.length+4]; - var result = stream.read_bytes(pl_length); - return {pl_type, (string)result.get_data()}; + var payload = stream.read_bytes(pl_length); + + var result = payload.get_data(); + result += '\0'; + + return {pl_type, (string)result}; } - internal async IpcReply? receive_async(InputStream stream) { + internal async IpcReponse? receive_async(InputStream stream) { var header = yield stream.read_bytes_async(14, Priority.DEFAULT, null); - uint8 *data = header.get_data(); + uint8 data[14] = header.get_data(); if (data == null) { return null; } uint32 pl_length = *(uint32 *)&data[IPC_MAGIC.length]; PayloadType pl_type = *(uint32 *)&data[IPC_MAGIC.length+4]; - var result = yield stream.read_bytes_async(pl_length, Priority.DEFAULT, null); + var payload = yield stream.read_bytes_async(pl_length, Priority.DEFAULT, null); - return {pl_type, (string)result.get_data()}; + var result = payload.get_data(); + result += '\0'; + + return {pl_type, (string)result}; } public string message(PayloadType type, string payload) { |