Skip to content

Commit b528231

Browse files
widgetiiclaude
andauthored
backup: read board vendor/model from the right cJSON nodes (#182)
do_upgrade() looked up the "vendor" and "model" items of the board info object, then called cJSON_GetStringValue(binfo) on the *object* instead of on the item it had just found. cJSON_GetStringValue() returns NULL for a non-string, so: - the vendor branch was NULL-guarded and silently did nothing; - the model branch was not, and ran strcpy(board_id, NULL). So `ipctool upgrade` segfaults on any board whose detector supplies a "model" key — currently Ruision, Anjoy and Hankvision (src/boards/*.c) — and on every other board it leaves board_id empty, so the "hardware" U-Boot variable set from it further down never gets written. Read the values from c_vendor/c_model, guard both against NULL, and bound the copies with snprintf: the strings come from board detection (sysinfo files, directory names) and were being strcpy/strcat'ed into fixed 1024-byte buffers unchecked. Behaviour is otherwise preserved, including board_id carrying the model alone. Note: `board` is assembled here but never read afterwards. That is pre-existing, so left alone rather than silently changing what the composed string is meant to be. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1bead33 commit b528231

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/backup.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -880,18 +880,16 @@ static int do_upgrade(const char *filename, bool force) {
880880

881881
cJSON *binfo = detect_board();
882882
char board[1024] = {0}, board_id[1024] = {0};
883-
cJSON *c_vendor = cJSON_GetObjectItem(binfo, "vendor");
884-
if (c_vendor) {
885-
char *bstr = cJSON_GetStringValue(binfo);
886-
if (bstr)
887-
strcpy(board, bstr);
888-
}
889-
cJSON *c_model = cJSON_GetObjectItem(binfo, "model");
890-
if (c_model) {
891-
char *bstr = cJSON_GetStringValue(binfo);
892-
strcpy(board_id, bstr);
893-
strcat(board, " ");
894-
strcat(board, bstr);
883+
const char *bstr =
884+
cJSON_GetStringValue(cJSON_GetObjectItem(binfo, "vendor"));
885+
if (bstr)
886+
snprintf(board, sizeof(board), "%s", bstr);
887+
888+
bstr = cJSON_GetStringValue(cJSON_GetObjectItem(binfo, "model"));
889+
if (bstr) {
890+
snprintf(board_id, sizeof(board_id), "%s", bstr);
891+
size_t used = strlen(board);
892+
snprintf(board + used, sizeof(board) - used, " %s", bstr);
895893
}
896894
if (binfo)
897895
cJSON_Delete(binfo);

0 commit comments

Comments
 (0)