Skip to content

Comments

Make ERR_str_reasons in err.c consistent again with err.h#17056

Closed
DDvO wants to merge 2 commits intoopenssl:masterfrom
siemens:fix_printing_generic_err_reasons
Closed

Make ERR_str_reasons in err.c consistent again with err.h#17056
DDvO wants to merge 2 commits intoopenssl:masterfrom
siemens:fix_printing_generic_err_reasons

Conversation

@DDvO
Copy link
Contributor

@DDvO DDvO commented Nov 17, 2021

For various generic reason codes, their string conversion goes wrong, e.g.:

    # 80B26552927F0000:error:1E8C0102:HTTP routines:foo:reason(786690):test/http_test.c:424:
    # 80B26552927F0000:error:1E880106:HTTP routines:foo:reason(524550):test/http_test.c:424:

I found that this is because some entries defined in include/openssl/err.h{,in} are missing from ERR_str_reasons in crypto/err/err.c
and that their order easily goes wrong there because they need to be sorted by their numerical reason code including any flags such as ERR_RFLAG_COMMON.

After fixing the entries, the above becomes:

    # 8032C819DE7F0000:error:1E8C0102:HTTP routines:foo:passed a null parameter:test/http_test.c:424:
    # 8032C819DE7F0000:error:1E880106:HTTP routines:foo:passed an invalid argument:test/http_test.c:424:

@DDvO DDvO added branch: master Applies to master branch approval: otc review pending triaged: bug The issue/pr is/fixes a bug branch: 3.0 Applies to openssl-3.0 branch labels Nov 17, 2021
@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: otc review pending labels Nov 17, 2021
@levitte
Copy link
Member

levitte commented Nov 18, 2021

I strongly dislike this solution. It doesn't address the actual problem, that flags become part of the index where they shouldn't. That makes it difficult re maintenance, as error codes in the header file become sorted differently than those in the source file, among other things.

The real issue is that err_string_data_hash() and err_string_data_hash() are using non-index bits for indexing...

@DDvO
Copy link
Contributor Author

DDvO commented Nov 18, 2021

flags become part of the index where they shouldn't.

Right - I'll provide a fixup that rectifies this, which will make ERR_str_reasons[] better maintainable.

@DDvO DDvO force-pushed the fix_printing_generic_err_reasons branch from 9fe3b77 to 1bc0b73 Compare November 18, 2021 18:08
@DDvO
Copy link
Contributor Author

DDvO commented Nov 18, 2021

I'll provide a fixup that rectifies this, which will make ERR_str_reasons[] better maintainable.

Done.

After some pitfalls, seems to be fine now.

@paulidale paulidale requested a review from t8m November 18, 2021 23:39
@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@levitte
Copy link
Member

levitte commented Nov 19, 2021

Actually, all that should be needed is to add the missing strings in ERR_str_reasons. Numeric order should not matter, since they are indexed by an lhash (int_error_hash)!

Now, I did try printing the two codes, and here's what I got:

$ ./util/wrap.pl apps/openssl errstr 1E8C0102
error:1E8C0102:HTTP routines::passed a null parameter
$ ./util/wrap.pl apps/openssl errstr 1E880106
error:1E880106:HTTP routines::reason(524550)

And indeed, there is no text string for ERR_R_PASSED_INVALID_ARGUMENT in crypto/err/err.c.

Why you got no text reason for 1E8C0102, I cannot tell.

@levitte
Copy link
Member

levitte commented Nov 19, 2021

Regarding the flags, I'm backing off what I said earlier. Considering that we're using the same reason macros everywhere, it really doesn't matter if we peal off the flags or not, as they should be the same anyway... that was a red herring.

@levitte
Copy link
Member

levitte commented Nov 19, 2021

I just submitted #17069, which only adds the missing reason string. To be noted that it's missing all the way back to 1.1.1.

The rest of this PR should probably be discussed a little further, because as noted in the modified test, it changes a previous behavior, something I didn't think of initially. That's probably not well suited for 3.0 or 1.1.1.

Copy link
Member

@levitte levitte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you lowercasing the library names? They are uppercase to match the API prefixes.
(and yes, one might argue that "STORE lib" should be "OSSL_STORE lib")

@DDvO
Copy link
Contributor Author

DDvO commented Nov 19, 2021

