Skip to content

Commit

Permalink
tools: imagetool: Remove unnecessary check from toc0_verify_cert_item()
Browse files Browse the repository at this point in the history
C99 introduced the possibility to mark function parameters declared as
arrays with an extra keyword "static":
	void foo(uint8_t digest[static SHA256_DIGEST_LENGTH]);
This requires the respective function argument to be at least as large
as specified. Passing in random pointers (like NULL) then becomes
undefined behaviour, and compilers warn about this.
Newer GCC compilers (starting with GCC 14) will also automatically mark
those parameters as "nonnull", and thus warn if a (redundant) NULL check
is done inside the function:
tools/sunxi_toc0.o tools/sunxi_toc0.c
tools/sunxi_toc0.c: In function 'toc0_verify_cert_item':
tools/sunxi_toc0.c:447:12: warning: 'nonnull' argument 'digest' compared to NULL [-Wnonnull-compare]
  447 |         if (digest && memcmp(&extension->digest, digest, SHA256_DIGEST_LENGTH)) {
      |            ^

Remove the unnecessary NULL check from toc0_verify_cert_item(), to avoid
the warning.

Signed-off-by: Seung-Woo Kim <[email protected]>
Reviewed-by: Andre Przywara <[email protected]>
[Andre: extend commit message]
Signed-off-by: Andre Przywara <[email protected]>
  • Loading branch information
devusr-sw-kim authored and Andre-ARM committed Aug 5, 2024
1 parent 6becf9b commit 59fff91
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/sunxi_toc0.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static int toc0_verify_cert_item(const uint8_t *buf, uint32_t len, RSA *fw_key,

/* If a digest was provided, compare it to the embedded digest. */
extension = &totalSequence->mainSequence.explicit3.extension;
if (digest && memcmp(&extension->digest, digest, SHA256_DIGEST_LENGTH)) {
if (memcmp(&extension->digest, digest, SHA256_DIGEST_LENGTH)) {
pr_err("Wrong firmware digest in certificate\n");
goto err;
}
Expand Down

0 comments on commit 59fff91

Please sign in to comment.