diff mbox

uefi: uefidump: don't dump non-printable variable contents (LP: #1435346)

Message ID 1427425574-3188-1-git-send-email-colin.king@canonical.com
State Rejected
Headers show

Commit Message

Colin Ian King March 27, 2015, 3:06 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Do a hex dump of kernel dump UEFI vars if the contents is
not printable ASCII.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/uefi/uefidump/uefidump.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

Comments

Ivan Hu March 27, 2015, 3:27 a.m. UTC | #1
This patch had already been sent and got 2 acks, any differences from 
the last one?

On 2015年03月27日 11:06, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Do a hex dump of kernel dump UEFI vars if the contents is
> not printable ASCII.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/uefi/uefidump/uefidump.c | 32 ++++++++++++++++++++++++--------
>   1 file changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index 8421e72..014abe2 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -768,19 +768,35 @@ static void uefidump_info_dump_type0(fwts_framework *fw, fwts_uefi_var *var)
>   {
>   	char *ptr = (char*)var->data;
>   	size_t len = var->datalen;
> +	bool printable = true;
>   
>   	while (len && *ptr) {
> -		char *start = ptr;
> -		while (len && *ptr && *ptr != '\n') {
> -			ptr++;
> -			len--;
> +		if (!(isspace(*ptr) || isprint(*ptr))) {
> +			printable = false;
> +			break;
>   		}
> +		ptr++;
> +		len--;
> +	}
>   
> -		if (*ptr == '\n') {
> -			*ptr++ = '\0';
> -			len--;
> -			fwts_log_info_verbatum(fw, "  KLog: %s.", start);
> +	ptr = (char*)var->data;
> +	len = var->datalen;
> +
> +	if (printable) {
> +		while (len && *ptr) {
> +			char *start = ptr;
> +			while (len && *ptr && *ptr != '\n') {
> +				ptr++;
> +				len--;
> +			}
> +			if (*ptr == '\n') {
> +				*ptr++ = '\0';
> +				len--;
> +				fwts_log_info_verbatum(fw, "  KLog: %s.", start);
> +			}
>   		}
> +	} else {
> +		uefidump_var_hexdump(fw, var);
>   	}
>   }
>
Colin Ian King March 27, 2015, 3:30 a.m. UTC | #2
On 26/03/15 20:27, ivanhu wrote:
> This patch had already been sent and got 2 acks, any differences from
> the last one?

Oops, sorry, I somehow sent that out by mistake. Please ignore this.

Colin
> 
> On 2015年03月27日 11:06, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Do a hex dump of kernel dump UEFI vars if the contents is
>> not printable ASCII.
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>   src/uefi/uefidump/uefidump.c | 32 ++++++++++++++++++++++++--------
>>   1 file changed, 24 insertions(+), 8 deletions(-)
>>
>> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
>> index 8421e72..014abe2 100644
>> --- a/src/uefi/uefidump/uefidump.c
>> +++ b/src/uefi/uefidump/uefidump.c
>> @@ -768,19 +768,35 @@ static void
>> uefidump_info_dump_type0(fwts_framework *fw, fwts_uefi_var *var)
>>   {
>>       char *ptr = (char*)var->data;
>>       size_t len = var->datalen;
>> +    bool printable = true;
>>         while (len && *ptr) {
>> -        char *start = ptr;
>> -        while (len && *ptr && *ptr != '\n') {
>> -            ptr++;
>> -            len--;
>> +        if (!(isspace(*ptr) || isprint(*ptr))) {
>> +            printable = false;
>> +            break;
>>           }
>> +        ptr++;
>> +        len--;
>> +    }
>>   -        if (*ptr == '\n') {
>> -            *ptr++ = '\0';
>> -            len--;
>> -            fwts_log_info_verbatum(fw, "  KLog: %s.", start);
>> +    ptr = (char*)var->data;
>> +    len = var->datalen;
>> +
>> +    if (printable) {
>> +        while (len && *ptr) {
>> +            char *start = ptr;
>> +            while (len && *ptr && *ptr != '\n') {
>> +                ptr++;
>> +                len--;
>> +            }
>> +            if (*ptr == '\n') {
>> +                *ptr++ = '\0';
>> +                len--;
>> +                fwts_log_info_verbatum(fw, "  KLog: %s.", start);
>> +            }
>>           }
>> +    } else {
>> +        uefidump_var_hexdump(fw, var);
>>       }
>>   }
>>   
> 
1
diff mbox

Patch

diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
index 8421e72..014abe2 100644
--- a/src/uefi/uefidump/uefidump.c
+++ b/src/uefi/uefidump/uefidump.c
@@ -768,19 +768,35 @@  static void uefidump_info_dump_type0(fwts_framework *fw, fwts_uefi_var *var)
 {
 	char *ptr = (char*)var->data;
 	size_t len = var->datalen;
+	bool printable = true;
 
 	while (len && *ptr) {
-		char *start = ptr;
-		while (len && *ptr && *ptr != '\n') {
-			ptr++;
-			len--;
+		if (!(isspace(*ptr) || isprint(*ptr))) {
+			printable = false;
+			break;
 		}
+		ptr++;
+		len--;
+	}
 
-		if (*ptr == '\n') {
-			*ptr++ = '\0';
-			len--;
-			fwts_log_info_verbatum(fw, "  KLog: %s.", start);
+	ptr = (char*)var->data;
+	len = var->datalen;
+
+	if (printable) {
+		while (len && *ptr) {
+			char *start = ptr;
+			while (len && *ptr && *ptr != '\n') {
+				ptr++;
+				len--;
+			}
+			if (*ptr == '\n') {
+				*ptr++ = '\0';
+				len--;
+				fwts_log_info_verbatum(fw, "  KLog: %s.", start);
+			}
 		}
+	} else {
+		uefidump_var_hexdump(fw, var);
 	}
 }