Skip to content

Commit 8296494

Browse files
Yusong Gaotorvalds
authored andcommitted
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: e5a2e3c ("scripts/sign-file.c: Add support for signing with a raw signature") Signed-off-by: Yusong Gao <[email protected]> Reviewed-by: Juerg Haefliger <[email protected]> Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ # v5 Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5bd7ef5 commit 8296494

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/sign-file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ int main(int argc, char **argv)
322322
CMS_NOSMIMECAP | use_keyid |
323323
use_signed_attrs),
324324
"CMS_add1_signer");
325-
ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0,
325+
ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1,
326326
"CMS_final");
327327

328328
#else
@@ -341,10 +341,10 @@ int main(int argc, char **argv)
341341
b = BIO_new_file(sig_file_name, "wb");
342342
ERR(!b, "%s", sig_file_name);
343343
#ifndef USE_PKCS7
344-
ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0,
344+
ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) != 1,
345345
"%s", sig_file_name);
346346
#else
347-
ERR(i2d_PKCS7_bio(b, pkcs7) < 0,
347+
ERR(i2d_PKCS7_bio(b, pkcs7) != 1,
348348
"%s", sig_file_name);
349349
#endif
350350
BIO_free(b);
@@ -374,9 +374,9 @@ int main(int argc, char **argv)
374374

375375
if (!raw_sig) {
376376
#ifndef USE_PKCS7
377-
ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) < 0, "%s", dest_name);
377+
ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) != 1, "%s", dest_name);
378378
#else
379-
ERR(i2d_PKCS7_bio(bd, pkcs7) < 0, "%s", dest_name);
379+
ERR(i2d_PKCS7_bio(bd, pkcs7) != 1, "%s", dest_name);
380380
#endif
381381
} else {
382382
BIO *b;
@@ -396,7 +396,7 @@ int main(int argc, char **argv)
396396
ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name);
397397
ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
398398

399-
ERR(BIO_free(bd) < 0, "%s", dest_name);
399+
ERR(BIO_free(bd) != 1, "%s", dest_name);
400400

401401
/* Finally, if we're signing in place, replace the original. */
402402
if (replace_orig)

0 commit comments

Comments
 (0)