Hey, While playing around with different MAC address notations supported by postgresql, I encountered the following:
db=> select '08002b-010203'::macaddr;
macaddr
-------------------
08:00:2b:01:02:03
(1 row)
db=> select '08002b-01023'::macaddr;
macaddr
-------------------
08:00:2b:01:02:03
(1 row)
db=> select '08002b-0123'::macaddr;
macaddr
-------------------
08:00:2b:00:12:03
(1 row)
db=> select '08002b-123'::macaddr;
ERROR: invalid input syntax for type macaddr: "08002b-123"
LINE 1: select '08002b-123'::macaddr;
^
db=> select '08002b-1203'::macaddr;
ERROR: invalid octet value in "macaddr" value: "08002b-1203"
LINE 1: select '08002b-1203'::macaddr;
^
(These particular results have been encountered on 8.4.4, but similar issues
still seem to exist in the git head I pulled last week.)
Note how for example '08002b-0123' is accepted as a valid MAC and is parsed as
'08:00:2b:00:12:03' leading to two additional zeroes being added in different
places. Furthermore, the last example actually matches the pattern for a MAC
without delimiters, incorrectly parsing "-1" as one of the octets and thus
resulting in an error about invalid octets instead of an invalid syntax.
In case anyone is interested, I have attached a simple attempt at a patch for
the MAC address parser that makes it a bit more strict in such a way that it
still accepts the formats specified in the documentation, but rejects many
other "broken" addresses that are currently accepted with sometimes surprising
results. The attached version also rejects MACs containing additional
whitespace between the octets and separators etc. The patch probably still
needs a bit of work to make it more in line with your coding style, as well as
a decent review to make sure it doesn't break anything else, but I'll leave
that to those who know more about postgresql, MAC notations and sscanf :)
I have also added a couple of additional test cases in the same diff, although
the code could still use a few more for possible corner cases etc.
Regards,
Matthijs Bomhoff
mac_parser.diff
Description: Binary data
-- Sent via pgsql-bugs mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