Yes, the comment on the indexing/order was misleading; it works regardless.
I've pushed a fixup that no more peels off the flags from the list entries, which simplifies things again.
Anyway I made sure the entries in err.c are in the same order as those in err.h.in, which should help maintenance.

@DDvO
Copy link
Contributor Author

DDvO commented Nov 19, 2021

Indeed the problem was that some entries were missing - but not only ERR_R_PASSED_INVALID_ARGUMENT,
also ERR_R_CRYPTO_LIB and ERR_R_OSSL_DECODER_LIB, which I added.

test_err* should better check for completeness of the string outputs.

@DDvO
Copy link
Contributor Author

DDvO commented Nov 19, 2021

I added a commit that exempts flags from the fallback decimal reason code printing,
such that, e.g., reason(524550) becomes reason(262), which I consider much more readable/helpful.

@DDvO
Copy link
Contributor Author

DDvO commented Nov 19, 2021

I also added a tweak to 02-test_errstr.t
such that error codes are printed in hex (rather than decimal) format,
which also improves readability (of the verbose output).

@DDvO DDvO requested review from levitte and paulidale November 19, 2021 10:27
@DDvO DDvO force-pushed the fix_printing_generic_err_reasons branch from 4dbecc0 to 58a3525 Compare November 19, 2021 10:36
@DDvO DDvO force-pushed the fix_printing_generic_err_reasons branch from 58a3525 to 5116e5f Compare November 19, 2021 10:38
@DDvO DDvO added approval: otc review pending and removed approval: done This pull request has the required number of approvals labels Nov 19, 2021
@DDvO DDvO requested a review from levitte November 19, 2021 10:41
DDvO added 2 commits November 19, 2021 11:57
Fixes printing generic reason strings, e.g., 'reason(524550)' vs. 'passed an invalid argument'
@DDvO
Copy link
Contributor Author

DDvO commented Nov 19, 2021

Why you got no text reason for 1E8C0102, I cannot tell.

I cannot reproduce this part of the issue (regarding passed a null parameter) myself.
Anyway, for the records, this is the output of all reasons defined in err.h.in before:

801BB4FE0C7F0000:error:01880002:bignum routines:test_reason_strings:system lib:test/errtest.c:339:
801BB4FE0C7F0000:error:01880003:bignum routines:test_reason_strings:BN lib:test/errtest.c:340:
801BB4FE0C7F0000:error:01880004:bignum routines:test_reason_strings:RSA lib:test/errtest.c:341:
801BB4FE0C7F0000:error:01880005:bignum routines:test_reason_strings:DH lib:test/errtest.c:342:
801BB4FE0C7F0000:error:01880006:bignum routines:test_reason_strings:EVP lib:test/errtest.c:343:
801BB4FE0C7F0000:error:01880007:bignum routines:test_reason_strings:BUF lib:test/errtest.c:344:
801BB4FE0C7F0000:error:01880008:bignum routines:test_reason_strings:OBJ lib:test/errtest.c:345:
801BB4FE0C7F0000:error:01880009:bignum routines:test_reason_strings:PEM lib:test/errtest.c:346:
801BB4FE0C7F0000:error:0188000A:bignum routines:test_reason_strings:DSA lib:test/errtest.c:347:
801BB4FE0C7F0000:error:0188000B:bignum routines:test_reason_strings:X509 lib:test/errtest.c:348:
801BB4FE0C7F0000:error:0188000D:bignum routines:test_reason_strings:ASN1 lib:test/errtest.c:350:
801BB4FE0C7F0000:error:0188000F:bignum routines:test_reason_strings:reason(524303):test/errtest.c:351:
801BB4FE0C7F0000:error:01880010:bignum routines:test_reason_strings:EC lib:test/errtest.c:352:
801BB4FE0C7F0000:error:01880020:bignum routines:test_reason_strings:BIO lib:test/errtest.c:353:
801BB4FE0C7F0000:error:01880021:bignum routines:test_reason_strings:PKCS7 lib:test/errtest.c:354:
801BB4FE0C7F0000:error:01880022:bignum routines:test_reason_strings:X509V3 lib:test/errtest.c:355:
801BB4FE0C7F0000:error:01880026:bignum routines:test_reason_strings:ENGINE lib:test/errtest.c:356:
801BB4FE0C7F0000:error:01880028:bignum routines:test_reason_strings:UI lib:test/errtest.c:357:
801BB4FE0C7F0000:error:0188002A:bignum routines:test_reason_strings:ECDSA lib:test/errtest.c:358:
801BB4FE0C7F0000:error:0188002C:bignum routines:test_reason_strings:STORE lib:test/errtest.c:359:
801BB4FE0C7F0000:error:0188003C:bignum routines:test_reason_strings:reason(524348):test/errtest.c:361:
801BB4FE0C7F0000:error:018C0000:bignum routines:test_reason_strings:fatal:test/errtest.c:362:
801BB4FE0C7F0000:error:018C0100:bignum routines:test_reason_strings:malloc failure:test/errtest.c:363:
801BB4FE0C7F0000:error:018C0101:bignum routines:test_reason_strings:called a function you should not call:test/errtest.c:364:
801BB4FE0C7F0000:error:018C0102:bignum routines:test_reason_strings:passed a null parameter:test/errtest.c:365:
801BB4FE0C7F0000:error:018C0103:bignum routines:test_reason_strings:internal error:test/errtest.c:366:
801BB4FE0C7F0000:error:018C0104:bignum routines:test_reason_strings:called a function that was disabled at compile-time:test/errtest.c:367:
801BB4FE0C7F0000:error:018C0105:bignum routines:test_reason_strings:init fail:test/errtest.c:368:
801BB4FE0C7F0000:error:01880106:bignum routines:test_reason_strings:reason(524550):test/errtest.c:369:
801BB4FE0C7F0000:error:018C0107:bignum routines:test_reason_strings:operation fail:test/errtest.c:371:
801BB4FE0C7F0000:error:018C0108:bignum routines:test_reason_strings:invalid provider functions:test/errtest.c:372:
801BB4FE0C7F0000:error:01880109:bignum routines:test_reason_strings:interrupted or cancelled:test/errtest.c:373:
801BB4FE0C7F0000:error:0188010A:bignum routines:test_reason_strings:nested asn1 error:test/errtest.c:374:
801BB4FE0C7F0000:error:0188010B:bignum routines:test_reason_strings:missing asn1 eos:test/errtest.c:375:
801BB4FE0C7F0000:error:0188010C:bignum routines:test_reason_strings:unsupported:test/errtest.c:376:
801BB4FE0C7F0000:error:0188010D:bignum routines:test_reason_strings:fetch failed:test/errtest.c:377:
801BB4FE0C7F0000:error:0188010E:bignum routines:test_reason_strings:invalid property definition:test/errtest.c:378:
801BB4FE0C7F0000:error:018C010F:bignum routines:test_reason_strings:unable to get read lock:test/errtest.c:379:
801BB4FE0C7F0000:error:018C0110:bignum routines:test_reason_strings:unable to get write lock:test/errtest.c:380:

and after the improvements by this PR:

