Commit 82964944 authored by Yusong Gao's avatar Yusong Gao Committed by Linus Torvalds

sign-file: Fix incorrect return values check

There are some wrong return values check in sign-file when call OpenSSL
API. The ERR() check cond is wrong because of the program only check the
return value is < 0 which ignored the return val is 0. For example:
1. CMS_final() return 1 for success or 0 for failure.
2. i2d_CMS_bio_stream() returns 1 for success or 0 for failure.
3. i2d_TYPEbio() return 1 for success and 0 for failure.
4. BIO_free() return 1 for success and 0 for failure.

Link: https://www.openssl.org/docs/manmaster/man3/
Fixes: e5a2e3c8 ("scripts/sign-file.c: Add support for signing with a raw signature")
Signed-off-by: default avatarYusong Gao <a869920004@gmail.com>
Reviewed-by: default avatarJuerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20231213024405.624692-1-a869920004@gmail.com/ # v5
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5bd7ef53
...@@ -322,7 +322,7 @@ int main(int argc, char **argv) ...@@ -322,7 +322,7 @@ int main(int argc, char **argv)
CMS_NOSMIMECAP | use_keyid | CMS_NOSMIMECAP | use_keyid |
use_signed_attrs), use_signed_attrs),
"CMS_add1_signer"); "CMS_add1_signer");
ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0, ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1,
"CMS_final"); "CMS_final");
#else #else
...@@ -341,10 +341,10 @@ int main(int argc, char **argv) ...@@ -341,10 +341,10 @@ int main(int argc, char **argv)
b = BIO_new_file(sig_file_name, "wb"); b = BIO_new_file(sig_file_name, "wb");
ERR(!b, "%s", sig_file_name); ERR(!b, "%s", sig_file_name);
#ifndef USE_PKCS7 #ifndef USE_PKCS7
ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0, ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) != 1,
"%s", sig_file_name); "%s", sig_file_name);
#else #else
ERR(i2d_PKCS7_bio(b, pkcs7) < 0, ERR(i2d_PKCS7_bio(b, pkcs7) != 1,
"%s", sig_file_name); "%s", sig_file_name);
#endif #endif
BIO_free(b); BIO_free(b);
...@@ -374,9 +374,9 @@ int main(int argc, char **argv) ...@@ -374,9 +374,9 @@ int main(int argc, char **argv)
if (!raw_sig) { if (!raw_sig) {
#ifndef USE_PKCS7 #ifndef USE_PKCS7
ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) < 0, "%s", dest_name); ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) != 1, "%s", dest_name);
#else #else
ERR(i2d_PKCS7_bio(bd, pkcs7) < 0, "%s", dest_name); ERR(i2d_PKCS7_bio(bd, pkcs7) != 1, "%s", dest_name);
#endif #endif
} else { } else {
BIO *b; BIO *b;
...@@ -396,7 +396,7 @@ int main(int argc, char **argv) ...@@ -396,7 +396,7 @@ int main(int argc, char **argv)
ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name); ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name);
ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name); ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
ERR(BIO_free(bd) < 0, "%s", dest_name); ERR(BIO_free(bd) != 1, "%s", dest_name);
/* Finally, if we're signing in place, replace the original. */ /* Finally, if we're signing in place, replace the original. */
if (replace_orig) if (replace_orig)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment