Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5261bf9

Browse files
committed
Make macaddr_in reject trailing garbage (except whitespace).
Per gripe from Patrick Welche, 13-Oct-2002.
1 parentf94e5bd commit5261bf9

File tree

1 file changed

+18
-9
lines changed
  • src/backend/utils/adt

1 file changed

+18
-9
lines changed

‎src/backend/utils/adt/mac.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*PostgreSQL type definitions for MAC addresses.
33
*
4-
*$Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.26 2002/09/04 20:31:28 momjian Exp $
4+
*$Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.27 2002/10/13 15:39:17 tgl Exp $
55
*/
66

77
#include"postgres.h"
@@ -35,19 +35,28 @@ macaddr_in(PG_FUNCTION_ARGS)
3535
d,
3636
e,
3737
f;
38+
charjunk[2];
3839
intcount;
3940

40-
count=sscanf(str,"%x:%x:%x:%x:%x:%x",&a,&b,&c,&d,&e,&f);
41+
/* %1s matches iff there is trailing non-whitespace garbage */
42+
43+
count=sscanf(str,"%x:%x:%x:%x:%x:%x%1s",
44+
&a,&b,&c,&d,&e,&f,junk);
4145
if (count!=6)
42-
count=sscanf(str,"%x-%x-%x-%x-%x-%x",&a,&b,&c,&d,&e,&f);
46+
count=sscanf(str,"%x-%x-%x-%x-%x-%x%1s",
47+
&a,&b,&c,&d,&e,&f,junk);
4348
if (count!=6)
44-
count=sscanf(str,"%2x%2x%2x:%2x%2x%2x",&a,&b,&c,&d,&e,&f);
49+
count=sscanf(str,"%2x%2x%2x:%2x%2x%2x%1s",
50+
&a,&b,&c,&d,&e,&f,junk);
4551
if (count!=6)
46-
count=sscanf(str,"%2x%2x%2x-%2x%2x%2x",&a,&b,&c,&d,&e,&f);
52+
count=sscanf(str,"%2x%2x%2x-%2x%2x%2x%1s",
53+
&a,&b,&c,&d,&e,&f,junk);
4754
if (count!=6)
48-
count=sscanf(str,"%2x%2x.%2x%2x.%2x%2x",&a,&b,&c,&d,&e,&f);
55+
count=sscanf(str,"%2x%2x.%2x%2x.%2x%2x%1s",
56+
&a,&b,&c,&d,&e,&f,junk);
4957
if (count!=6)
50-
count=sscanf(str,"%2x%2x%2x%2x%2x%2x",&a,&b,&c,&d,&e,&f);
58+
count=sscanf(str,"%2x%2x%2x%2x%2x%2x%1s",
59+
&a,&b,&c,&d,&e,&f,junk);
5160
if (count!=6)
5261
elog(ERROR,"macaddr_in: error in parsing \"%s\"",str);
5362

@@ -122,11 +131,11 @@ text_macaddr(PG_FUNCTION_ARGS)
122131
{
123132
text*addr=PG_GETARG_TEXT_P(0);
124133
Datumresult;
125-
charstr[18];
134+
charstr[100];
126135
intlen;
127136

128137
len= (VARSIZE(addr)-VARHDRSZ);
129-
if (len >=18)
138+
if (len >=sizeof(str))
130139
elog(ERROR,"Text is too long to convert to MAC address");
131140

132141
memcpy(str,VARDATA(addr),len);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp