Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F115258559
D49936.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D49936.diff
View Options
diff --git a/lib/libc/net/linkaddr.3 b/lib/libc/net/linkaddr.3
--- a/lib/libc/net/linkaddr.3
+++ b/lib/libc/net/linkaddr.3
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd February 28, 2007
+.Dd April 21, 2025
.Dt LINK_ADDR 3
.Os
.Sh NAME
@@ -41,16 +41,26 @@
.In sys/types.h
.In sys/socket.h
.In net/if_dl.h
-.Ft void
+.Ft int
.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl"
.Ft char *
.Fn link_ntoa "const struct sockaddr_dl *sdl"
.Sh DESCRIPTION
The routine
.Fn link_addr
-interprets character strings representing
-link-level addresses, returning binary information suitable
-for use in system calls.
+parses a character string
+.Fa addr
+representing a link-level address,
+and stores the resulting address in the structure pointed to by
+.Fa sdl .
+Addresses consist of a series of hexadecimal characters separated by
+either
+.Sq "."
+or
+.Sq ":"
+characters, or an arbitrary string containing the name of an interface
+or the numeric value of an interface index.
+.Pp
The routine
.Fn link_ntoa
takes
@@ -96,10 +106,8 @@
always returns a null terminated string.
The
.Fn link_addr
-function
-has no return value.
-(See
-.Sx BUGS . )
+function returns 0 on success, or -1 if the address did not appear to
+be a valid link-level address.
.Sh SEE ALSO
.Xr getnameinfo 3
.Sh HISTORY
@@ -113,11 +121,6 @@
The returned values for link_ntoa
reside in a static memory area.
.Pp
-The function
-.Fn link_addr
-should diagnose improperly formed input, and there should be an unambiguous
-way to recognize this.
-.Pp
If the
.Va sdl_len
field of the link socket address
diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c
--- a/lib/libc/net/linkaddr.c
+++ b/lib/libc/net/linkaddr.c
@@ -46,7 +46,7 @@
#define DELIM (4*2)
#define LETTER (4*3)
-void
+int
link_addr(const char *addr, struct sockaddr_dl *sdl)
{
char *cp = sdl->sdl_data;
@@ -69,8 +69,10 @@
(((*addr >= 'A') && (*addr <= 'Z')) ||
((*addr >= 'a') && (*addr <= 'z'))))
state |= LETTER;
- else
+ else if ((*addr == ':') || (*addr == '.'))
state |= DELIM;
+ else
+ return (-1);
addr++;
switch (state /* | INPUT */) {
case NAMING | DIGIT:
@@ -110,7 +112,7 @@
new = cp - (char *)sdl;
if (new > sizeof(*sdl))
sdl->sdl_len = new;
- return;
+ return (0);
}
static const char hexlist[] = "0123456789abcdef";
diff --git a/sbin/ifconfig/af_link.c b/sbin/ifconfig/af_link.c
--- a/sbin/ifconfig/af_link.c
+++ b/sbin/ifconfig/af_link.c
@@ -210,7 +210,8 @@
temp[0] = ':';
strcpy(temp + 1, addr);
sdl.sdl_len = sizeof(sdl);
- link_addr(temp, &sdl);
+ if (link_addr(temp, &sdl) == -1)
+ errx(1, "malformed link-level address");
free(temp);
}
if (sdl.sdl_alen > sizeof(sa->sa_data))
diff --git a/sys/net/if_dl.h b/sys/net/if_dl.h
--- a/sys/net/if_dl.h
+++ b/sys/net/if_dl.h
@@ -78,7 +78,7 @@
#include <sys/cdefs.h>
__BEGIN_DECLS
-void link_addr(const char *, struct sockaddr_dl *);
+int link_addr(const char *, struct sockaddr_dl *);
char *link_ntoa(const struct sockaddr_dl *);
__END_DECLS
diff --git a/sys/sys/param.h b/sys/sys/param.h
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -73,7 +73,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1500038
+#define __FreeBSD_version 1500039
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 22, 11:09 PM (6 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17717537
Default Alt Text
D49936.diff (3 KB)
Attached To
Mode
D49936: link_addr: only accept '.' and ':' as separators
Attached
Detach File
Event Timeline
Log In to Comment