[OE-core] [PATCH v3] wic: ensure generated disk system identifier is non-zero

Ed Bartosh ed.bartosh at linux.intel.com
Sun Jul 30 10:02:36 UTC 2017


On Sat, Jul 29, 2017 at 12:45:27AM +1000, Jonathan Liu wrote:
> Zero may be interpreted as no MBR signature present and another
> partitioning program might install a new MBR signature.
> 
> Signed-off-by: Jonathan Liu <net147 at gmail.com>
> ---
>  scripts/lib/wic/plugins/imager/direct.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
> index f20d8433f1..fe9b688ab0 100644
> --- a/scripts/lib/wic/plugins/imager/direct.py
> +++ b/scripts/lib/wic/plugins/imager/direct.py
> @@ -297,7 +297,7 @@ class PartitionedImage():
>                            # all partitions (in bytes)
>          self.ptable_format = ptable_format  # Partition table format
>          # Disk system identifier
> -        self.identifier = int.from_bytes(os.urandom(4), 'little')
> +        self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffff
>  

Can we generate random identifier by calling os.urandom again if
self.identifier is zero? Something like this, may be?

while True:
    self.identifier = int.from_bytes(os.urandom(4), 'little')
    if self.identifier:
        break

Assigning constant 0xffffffff can potentially create nonunique identifiers.

>          self.partitions = partitions
>          self.partimages = []
> -- 
> 2.13.2
> 
> -- 
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core at lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core

-- 
--
Regards,
Ed



More information about the Openembedded-core mailing list