ERR: Adapt ERR_raise() calls after making CRYPTO_malloc() and friends report ERR_R_MALLOC_FAILURE#19072
ERR: Adapt ERR_raise() calls after making CRYPTO_malloc() and friends report ERR_R_MALLOC_FAILURE#19072DDvO wants to merge 2 commits intoopenssl:masterfrom
ERR_raise() calls after making CRYPTO_malloc() and friends report ERR_R_MALLOC_FAILURE#19072Conversation
levitte
left a comment
There was a problem hiding this comment.
... etc etc etc. Do you see the pattern well enough?
| b = BUF_MEM_new(); | ||
| if (b == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_BUF_LIB, since that's the function that was called
|
|
||
| if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_BUF_LIB, since that's the function that was called
|
|
||
| if (!BUF_MEM_grow_clean(b, len + chunk)) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_BUF_LIB, since that's the function that was called
| n = ASN1_item_i2d(x, &b, it); | ||
| if (b == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_ASN1_LIB, since that's the function that was called
|
|
||
| if (ASN1_STRING_set(ret, NULL, len) == 0) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_ASN1_LIB, since that's the function that was called
| dest = ASN1_STRING_type_new(str_type); | ||
| if (dest == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_ASN1_LIB, since that's the function that was called
|
|
||
| if (ctx == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_EVP_LIB, since that's the function that was called
|
|
||
| if (ctx == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_EVP_LIB, since that's the function that was called
| bf = BIO_new(BIO_f_buffer()); | ||
| if (bf == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_BIO_LIB, since that's the function that was called
|
|
||
| if ((b64 = BIO_new(BIO_f_base64())) == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Should be ERR_R_BIO_LIB, since that's the function that was called
Sure, but replacing If we go for this extra preciseness, this will require manually checking all 1200+ changes and adapting them where needed. And the gain would be IMO minimal. Are you sure to require this effort for little benefit? |
|
Hmm, the *err() calls were supposed to be replaced with ERR_raise already. Could you perhaps do it too? |
Ok, adapted remnant Looks like not much can be done in this regard on |
Apparently, I wasn't clear enough there, but that was exactly a point I tried to raise. Fact is, it was mentioned already a few times that
I'm well aware that this is a big job. This is a reason I continually disagreed with certain statements back in #14833. |
Good. Apparently, we missed some spots when converting *err() calls to ERR_raise...
There were more reasons than that, it turned out to be technically difficult. I don't remember all the details, unfortunately. |
|
SSLfatal and RLAYERfatal and the err calls in engines of course need to be kept. |
Fine. |
IMO not worth it. |
I'm aware of that, and so I consider getting rid of the potentially pretty misleading In particular, I feel
If the change you requested is still of sufficient value to you, I suggest getting an OTC decision (in particular regarding the reviewing effort) and then executing the change yourself in a follow-up PR. |
f1a55cd to
df57553
Compare
|
Rebased this PR on the meanwhile merge parent PR #14833. |
|
@levitte, a few more thoughts on the partial inaccuracy of simply using
|
| c = OPENSSL_clear_realloc(a->data, a->length, w + 1); | ||
| if (c == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
Raised errors following a memory allocation call should just be removed IMO. The memory allocation call will report file and line number. Subsequently reporting that it was LIB_ASN1 isn't helpful. It's obviously ASN1 from the file name.
In this instance, we'd get an error on lines 162 and 164. Polluting the error stack.
There was a problem hiding this comment.
Yeah, for the cases where there is an OPENSSL_*alloc() call immediately before the ERR_raise(ERR_LIB_FOO, ERR_R_CRYPTO_LIB) call with just the NULL check in between, I agree it will be better to drop the ERR_raise() call.
Though in the rather rare event of an malloc error it would not hurt to have the essentially duplicate error report (in particular since the size of the error queue should not be an issue here),
it would look a little weird and the about 400 now superfluous ERR_raise() calls just clog the source code and increase the binary footprint.
| b = BUF_MEM_new(); | ||
| if (b == NULL) { | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); | ||
| ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
There was a problem hiding this comment.
This error is potentially useful. It will tell us where the failing BUF_MEM function was called from.
|
This PR is in a state where it requires action by @openssl/otc but the last update was 30 days ago |
... while in reality, it is a utility "sub-system", all declared in If you think about it, though, the extended line of thinking from where you're going with this is that we can essentially forego almost all sub-system indicators (what the ERR sub-system calls "lib"), and all that will remain for things in libcrypto is However, that's not at all how it all works now, and I definitely do not believe that it's a good thing to do some kind of incremental (almost sneaky) shift toward that.
I'm actually working out that PR now. |
df57553 to
6a6e27b
Compare
|
Rebased to fix merge conflict |
See #19301 |
As requested in #14833 (comment), this
is an extension of #14833 with a further commit thatreplacesall
ERR_raise(ERR_LIB_FOO, ERR_R_MALLOC_FAILURE)callsby
ERR_raise(ERR_LIB_FOO, ERR_R_CRYPTO_LIB).It does this change also for
SSLfatal()andRLAYERfatal()calls,as well as for the (legacy engine)ECerr(),EVPerr(),CAPIerr()andATTICerr()calls.On this occasion, it also adapts remnant
ECerr()andEVPerr()calls incrypto/toERR_raise().