808B11CDB37F0000:error:01880002:bignum routines:test_reason_strings:system lib:test/errtest.c:339:
808B11CDB37F0000:error:01880003:bignum routines:test_reason_strings:BN lib:test/errtest.c:340:
808B11CDB37F0000:error:01880004:bignum routines:test_reason_strings:RSA lib:test/errtest.c:341:
808B11CDB37F0000:error:01880005:bignum routines:test_reason_strings:DH lib:test/errtest.c:342:
808B11CDB37F0000:error:01880006:bignum routines:test_reason_strings:EVP lib:test/errtest.c:343:
808B11CDB37F0000:error:01880007:bignum routines:test_reason_strings:BUF lib:test/errtest.c:344:
808B11CDB37F0000:error:01880008:bignum routines:test_reason_strings:OBJ lib:test/errtest.c:345:
808B11CDB37F0000:error:01880009:bignum routines:test_reason_strings:PEM lib:test/errtest.c:346:
808B11CDB37F0000:error:0188000A:bignum routines:test_reason_strings:DSA lib:test/errtest.c:347:
808B11CDB37F0000:error:0188000B:bignum routines:test_reason_strings:X509 lib:test/errtest.c:348:
808B11CDB37F0000:error:0188000D:bignum routines:test_reason_strings:ASN1 lib:test/errtest.c:350:
808B11CDB37F0000:error:0188000F:bignum routines:test_reason_strings:reason(15):test/errtest.c:351:
808B11CDB37F0000:error:01880010:bignum routines:test_reason_strings:EC lib:test/errtest.c:352:
808B11CDB37F0000:error:01880020:bignum routines:test_reason_strings:BIO lib:test/errtest.c:353:
808B11CDB37F0000:error:01880021:bignum routines:test_reason_strings:PKCS7 lib:test/errtest.c:354:
808B11CDB37F0000:error:01880022:bignum routines:test_reason_strings:X509V3 lib:test/errtest.c:355:
808B11CDB37F0000:error:01880026:bignum routines:test_reason_strings:ENGINE lib:test/errtest.c:356:
808B11CDB37F0000:error:01880028:bignum routines:test_reason_strings:UI lib:test/errtest.c:357:
808B11CDB37F0000:error:0188002A:bignum routines:test_reason_strings:ECDSA lib:test/errtest.c:358:
808B11CDB37F0000:error:0188002C:bignum routines:test_reason_strings:STORE lib:test/errtest.c:359:
808B11CDB37F0000:error:0188003C:bignum routines:test_reason_strings:reason(60):test/errtest.c:361:
808B11CDB37F0000:error:018C0000:bignum routines:test_reason_strings:fatal:test/errtest.c:362:
808B11CDB37F0000:error:018C0100:bignum routines:test_reason_strings:malloc failure:test/errtest.c:363:
808B11CDB37F0000:error:018C0101:bignum routines:test_reason_strings:called a function you should not call:test/errtest.c:364:
808B11CDB37F0000:error:018C0102:bignum routines:test_reason_strings:passed a null parameter:test/errtest.c:365:
808B11CDB37F0000:error:018C0103:bignum routines:test_reason_strings:internal error:test/errtest.c:366:
808B11CDB37F0000:error:018C0104:bignum routines:test_reason_strings:called a function that was disabled at compile-time:test/errtest.c:367:
808B11CDB37F0000:error:018C0105:bignum routines:test_reason_strings:init fail:test/errtest.c:368:
808B11CDB37F0000:error:01880106:bignum routines:test_reason_strings:reason(262):test/errtest.c:369:
808B11CDB37F0000:error:018C0107:bignum routines:test_reason_strings:operation fail:test/errtest.c:371:
808B11CDB37F0000:error:018C0108:bignum routines:test_reason_strings:invalid provider functions:test/errtest.c:372:
808B11CDB37F0000:error:01880109:bignum routines:test_reason_strings:interrupted or cancelled:test/errtest.c:373:
808B11CDB37F0000:error:0188010A:bignum routines:test_reason_strings:nested asn1 error:test/errtest.c:374:
808B11CDB37F0000:error:0188010B:bignum routines:test_reason_strings:missing asn1 eos:test/errtest.c:375:
808B11CDB37F0000:error:0188010C:bignum routines:test_reason_strings:unsupported:test/errtest.c:376:
808B11CDB37F0000:error:0188010D:bignum routines:test_reason_strings:fetch failed:test/errtest.c:377:
808B11CDB37F0000:error:0188010E:bignum routines:test_reason_strings:invalid property definition:test/errtest.c:378:
808B11CDB37F0000:error:018C010F:bignum routines:test_reason_strings:unable to get read lock:test/errtest.c:379:
808B11CDB37F0000:error:018C0110:bignum routines:test_reason_strings:unable to get write lock:test/errtest.c:380:

@DDvO DDvO requested a review from levitte November 19, 2021 11:42
@levitte
Copy link
Member

levitte commented Nov 19, 2021

Thanks for your patience

@t8m t8m added approval: done This pull request has the required number of approvals and removed approval: otc review pending labels Nov 19, 2021
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Nov 20, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Nov 22, 2021
Fixes printing generic reason strings, e.g., 'reason(524550)' vs. 'passed an invalid argument'

Reviewed-by: Richard Levitte <[email protected]>
(Merged from #17056)
openssl-machine pushed a commit that referenced this pull request Nov 22, 2021
openssl-machine pushed a commit that referenced this pull request Nov 22, 2021
Fixes printing generic reason strings, e.g., 'reason(524550)' vs. 'passed an invalid argument'

Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #17056)
openssl-machine pushed a commit that referenced this pull request Nov 22, 2021
Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #17056)
@DDvO
Copy link
Contributor Author

DDvO commented Nov 22, 2021

Merged to master and 3.0 - thanks @paulidale , @t8m and @levitte.
For 1.1.1 see #17069.

@DDvO DDvO closed this Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants