Skip to contentSkip to conversation

sign-file: Fix incorrect return values check

PATCH RESEND Superseded Yusong Gao 2 participants 3 messages Nov 20, 2023 – Nov 21, 2023

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yusong Gao

author
#0 lore raw

PATCH RESEND v2 1/1 sign-file: Fix incorrect return values check

There are some wrong return values check in sign-file when call OpenSSL API. For example the CMS_final() return 1 for success or 0 for failure. The ERR() check cond is wrong because of the program only check the return value is < 0 instead of <= 0.

Link:
https://www.openssl.org/docs/manmaster/man3/CMS_final.html
https://www.openssl.org/docs/manmaster/man3/i2d_CMS_bio_stream.html
https://www.openssl.org/docs/manmaster/man3/i2d_PKCS7_bio.html
https://www.openssl.org/docs/manmaster/man3/BIO_free.html

---
 scripts/sign-file.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
scripts/sign-file.c +6 -6
index 598ef5465f82..dcebbcd6bebd 100644
@@ -322,7 +322,7 @@ int main(int argc, char **argv)
 				     CMS_NOSMIMECAP | use_keyid |
 				     use_signed_attrs),
 		    "CMS_add1_signer");
-		ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0,
+		ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) <= 0,
 		    "CMS_final");
 
 #else
@@ -341,10 +341,10 @@ int main(int argc, char **argv)
 			b = BIO_new_file(sig_file_name, "wb");
 			ERR(!b, "%s", sig_file_name);
 #ifndef USE_PKCS7
-			ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0,
+			ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) <= 0,
 			    "%s", sig_file_name);
 #else
-			ERR(i2d_PKCS7_bio(b, pkcs7) < 0,
+			ERR(i2d_PKCS7_bio(b, pkcs7) <= 0,
 			    "%s", sig_file_name);
 #endif
 			BIO_free(b);
@@ -374,9 +374,9 @@ int main(int argc, char **argv)
 
 	if (!raw_sig) {
 #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) <= 0, "%s", dest_name);
 #else
-		ERR(i2d_PKCS7_bio(bd, pkcs7) < 0, "%s", dest_name);
+		ERR(i2d_PKCS7_bio(bd, pkcs7) <= 0, "%s", dest_name);
 #endif
 	} else {
 		BIO *b;
@@ -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, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
 
-	ERR(BIO_free(bd) < 0, "%s", dest_name);
+	ERR(BIO_free(bd) <= 0, "%s", dest_name);
 
 	/* Finally, if we're signing in place, replace the original. */
 	if (replace_orig)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 2 lines · Yusong Gao

There are some wrong return values check in sign-file when call OpenSSL API. For example the CMS_final() return 1 for success or 0 for failure.

Why not make it a closed sentence and list the functions that need to be changed?

Quoted 3 lines

The ERR() check cond is wrong because of the program only check the return value is < 0 instead of <= 0.

Lacking Fixes tag(s). See: ttps://www.kernel.org/doc/html/latest/process/submitting-patches.html

Quoted 5 lines

Link:
https://www.openssl.org/docs/manmaster/man3/CMS_final.html
https://www.openssl.org/docs/manmaster/man3/i2d_CMS_bio_stream.html
https://www.openssl.org/docs/manmaster/man3/i2d_PKCS7_bio.html
https://www.openssl.org/docs/manmaster/man3/BIO_free.html

Replace with

BR, Jarkko

author
#2 lore raw

PATCH RESEND v2 1/1 sign-file: Fix incorrect return values check

In reply to Yusong Gao
Quoted 24 lines · Jarkko Sakkinen
Quoted 4 lines · Yusong Gao

There are some wrong return values check in sign-file when call OpenSSL
API. For example the CMS_final() return 1 for success or 0 for failure.

Why not make it a closed sentence and list the functions that need to be
changed?

Quoted 3 lines

The ERR() check cond is wrong because of the program only check the return value is < 0 instead of <= 0.

Lacking Fixes tag(s). See:
ttps://www.kernel.org/doc/html/latest/process/submitting-patches.html

Quoted 5 lines

Link:
https://www.openssl.org/docs/manmaster/man3/CMS_final.html
https://www.openssl.org/docs/manmaster/man3/i2d_CMS_bio_stream.html
https://www.openssl.org/docs/manmaster/man3/i2d_PKCS7_bio.html
https://www.openssl.org/docs/manmaster/man3/BIO_free.html

Quoted 5 lines

Replace with

BR, Jarkko

Thanks a lot for you comments, I will fix that.

BR, Yusong Gao