diff mbox series

corelib: print error code instead of reason string

Message ID 1521656509-13564-1-git-send-email-geier.xmartin@gmail.com
State Changes Requested
Headers show
Series corelib: print error code instead of reason string | expand

Commit Message

Martin Geier March 21, 2018, 6:21 p.m. UTC
From: Martin Geier <martin.geier@streamunlimited.com>

Reason string is often null, print error hex code same way
as in swupdate_DECRYPT_update or swupdate_DECRYPT_init functions

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
---
 corelib/swupdate_decrypt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Stefano Babic March 21, 2018, 9:46 p.m. UTC | #1
Hi Martin,

On 21/03/2018 19:21, Martin Geier wrote:
> From: Martin Geier <martin.geier@streamunlimited.com>
> 
> Reason string is often null,

Often or always ?

> print error hex code same way
> as in swupdate_DECRYPT_update or swupdate_DECRYPT_init functions
> 
> Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
> ---
>  corelib/swupdate_decrypt.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c
> index 3238cce..c944876 100644
> --- a/corelib/swupdate_decrypt.c
> +++ b/corelib/swupdate_decrypt.c
> @@ -96,8 +96,7 @@ int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
>  		return -EINVAL;
>  
>  	if (EVP_DecryptFinal_ex(SSL_GET_CTXDEC(dgst), buf, outlen) != 1) {
> -		ERROR("Decryption error 0x%s\n", 
> -				ERR_reason_error_string(ERR_get_error()));
> +		ERROR("Final: Decryption error 0x%lx\n", ERR_get_error());

I suggest to have both hexadecimal error and ERR_reason_error, if any.

Best regards,
Stefano Babic
Martin Geier March 24, 2018, 9:56 a.m. UTC | #2
Hi,

On 21.03.2018 22:46, Stefano Babic wrote:

> Hi Martin,
>
> On 21/03/2018 19:21, Martin Geier wrote:
>> From: Martin Geier <martin.geier@streamunlimited.com>
>>
>> Reason string is often null,
> Often or always ?

 From documentation: ... ERR_reason_error_string() return the strings, and NULL if none is registered for the error code,
but I saw this function failed in only one case - wrong encryption/decryption key, with error code 06065064
translated as NULL.
This can be fixed calling ERR_load_crypto_strings() in main.

>
>> print error hex code same way
>> as in swupdate_DECRYPT_update or swupdate_DECRYPT_init functions
>>
>> Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
>> ---
>>   corelib/swupdate_decrypt.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c
>> index 3238cce..c944876 100644
>> --- a/corelib/swupdate_decrypt.c
>> +++ b/corelib/swupdate_decrypt.c
>> @@ -96,8 +96,7 @@ int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
>>   		return -EINVAL;
>>   
>>   	if (EVP_DecryptFinal_ex(SSL_GET_CTXDEC(dgst), buf, outlen) != 1) {
>> -		ERROR("Decryption error 0x%s\n",
>> -				ERR_reason_error_string(ERR_get_error()));
>> +		ERROR("Final: Decryption error 0x%lx\n", ERR_get_error());
> I suggest to have both hexadecimal error and ERR_reason_error, if any.

Ok I can change it to something like:
const char *reason = ERR_reason_error_string(ERR_peek_error());
ERROR("Final: Decryption error 0x%lx, reason: %s\n", ERR_get_error(), reason != NULL ? reason, "unknown");

In this case, the same change should be made also for Init and Update function...

>
> Best regards,
> Stefano Babic
>
Martin Geier
Stefano Babic March 24, 2018, 5:54 p.m. UTC | #3
Hallo Martin,

On 24/03/2018 10:56, Martin Geier wrote:
> Hi,
> 
> On 21.03.2018 22:46, Stefano Babic wrote:
> 
>> Hi Martin,
>>
>> On 21/03/2018 19:21, Martin Geier wrote:
>>> From: Martin Geier <martin.geier@streamunlimited.com>
>>>
>>> Reason string is often null,
>> Often or always ?
> 
> From documentation: ... ERR_reason_error_string() return the strings,
> and NULL if none is registered for the error code,
> but I saw this function failed in only one case - wrong
> encryption/decryption key, with error code 06065064
> translated as NULL.
> This can be fixed calling ERR_load_crypto_strings() in main.

ok

> 
>>
>>> print error hex code same way
>>> as in swupdate_DECRYPT_update or swupdate_DECRYPT_init functions
>>>
>>> Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
>>> ---
>>>   corelib/swupdate_decrypt.c | 3 +--
>>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c
>>> index 3238cce..c944876 100644
>>> --- a/corelib/swupdate_decrypt.c
>>> +++ b/corelib/swupdate_decrypt.c
>>> @@ -96,8 +96,7 @@ int swupdate_DECRYPT_final(struct swupdate_digest
>>> *dgst, unsigned char *buf,
>>>           return -EINVAL;
>>>         if (EVP_DecryptFinal_ex(SSL_GET_CTXDEC(dgst), buf, outlen) !=
>>> 1) {
>>> -        ERROR("Decryption error 0x%s\n",
>>> -                ERR_reason_error_string(ERR_get_error()));
>>> +        ERROR("Final: Decryption error 0x%lx\n", ERR_get_error());
>> I suggest to have both hexadecimal error and ERR_reason_error, if any.
> 
> Ok I can change it to something like:
> const char *reason = ERR_reason_error_string(ERR_peek_error());
> ERROR("Final: Decryption error 0x%lx, reason: %s\n", ERR_get_error(),
> reason != NULL ? reason, "unknown");
> 
> In this case, the same change should be made also for Init and Update
> function...

Fine.

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c
index 3238cce..c944876 100644
--- a/corelib/swupdate_decrypt.c
+++ b/corelib/swupdate_decrypt.c
@@ -96,8 +96,7 @@  int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
 		return -EINVAL;
 
 	if (EVP_DecryptFinal_ex(SSL_GET_CTXDEC(dgst), buf, outlen) != 1) {
-		ERROR("Decryption error 0x%s\n", 
-				ERR_reason_error_string(ERR_get_error()));
+		ERROR("Final: Decryption error 0x%lx\n", ERR_get_error());
 		return -EFAULT;
 	}