Skip to content

zcbor_tag_expect failure wrongly increments elem_count #583

@GB6336

Description

@GB6336
bool zcbor_tag_decode(zcbor_state_t *state, uint32_t *result)
{
	ZCBOR_PRINT_FUNC_NAME();
	INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_TAG);

	if (!value_extract(state, result, sizeof(*result), NULL)) {
		ZCBOR_FAIL();
	}
	state->elem_count++;
       // !!! elem_count is not consumend
	return true;
}


bool zcbor_tag_expect(zcbor_state_t *state, uint32_t expected)
{
	ZCBOR_PRINT_FUNC_NAME();
	uint32_t actual;

	if (!zcbor_tag_decode(state, &actual)) {
		ZCBOR_FAIL();
	}
	if (actual != expected) {
                 // !!! BUG restore increments elem_count, which it shouldn't as  elem_count was not consumend
		ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
	}
	return true;
}

zcbor_tag_decode does not consume elem_count so should not be used with ERR_RESTORE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions