Bug 1661245 - bad detection of a string aka mac address
Summary: bad detection of a string aka mac address
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libyaml
Version: 7.6
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: rc
: ---
Assignee: John Eckersberg
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-20 15:11 UTC by Cyril Lopez
Modified: 2019-03-06 00:57 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-12-20 15:17:38 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Cyril Lopez 2018-12-20 15:11:56 UTC
Description of problem:

When I load a yaml with a MAC address as 52:54:00:58:15:35, this is converted in 41135249735

If I change to 52:54:00:58:65:35, is not converted.

Version-Release number of selected component (if applicable):
libyaml-0.1.4-11.el7_0.x86_64
python-2.7.5-76.el7.x86_64

How reproducible:
The YAML file
---
parameter_defaults:
  EnableFencing: true
  FencingConfig:
    devices:
    - agent: fence_xvm
      host_mac: 52:54:00:72:b7:e5
      params:
        multicast_address: 225.0.0.12
        key_file: /etc/cluster/fence_xvm.key
        port: controller01
        interval: 10m
        pcmk_host_list: ctl01
    - agent: fence_xvm
      host_mac: 52:54:00:86:94:61
      params:
        multicast_address: 225.0.0.13
        key_file: /etc/cluster/fence_xvm.key
        port: controller02
        interval: 10m
        pcmk_host_list: ctl02
    - agent: fence_xvm
      host_mac: 52:54:00:58:15:35
      params:
        multicast_address: 225.0.0.14
        key_file: /etc/cluster/fence_xvm.key
        port: controller03
        interval: 10m
        pcmk_host_list: ctl03
...

Steps to Reproduce:
1. take the file below as my.yaml
2. python -c 'import yaml, sys; print yaml.load(sys.stdin)' < my.yaml

Actual results:
{'parameter_defaults': {'FencingConfig': {'devices': [{'params': {'port': 'controller01', 'multicast_address': '225.0.0.12', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl01'}, 'agent': 'fence_xvm', 'host_mac': '52:54:00:72:b7:e5'}, {'params': {'port': 'controller02', 'multicast_address': '225.0.0.13', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl02'}, 'agent': 'fence_xvm', 'host_mac': '52:54:00:86:94:61'}, {'params': {'port': 'controller03', 'multicast_address': '225.0.0.14', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl03'}, 'agent': 'fence_xvm', 'host_mac': 41135249735}]}, 'EnableFencing': True}}


Expected results:
{'parameter_defaults': {'FencingConfig': {'devices': [{'params': {'port': 'controller01', 'multicast_address': '225.0.0.12', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl01'}, 'agent': 'fence_xvm', 'host_mac': '52:54:00:72:b7:e5'}, {'params': {'port': 'controller02', 'multicast_address': '225.0.0.13', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl02'}, 'agent': 'fence_xvm', 'host_mac': '52:54:00:86:94:61'}, {'params': {'port': 'controller03', 'multicast_address': '225.0.0.14', 'interval': '10m', 'key_file': '/etc/cluster/fence_xvm.key', 'pcmk_host_list': 'ctl03'}, 'agent': 'fence_xvm', 'host_mac': '52:54:00:58:15:35'}]}, 'EnableFencing': True}}


Additional info:

Comment 1 Cyril Lopez 2018-12-20 15:17:38 UTC
This mac is a sexagesimal, must be quoted

Comment 2 Hervé Beraud 2018-12-21 15:38:21 UTC
The real error come from this regex:

^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?(?:0|[1-9][0-9_]*)|[-+]?0x[0-9a-fA-F_]+|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$

Who recognize 52:54:00:58:15:35 like an integer...

When we try this regex on 52:54:00:86:94:61 the problem doesn't occur

Comment 3 Hervé Beraud 2018-12-21 15:39:46 UTC
This regex come from the PyYAML library.
The regex is defined in the resolver of pyyaml https://github.com/yaml/pyyaml/blob/master/lib3/yaml/resolver.py#L186

Comment 4 Hervé Beraud 2018-12-21 16:12:51 UTC
The problem occur under python version 2 and 3 and so PyYAML 2 and 3

Comment 5 Hervé Beraud 2018-12-21 16:37:16 UTC
The YAML specification speak about a decimal integer notation, with a leading “-” character for negative values, matching the regular expression: 

0 | -? [1-9] [0-9]* 

https://yaml.org/spec/1.2/spec.html#id2803828

The current regex defined by PyYAML have a problem and introduce this bug

Comment 6 Hervé Beraud 2018-12-21 17:58:51 UTC
The right regex is => ^(?:[-+]?0b[0-1_]+|[-+]?0o?[0-7_]+|[-+]?[0-9_]+|[-+]?0x[0-9a-fA-F_]+)$

I will to fix that on PyYAML and try to backport fix downstream after that

Comment 7 Hervé Beraud 2018-12-21 18:32:31 UTC
With the following regex we can capture the following elements who correspond to the YAML standard definition 1.1 and 1.2

^(?:[-+]?0b[0-1_]+|[-+]?0o?[0-7_]+|[-+]?0?(?:0|[1-9][0-9_]*)|[-+]?0x[0-9a-fA-F_]+)$

Consider the following sample tests :
52:54:00:86:94:61
52:54:00:58:15:35
52:54:00:72:b7:e5
52:54:00:59:16:35
54
0b564
0x64
123456789
0123456789
0b0
0xb
0o13
0xB

This regex catch the following result set:
54
0x64
123456789
0123456789
0b0
0xb
0o13
0xB

We are compatible with the following YAML specifications for the octal and hexadecimal representations:
1.1 => https://yaml.org/spec/current.html#id2507367
1.2 => http://yaml.org/spec/1.2/spec.html#id2764652

Currently PyYAML doesn't deal with retro compatibility and also doesn't catch the octal and hexa representation.

Comment 8 Hervé Beraud 2018-12-21 20:50:05 UTC
concerning the sexagesimal the representation come from https://yaml.org/type/int.html the support was dropped[1] since the version 1.1 of the yaml specifications.

[1] https://yaml.org/spec/1.2/spec.html#id2805071

PyYAML only support YAML 1.1 (https://pyyaml.org/wiki/PyYAML) so sexagesimal can be fixed directly on.

My previous comments and especially my regex doesn't that PyYAML consider YAML standards version 1.1

So quotes are the right solution.

But the real problem is that the format of the MAC address look like a sexagesimal format without really being one.

Comment 9 Hervé Beraud 2018-12-21 20:51:17 UTC
s/can be fixed directly on/cannot be fixed directly on/


Note You need to log in before you can comment on or make changes to this bug.