stand: dev_net: correct net_open's interpretation of params
net_open previously casted the first vararg to a char * and this was half-OK: at first, it is passed to netif_open, which would cast it back to the struct devdesc * that it really is and use it properly. It is then strdup()d and used as the netdev_name, which is objectively wrong. Correct it so that the first vararg is properly casted to a struct devdesc * and the netdev_name gets set properly to make it more clear at a glance that it's not doing something horribly wrong. Reported by: mmel Reviewed by: imp, mmel, tsoome MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D19206
This commit is contained in:
parent
11e67b92b5
commit
e49f2c66d1
@ -122,13 +122,15 @@ net_open(struct open_file *f, ...)
|
|||||||
{
|
{
|
||||||
struct iodesc *d;
|
struct iodesc *d;
|
||||||
va_list args;
|
va_list args;
|
||||||
char *devname; /* Device part of file name (or NULL). */
|
struct devdesc *dev;
|
||||||
|
const char *devname; /* Device part of file name (or NULL). */
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
va_start(args, f);
|
va_start(args, f);
|
||||||
devname = va_arg(args, char*);
|
dev = va_arg(args, struct devdesc *);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
|
devname = dev->d_dev->dv_name;
|
||||||
/* Before opening another interface, close the previous one first. */
|
/* Before opening another interface, close the previous one first. */
|
||||||
if (netdev_sock >= 0 && strcmp(devname, netdev_name) != 0)
|
if (netdev_sock >= 0 && strcmp(devname, netdev_name) != 0)
|
||||||
net_cleanup();
|
net_cleanup();
|
||||||
@ -137,7 +139,7 @@ net_open(struct open_file *f, ...)
|
|||||||
if (netdev_opens == 0) {
|
if (netdev_opens == 0) {
|
||||||
/* Find network interface. */
|
/* Find network interface. */
|
||||||
if (netdev_sock < 0) {
|
if (netdev_sock < 0) {
|
||||||
netdev_sock = netif_open(devname);
|
netdev_sock = netif_open(dev);
|
||||||
if (netdev_sock < 0) {
|
if (netdev_sock < 0) {
|
||||||
printf("net_open: netif_open() failed\n");
|
printf("net_open: netif_open() failed\n");
|
||||||
return (ENXIO);
|
return (ENXIO);
|
||||||
|
Loading…
Reference in New Issue
Block a user