Merge branch 'feat/ota-branch-switch' into merge/ota-branch-into-observer-firmware-dev

This commit is contained in:
agessaman
2026-10-03 15:52:39 -07:00
2 changed files with 7 additions and 1 deletions
+3 -1
View File
@@ -117,11 +117,13 @@ static inline bool ota_compat_parse(const char* s, OtaCompat* out) {
}
// Find the tag in an image chunk; returns the NUL-terminated value text, or nullptr when
// the chunk holds no complete tag.
// the chunk holds no complete tag. Skips the bare OTA_COMPAT_TAG search literal, which
// every image also contains.
static inline const char* ota_compat_find(const uint8_t* buf, size_t len) {
const size_t tag_len = sizeof(OTA_COMPAT_TAG) - 1;
for (size_t i = 0; i + tag_len < len; i++) {
if (memcmp(buf + i, OTA_COMPAT_TAG, tag_len) != 0) continue;
if (buf[i + tag_len] < '0' || buf[i + tag_len] > '9') continue;
if (memchr(buf + i + tag_len, 0, len - i - tag_len)) return (const char*)buf + i + tag_len;
}
return nullptr;
@@ -62,6 +62,10 @@ TEST(OtaCompat, FindsCompleteTagOnly) {
EXPECT_STREQ(v, "2+eth");
const char cut[] = "junk ota-compat:2+e"; // value runs past the chunk end
EXPECT_EQ(ota_compat_find((const uint8_t*)cut, sizeof(cut) - 1), nullptr);
const char literal_first[] = "ota-compat:\0code\0ota-compat:1\0"; // search literal precedes the tag
v = ota_compat_find((const uint8_t*)literal_first, sizeof(literal_first));
ASSERT_NE(v, nullptr);
EXPECT_STREQ(v, "1");
const char none[] = "ota-compat";
EXPECT_EQ(ota_compat_find((const uint8_t*)none, sizeof(none)), nullptr);
}