Skip to content

Commit

Permalink
[open-dice] Add a local strlen implementation for open-dice
Browse files Browse the repository at this point in the history
It requires strlen() in the cbor_writer library which is not included in
the OT development environment.

Bug: 356532759
Signed-off-by: Tommy Chiu <tommychiu@google.com>
  • Loading branch information
tommychiu-github authored and timothytrippel committed Oct 23, 2024
1 parent a4a0908 commit 768baf2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions third_party/open-dice/Add-a-local-strlen-implementation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 1a2ead40e2e15ca058882ad86f4ac32e5c5b6177 Mon Sep 17 00:00:00 2001
From: Tommy Chiu <tommychiu@google.com>
Date: Thu, 17 Oct 2024 13:23:43 +0800
Subject: [PATCH] Add a local strlen implementation

Not all developing environments have access to strlen.
---
src/cbor_writer.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/cbor_writer.c b/src/cbor_writer.c
index 6c70129..c473543 100644
--- a/src/cbor_writer.c
+++ b/src/cbor_writer.c
@@ -30,6 +30,12 @@ enum CborType {
CBOR_TYPE_SIMPLE = 7,
};

+static unsigned long _strlen(const char* in) {
+ unsigned long ret;
+ for (ret = 0; *in++; ret++);
+ return ret;
+}
+
static bool CborWriteWouldOverflowCursor(size_t size, struct CborOut* out) {
return size > SIZE_MAX - out->cursor;
}
@@ -127,7 +133,7 @@ uint8_t* CborAllocBstr(size_t data_size, struct CborOut* out) {
}

void CborWriteTstr(const char* str, struct CborOut* out) {
- CborWriteStr(CBOR_TYPE_TSTR, strlen(str), str, out);
+ CborWriteStr(CBOR_TYPE_TSTR, _strlen(str), str, out);
}

char* CborAllocTstr(size_t size, struct CborOut* out) {
--
2.47.0.rc1.288.g06298d1525-goog

4 changes: 4 additions & 0 deletions third_party/open-dice/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def open_dice_repos(local = None):
strip_prefix = "open-dice-cf3f4cc7a3506a33ee3a437544ef6f40056b3563",
urls = ["https://github.com/google/open-dice/archive/cf3f4cc7a3506a33ee3a437544ef6f40056b3563.zip"],
sha256 = "d7ce830111451afe2a255cac3b750f82e50efe2aaf6bac0b076881c964cfe78d",
patches = [
Label("//third_party/open-dice:Add-a-local-strlen-implementation.patch"),
],
patch_args = ["-p1"],
)

0 comments on commit 768baf2

Please sign in to comment.