After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 730514 - keyfile: fix reading MAC addresses in old format (list of integers)
keyfile: fix reading MAC addresses in old format (list of integers)
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-05-21 12:27 UTC by Jiri Klimes
Modified: 2014-05-29 19:00 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jiri Klimes 2014-05-21 12:27:31 UTC
mac_address_parser() missed reading MAC addresses in old format. Please see a branch with a fix jk/keyfile-mac-fix.
Comment 1 Thomas Haller 2014-05-23 11:07:34 UTC
I think, nm_utils_hwaddr_type() should accept unknown lengths and just return "-1". It is useful for functions with a "is_a" or "has_a" semantic to allow invalid types, so that they can be used to check for valid types.

I pushed a commit on top of yours changing this behaviour (and reverting your change). I also checked all uses of those functions and related hwaddr functions that they behave reasonable in case of errors and/or assert against the input.

Your test case looks good to me.
Comment 2 Dan Williams 2014-05-23 17:10:37 UTC
We deprecated nm_utils_hwaddr_type() though:

 * Deprecated: This could not be extended to cover other types, since
 * there is not a one-to-one mapping between types and lengths. This
 * was mostly only used to get a type to pass to
 * nm_utils_hwaddr_ntoa() or nm_utils_hwaddr_aton() when you only had
 * a length; but you can just use nm_utils_hwaddr_ntoa_len() or
 * nm_utils_hwaddr_aton_len() now instead.

So perhaps we should switch to nm_utils_hwaddr_atoba_len() for the first case?  At least if we're here, we should rewrite the code to stop using deprecated functions.

---

Thomas' change looks fine to me.
Comment 3 Thomas Haller 2014-05-23 17:23:29 UTC
(In reply to comment #2)
> We deprecated nm_utils_hwaddr_type() though:
> 
>  * Deprecated: This could not be extended to cover other types, since
>  * there is not a one-to-one mapping between types and lengths. This
>  * was mostly only used to get a type to pass to
>  * nm_utils_hwaddr_ntoa() or nm_utils_hwaddr_aton() when you only had
>  * a length; but you can just use nm_utils_hwaddr_ntoa_len() or
>  * nm_utils_hwaddr_aton_len() now instead.
> 
> So perhaps we should switch to nm_utils_hwaddr_atoba_len() for the first case? 
> At least if we're here, we should rewrite the code to stop using deprecated
> functions.

I think that is not possible, because we use the length for guessing the type of the MAC address. There is not replacement for that.

- nm_utils_hwaddr_ntoa() or nm_utils_hwaddr_aton():
  already expect the "type", which nm_utils_hwaddr_type() guesses.

- nm_utils_hwaddr_ntoa_len():
  expects that you already know the length (and indirectly the type).
  It will then check that the provided input string parses as a valid MAC
  address of that type/length.


A better name for nm_utils_hwaddr_type() would be nm_utils_guess_hwaddr_type_from_len()
Comment 4 Thomas Haller 2014-05-27 14:13:50 UTC
I pushed 4 additional commits.

>> libnm-util: undeprecated nm_utils_hwaddr_type()

It seems useful to be able to test for common HWADDR lengths. Maybe we should not deprecate nm_utils_hwaddr_type() -- ?


>> keyfile: don't check HWADDR length in mac_address_parser()
>> keyfile: don't check HWADDR length in mac_address_writer()
>> cli: don't use nm_utils_hwaddr_type() to stringify HWADDR

no longer user nm_utils_hwaddr_type(). If we keep the function deprecated, we should not use it. Even if we decide to undeprecated it, we might want to keep these patches, because they make the parsing/stringification of HWADDR more relaxed. Which *could* be desired -- ?
Comment 5 Dan Winship 2014-05-27 14:43:20 UTC
(In reply to comment #4)
> I pushed 4 additional commits.
> 
> >> libnm-util: undeprecated nm_utils_hwaddr_type()
> 
> It seems useful to be able to test for common HWADDR lengths. Maybe we should
> not deprecate nm_utils_hwaddr_type() -- ?

But it can never be made much more generic, because most of the ARPHRD types have length 8. So it's really "distinguish between ARPHRD_ETHER and ARPHRD_INFINIBAND but only if you know it has to be one or the other". And that's pretty easy to open code.

> >> keyfile: don't check HWADDR length in mac_address_parser()

An alternative here that wouldn't lose any checking would be to add two wrappers around mac_address_parser() that call into the same generic function, passing the expected length along with the other args. (And likewise with writer.)
Comment 6 Thomas Haller 2014-05-27 16:30:35 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > I pushed 4 additional commits.
> > 
> > >> libnm-util: undeprecated nm_utils_hwaddr_type()
> > 
> > It seems useful to be able to test for common HWADDR lengths. Maybe we should
> > not deprecate nm_utils_hwaddr_type() -- ?
> 
> But it can never be made much more generic, because most of the ARPHRD types
> have length 8. So it's really "distinguish between ARPHRD_ETHER and
> ARPHRD_INFINIBAND but only if you know it has to be one or the other". And
> that's pretty easy to open code.
> 
> > >> keyfile: don't check HWADDR length in mac_address_parser()
> 
> An alternative here that wouldn't lose any checking would be to add two
> wrappers around mac_address_parser() that call into the same generic function,
> passing the expected length along with the other args. (And likewise with
> writer.)

Yeah, these 4 patches are suggestions, not sure we want to do that (e.g. the un-deprecation?).

I pushed a fixup! with that suggestion. Not sure if it's a good idea though. There is already NMSetting:verify() which enforces the proper length of the MAC address. This kind of duplicates this requirement. On the other hand, it moves the validation closer to reading the keyfile value, so it might be better. Opinions?
Comment 7 Dan Winship 2014-05-27 18:06:50 UTC
(In reply to comment #6)
> There is already NMSetting:verify() which enforces the proper length of the MAC
> address. This kind of duplicates this requirement. On the other hand, it moves
> the validation closer to reading the keyfile value, so it might be better.
> Opinions?

the error from NMSetting:verify() includes the property name that it's talking about, so it should still be pretty clear what the problem is at that point.
Comment 8 Dan Williams 2014-05-28 23:09:59 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > I pushed 4 additional commits.
> > > 
> > > >> libnm-util: undeprecated nm_utils_hwaddr_type()
> > > 
> > > It seems useful to be able to test for common HWADDR lengths. Maybe we should
> > > not deprecate nm_utils_hwaddr_type() -- ?
> > 
> > But it can never be made much more generic, because most of the ARPHRD types
> > have length 8. So it's really "distinguish between ARPHRD_ETHER and
> > ARPHRD_INFINIBAND but only if you know it has to be one or the other". And
> > that's pretty easy to open code.
> > 
> > > >> keyfile: don't check HWADDR length in mac_address_parser()
> > 
> > An alternative here that wouldn't lose any checking would be to add two
> > wrappers around mac_address_parser() that call into the same generic function,
> > passing the expected length along with the other args. (And likewise with
> > writer.)
> 
> Yeah, these 4 patches are suggestions, not sure we want to do that (e.g. the
> un-deprecation?).
> 
> I pushed a fixup! with that suggestion. Not sure if it's a good idea though.
> There is already NMSetting:verify() which enforces the proper length of the MAC
> address. This kind of duplicates this requirement. On the other hand, it moves
> the validation closer to reading the keyfile value, so it might be better.
> Opinions?

I like this approach.  The squashed branch looks good to me and passes 'make check'.
Comment 9 Thomas Haller 2014-05-29 17:03:44 UTC
Branch merged as:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=b5a94ae4796dac2cc757d301a27e1a6f91ee23a3


(dropped patch with undeprecation nm_utils_hwaddr_type())