From: | Matthijs Bomhoff <matthijs(at)quarantainenet(dot)nl> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | MACADDR parsing issues |
Date: | 2011-06-06 14:00:52 |
Message-ID: | FAF482C3-B9D4-43DD-9697-0600E97E2FAB@quarantainenet.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
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
Attachment | Content-Type | Size |
---|---|---|
mac_parser.diff | application/octet-stream | 8.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2011-06-06 14:31:50 | Re: MACADDR parsing issues |
Previous Message | Peter Eisentraut | 2011-06-06 10:22:36 | Re: BUG #6052: ADD COLUMN - ERROR: tables can have at most 1600 columns |