[blivet] Beware of parted possibly returning unicode objects (#973019)

Vratislav Podzimek vpodzime at redhat.com
Mon Jun 24 13:27:24 UTC 2013


On Thu, 2013-06-20 at 09:25 -0700, Brian C. Lane wrote:
> On Wed, Jun 19, 2013 at 01:57:12PM +0200, Vratislav Podzimek wrote:
> > We return plain strings everywhere so we should encode the unicode object with
> > utf-8 and store it as a plain string.
> > 
> > Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> > ---
> >  blivet/devices.py | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/blivet/devices.py b/blivet/devices.py
> > index 4877a39..6aa6c26 100644
> > --- a/blivet/devices.py
> > +++ b/blivet/devices.py
> > @@ -1374,8 +1374,8 @@ class PartitionDevice(StorageDevice):
> >          if self.partedPartition is None:
> >              self._name = self.req_name
> >          else:
> > -            self._name = \
> > -                devicePathToName(self.partedPartition.getDeviceNodeName())
> > +            dev_node_name = self.partedPartition.getDeviceNodeName()
> > +            self._name = devicePathToName(dev_node_name.encode("utf-8"))
> >  
> >      def dependsOn(self, dep):
> >          """ Return True if this device depends on dep. """
> > -- 
> > 1.7.11.7
> 
> Have you tested this? I'm worried about what happens when the ascii
> self._name gets used. Are there places where it has to match what parted
> returned? eg. looking up the device using the name.
I've tested that it really fixes the issue reported in the bug. However,
I'll give it some more testing to find out if it doesn't break something
else. Generally it should be okay, because "ascii_str".encode("utf-8")
just returns the same string and u"ascii_str" == "ascii_str" returns
True. But looking at the code I see more places where the
getDeviceNodeName is called, so I'll send a new patch adding the
encoding to them as well.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list