static int
get_instance(const char *name)
{
- const char *cp, *endcp;
+ const char *cp, *endcp, *errstr;
int n;
if (strcmp(name, "any") == 0) {
for (cp = name; cp < endcp && !isdigit((unsigned char)*cp); ++cp)
continue;
- if (isdigit((unsigned char)*cp))
- n = atoi(cp);
- else
- n = 0;
- return (n);
+ n = strtonum(cp, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ return -1;
+ return n;
}
static int
* Add it to the list, in the appropriate location.
* First, get the instance number of this interface.
*/
- this_instance = get_instance(name);
+ if ((this_instance = get_instance(name)) == -1) {
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "malformed device name: %s", name);
+ goto fail;
+ }
/*
* Now look for the last interface with an instance number
-/* $OpenBSD: inet.c,v 1.27 2024/04/05 18:01:56 deraadt Exp $ */
+/* $OpenBSD: inet.c,v 1.28 2024/08/28 11:41:42 op Exp $ */
/*
* Copyright (c) 1994, 1995, 1996, 1997, 1998
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ifaddrs *ifap, *ifa, *mp;
int n, minunit;
char *cp;
+ const char *errstr;
static char device[IF_NAMESIZE + 1];
if (getifaddrs(&ifap) != 0) {
continue;
for (cp = ifa->ifa_name; !isdigit((unsigned char)*cp); ++cp)
continue;
- n = atoi(cp);
+ n = strtonum(cp, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ continue;
if (n < minunit) {
minunit = n;
mp = ifa;
#else
int fd, minunit, n;
char *cp;
+ const char *errstr;
struct ifreq *ifrp, *ifend, *ifnext, *mp;
struct ifconf ifc;
struct ifreq ibuf[16], ifr;
for (cp = ifrp->ifr_name; !isdigit((unsigned char)*cp); ++cp)
continue;
- n = atoi(cp);
+ n = strtonum(cp, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ continue;
if (n < minunit) {
minunit = n;
mp = ifrp;