summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-02-11 02:22:23 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-02-11 02:22:23 +0000
commitf1473a3ae3584d1cad2498243f1b315a71f7d9db (patch)
treeda7ce4f5ed1a0f8b9f7a57a0882c6ac103da6d05
parent8d7cafed36ef2a7555131a69c6aee4eb696e1a3f (diff)
parent12984691edd5611d5d38ddd876a273b409ae3bb6 (diff)
downloadgatekeeper-f1473a3ae3584d1cad2498243f1b315a71f7d9db.tar.gz
Merge "Appease UB sanitizer on reading gatekeeper error codes."
-rw-r--r--gatekeeper_messages.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/gatekeeper_messages.cpp b/gatekeeper_messages.cpp
index 01f2f8c..3b78664 100644
--- a/gatekeeper_messages.cpp
+++ b/gatekeeper_messages.cpp
@@ -50,6 +50,22 @@ static inline void append_to_buffer(uint8_t **buffer, const SizedBuffer &to_appe
}
}
+static inline gatekeeper_error_t readError(uint32_t code) {
+ switch (code) {
+ case ERROR_NONE:
+ return ERROR_NONE;
+ case ERROR_INVALID:
+ return ERROR_INVALID;
+ case ERROR_RETRY:
+ return ERROR_RETRY;
+ case ERROR_MEMORY_ALLOCATION_FAILED:
+ return ERROR_MEMORY_ALLOCATION_FAILED;
+ case ERROR_UNKNOWN:
+ default:
+ return ERROR_UNKNOWN;
+ }
+}
+
static inline gatekeeper_error_t read_from_buffer(const uint8_t **buffer, const uint8_t *end,
SizedBuffer *target) {
if (target == nullptr) return ERROR_INVALID;
@@ -119,7 +135,7 @@ uint32_t GateKeeperMessage::Serialize(uint8_t *buffer, const uint8_t *end) const
gatekeeper_error_t GateKeeperMessage::Deserialize(const uint8_t *payload, const uint8_t *end) {
if (!fitsBuffer(payload, end, sizeof(serial_header_t))) return ERROR_INVALID;
const serial_header_t *header = reinterpret_cast<const serial_header_t *>(payload);
- error = static_cast<gatekeeper_error_t>(header->error);
+ error = readError(header->error);
user_id = header->user_id;
payload += sizeof(*header);
if (error == ERROR_NONE) {