* grub-core/fs/udf.c: Fix reading label, lvd.ident is dstring
PATCH 1/1 * grub-core/fs/udf.c: Fix reading label, lvd.ident is dstring
UDF dstring has stored length in the last byte of buffer. Therefore last byte is not part of recorded characters. And empty string in dstring is encoded as empty buffer, including first byte (compression id).
---
I'm not sure how Grub2 should handle empty label. Current patch set empty buffer for empty label. But it is possible to ignore and do not set label in this case at all.
--- grub-core/fs/udf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
grub-core/fs/udf.c +20 -1
@@ -860,6 +860,25 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)return outbuf; } +static char * +read_dstring (const grub_uint8_t *raw,grub_size_t sz,char *outbuf) +{ +grub_size_t len; + +if (raw[0 ] ==0 ) + { +if (!outbuf) + outbuf =grub_malloc (1 ); + outbuf[0 ] =0 ; +return outbuf; + } + + len = raw[sz -1 ]; +if (len > sz -1 ) + len = sz -1 ; +return read_string (raw, len, outbuf); +} +static int grub_udf_iterate_dir (grub_fshelp_node_t dir,grub_fshelp_iterate_dir_hook_t hook,void *hook_data)
@@ -1197,7 +1216,7 @@ grub_udf_label (grub_device_t device, char **label)if (data) { - *label =read_string (data->lvd.ident,sizeof (data->lvd.ident),0 ); + *label =read_dstring (data->lvd.ident,sizeof (data->lvd.ident),0 );grub_free (data); }else
Signature · 1 line
1.7.9.5
Quoted 9 lines · On Thursday 22 June 2017 14:33:17 Pali Rohár wrote:
UDF dstring has stored length in the last byte of buffer. Therefore last byte is not part of recorded characters. And empty string in dstring is encoded as empty buffer, including first byte (compression id).
---
I'm not sure how Grub2 should handle empty label. Current patch set empty buffer for empty label. But it is possible to ignore and do not set label in this case at all.
---
Hi! Any comments on this patch? Specially how to deal with empty labels?
Quoted 43 lines
grub-core/fs/udf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)grub-core/fs/udf.c +19
-1@@ -860,6 +860,25 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) return outbuf; } +static char * +read_dstring (const grub_uint8_t *raw,grub_size_t sz,char *outbuf) +{ +grub_size_t len; + +if (raw[0 ] ==0 ) + { +if (!outbuf) + outbuf =grub_malloc (1 ); + outbuf[0 ] =0 ; +return outbuf; + } + + len = raw[sz -1 ]; +if (len > sz -1 ) + len = sz -1 ; +return read_string (raw, len, outbuf); +} +static int grub_udf_iterate_dir (grub_fshelp_node_t dir,grub_fshelp_iterate_dir_hook_t hook,void *hook_data)@@ -1197,7 +1216,7 @@ grub_udf_label (grub_device_t device, char **label)if (data) { - *label = read_string (data->lvd.ident, sizeof(
data->lvd.ident), 0); + *label =read_dstring(data->lvd.ident, sizeof (data->lvd.ident), 0); grub_free (data); }else
Signature · 2 lines
Pali Rohár [email protected]
Committed with fixes and simplifications. The biggest problem was lack of check whether grub_malloc succeeded
Quoted 61 lines · Pali Rohár
UDF dstring has stored length in the last byte of buffer. Therefore last byte is not part of recorded characters. And empty string in dstring is encoded as empty buffer, including first byte (compression id).
---
I'm not sure how Grub2 should handle empty label. Current patch set empty buffer for empty label. But it is possible to ignore and do not set label in this case at all.--- grub-core/fs/udf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)grub-core/fs/udf.c +19
-0@@ -860,6 +860,25 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)return outbuf; } +static char * +read_dstring (const grub_uint8_t *raw,grub_size_t sz,char *outbuf) +{ +grub_size_t len; + +if (raw[0 ] ==0 ) + { +if (!outbuf) + outbuf =grub_malloc (1 ); + outbuf[0 ] =0 ; +return outbuf; + } + + len = raw[sz -1 ]; +if (len > sz -1 ) + len = sz -1 ; +return read_string (raw, len, outbuf); +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir,
grub_fshelp_iterate_dir_hook_thook, void*hook_data)grub-core/fs/udf.c +1
-1@@ -1197,7 +1216,7 @@ grub_udf_label (grub_device_t device, char **label)if (data) { - *label =read_string (data->lvd.ident,sizeof (data->lvd.ident),0 ); + *label =read_dstring (data->lvd.ident,sizeof (data->lvd.ident),0 );grub_free (data); }else
--
1.7.9.5_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Thanks a lot!
Quoted 66 lines · On Monday 07 August 2017 15:40:15 Vladimir 'phcoder' Serbinenko wrote:
Committed with fixes and simplifications. The biggest problem was lack of check whether
grub_mallocsucceededQuoted 61 lines · Pali Rohár
UDF dstring has stored length in the last byte of buffer. Therefore last byte is not part of recorded characters. And empty string in dstring is encoded as empty buffer, including first byte (compression id).
---
I'm not sure how Grub2 should handle empty label. Current patch set empty buffer for empty label. But it is possible to ignore and do not set label in this case at all.--- grub-core/fs/udf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)grub-core/fs/udf.c +19
-0@@ -860,6 +860,25 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)return outbuf; } +static char * +read_dstring (const grub_uint8_t *raw,grub_size_t sz,char *outbuf) +{ +grub_size_t len; + +if (raw[0 ] ==0 ) + { +if (!outbuf) + outbuf =grub_malloc (1 ); + outbuf[0 ] =0 ; +return outbuf; + } + + len = raw[sz -1 ]; +if (len > sz -1 ) + len = sz -1 ; +return read_string (raw, len, outbuf); +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir,
grub_fshelp_iterate_dir_hook_thook, void*hook_data)grub-core/fs/udf.c +1
-1@@ -1197,7 +1216,7 @@ grub_udf_label (grub_device_t device, char **label)if (data) { - *label =read_string (data->lvd.ident,sizeof (data->lvd.ident),0 ); + *label =read_dstring (data->lvd.ident,sizeof (data->lvd.ident),0 );grub_free (data); }else
--
1.7.9.5_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Pali Rohár [email protected]