Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys change nfs_boot_sendrecv to take sockaddr_in * instead o...
details: https://anonhg.NetBSD.org/src/rev/27ceddce8d29
branches: trunk
changeset: 338390:27ceddce8d29
user: rtr <rtr%NetBSD.org@localhost>
date: Thu May 21 02:04:22 2015 +0000
description:
change nfs_boot_sendrecv to take sockaddr_in * instead of mbuf *
fixes m_serv (single mbuf leak) leak in kern/subr_tftproot.c
diffstat:
sys/kern/subr_tftproot.c | 18 +++++++-----------
sys/nfs/krpc_subr.c | 18 +++++++-----------
sys/nfs/nfs_boot.c | 8 ++++----
sys/nfs/nfs_bootdhcp.c | 26 +++++++++++---------------
sys/nfs/nfsdiskless.h | 4 ++--
5 files changed, 31 insertions(+), 43 deletions(-)
diffs (264 lines):
diff -r 869f6ef10dff -r 27ceddce8d29 sys/kern/subr_tftproot.c
--- a/sys/kern/subr_tftproot.c Thu May 21 01:29:13 2015 +0000
+++ b/sys/kern/subr_tftproot.c Thu May 21 02:04:22 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_tftproot.c,v 1.15 2015/05/10 18:55:22 rtr Exp $ */
+/* $NetBSD: subr_tftproot.c,v 1.16 2015/05/21 02:04:22 rtr Exp $ */
/*-
* Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved.
@@ -39,7 +39,7 @@
#include "opt_md.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.15 2015/05/10 18:55:22 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.16 2015/05/21 02:04:22 rtr Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -207,7 +207,7 @@
struct socket *so = NULL;
struct mbuf *m_serv = NULL;
struct mbuf *m_outbuf = NULL;
- struct sockaddr_in *sin;
+ struct sockaddr_in sin;
struct tftphdr *tftp;
size_t packetlen, namelen;
int error = -1;
@@ -233,11 +233,8 @@
/*
* Set server address and port
*/
- m_serv = m_get(M_WAIT, MT_SONAME);
- m_serv->m_len = sizeof(*sin);
- sin = mtod(m_serv, struct sockaddr_in *);
- memcpy(sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(*sin));
- sin->sin_port = htons(IPPORT_TFTP);
+ memcpy(&sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(sin));
+ sin.sin_port = htons(IPPORT_TFTP);
/*
* Set send buffer, prepare the TFTP packet
@@ -268,9 +265,8 @@
/*
* Perform the file transfer
*/
- sin = (struct sockaddr_in *)&trh->trh_nd->nd_root.ndm_saddr;
printf("tftproot: download %s:%s ",
- inet_ntoa(sin->sin_addr), trh->trh_nd->nd_bootfile);
+ inet_ntoa(sin.sin_addr), trh->trh_nd->nd_bootfile);
do {
/*
@@ -287,7 +283,7 @@
* We get the sender address here, which should be
* the same server with a different port
*/
- if ((error = nfs_boot_sendrecv(so, m_serv, NULL, m_outbuf,
+ if ((error = nfs_boot_sendrecv(so, &sin, NULL, m_outbuf,
tftproot_recv, NULL, &m_serv, trh, l)) != 0) {
DPRINTF(("%s():%d sendrecv failed %d\n",
__func__, __LINE__, error));
diff -r 869f6ef10dff -r 27ceddce8d29 sys/nfs/krpc_subr.c
--- a/sys/nfs/krpc_subr.c Thu May 21 01:29:13 2015 +0000
+++ b/sys/nfs/krpc_subr.c Thu May 21 02:04:22 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: krpc_subr.c,v 1.40 2015/05/09 18:12:19 rtr Exp $ */
+/* $NetBSD: krpc_subr.c,v 1.41 2015/05/21 02:04:22 rtr Exp $ */
/*
* Copyright (c) 1995 Gordon Ross, Adam Glass
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: krpc_subr.c,v 1.40 2015/05/09 18:12:19 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: krpc_subr.c,v 1.41 2015/05/21 02:04:22 rtr Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -219,8 +219,8 @@
/* from_p: output */
{
struct socket *so;
- struct sockaddr_in *sin;
- struct mbuf *m, *nam, *mhead, *from;
+ struct sockaddr_in sin;
+ struct mbuf *m, *mhead, *from;
struct rpc_call *call;
struct rpc_reply *reply;
int error, len;
@@ -235,7 +235,7 @@
return (EAFNOSUPPORT);
/* Free at end if not null. */
- nam = mhead = NULL;
+ mhead = NULL;
from = NULL;
/*
@@ -274,10 +274,7 @@
/*
* Setup socket address for the server.
*/
- nam = m_get(M_WAIT, MT_SONAME);
- sin = mtod(nam, struct sockaddr_in *);
- memcpy((void *)sin, (void *)sa,
- (nam->m_len = sa->sin_len));
+ sin = *sa;
/*
* Prepend RPC message header.
@@ -314,7 +311,7 @@
mhead->m_pkthdr.len = len;
mhead->m_pkthdr.rcvif = NULL;
- error = nfs_boot_sendrecv(so, nam, NULL, mhead, krpccheck, &m, &from,
+ error = nfs_boot_sendrecv(so, &sin, NULL, mhead, krpccheck, &m, &from,
&xid, l);
if (error)
goto out;
@@ -383,7 +380,6 @@
}
out:
- if (nam) m_freem(nam);
if (mhead) m_freem(mhead);
if (from) m_freem(from);
soclose(so);
diff -r 869f6ef10dff -r 27ceddce8d29 sys/nfs/nfs_boot.c
--- a/sys/nfs/nfs_boot.c Thu May 21 01:29:13 2015 +0000
+++ b/sys/nfs/nfs_boot.c Thu May 21 02:04:22 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_boot.c,v 1.84 2015/05/09 15:22:47 rtr Exp $ */
+/* $NetBSD: nfs_boot.c,v 1.85 2015/05/21 02:04:22 rtr Exp $ */
/*-
* Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.84 2015/05/09 15:22:47 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.85 2015/05/21 02:04:22 rtr Exp $");
#ifdef _KERNEL_OPT
#include "opt_nfs.h"
@@ -425,7 +425,7 @@
#define TOTAL_TIMEOUT 30 /* seconds */
int
-nfs_boot_sendrecv(struct socket *so, struct mbuf *nam,
+nfs_boot_sendrecv(struct socket *so, struct sockaddr_in *nam,
int (*sndproc)(struct mbuf *, void *, int),
struct mbuf *snd,
int (*rcvproc)(struct mbuf **, void *),
@@ -468,7 +468,7 @@
error = ENOBUFS;
goto out;
}
- error = (*so->so_send)(so, mtod(nam, struct sockaddr *), NULL,
+ error = (*so->so_send)(so, (struct sockaddr *)nam, NULL,
m, NULL, 0, lwp);
if (error) {
printf("nfs_boot: sosend: %d\n", error);
diff -r 869f6ef10dff -r 27ceddce8d29 sys/nfs/nfs_bootdhcp.c
--- a/sys/nfs/nfs_bootdhcp.c Thu May 21 01:29:13 2015 +0000
+++ b/sys/nfs/nfs_bootdhcp.c Thu May 21 02:04:22 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_bootdhcp.c,v 1.54 2015/05/09 18:12:19 rtr Exp $ */
+/* $NetBSD: nfs_bootdhcp.c,v 1.55 2015/05/21 02:04:22 rtr Exp $ */
/*-
* Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.54 2015/05/09 18:12:19 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.55 2015/05/21 02:04:22 rtr Exp $");
#ifdef _KERNEL_OPT
#include "opt_nfs_boot.h"
@@ -486,8 +486,8 @@
struct ifnet *ifp = nd->nd_ifp;
static u_int32_t xid = ~0xFF;
struct bootp *bootp; /* request */
- struct mbuf *m, *nam;
- struct sockaddr_in *sin;
+ struct mbuf *m;
+ struct sockaddr_in sin;
int error;
const u_char *haddr;
u_char hafmt, halen;
@@ -505,7 +505,7 @@
* and free each at the end if not null.
*/
bpc.replybuf = NULL;
- m = nam = NULL;
+ m = NULL;
/* Record our H/W (Ethernet) address. */
{ const struct sockaddr_dl *sdl = ifp->if_sadl;
@@ -585,12 +585,10 @@
/*
* Setup socket address for the server.
*/
- nam = m_get(M_WAIT, MT_SONAME);
- sin = mtod(nam, struct sockaddr_in *);
- sin->sin_len = nam->m_len = sizeof(*sin);
- sin->sin_family = AF_INET;
- sin->sin_addr.s_addr = INADDR_BROADCAST;
- sin->sin_port = htons(IPPORT_BOOTPS);
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = INADDR_BROADCAST;
+ sin.sin_port = htons(IPPORT_BOOTPS);
/*
* Allocate buffer used for request
@@ -635,7 +633,7 @@
bpc.dhcp_ok = 0;
#endif
- error = nfs_boot_sendrecv(so, nam, bootpset, m,
+ error = nfs_boot_sendrecv(so, &sin, bootpset, m,
bootpcheck, NULL, NULL, &bpc, lwp);
if (error)
goto out;
@@ -662,7 +660,7 @@
bpc.expected_dhcpmsgtype = DHCPACK;
- error = nfs_boot_sendrecv(so, nam, bootpset, m,
+ error = nfs_boot_sendrecv(so, &sin, bootpset, m,
bootpcheck, NULL, NULL, &bpc, lwp);
if (error)
goto out;
@@ -688,8 +686,6 @@
free(bpc.replybuf, M_DEVBUF);
if (m)
m_freem(m);
- if (nam)
- m_freem(nam);
soclose(so);
return (error);
}
diff -r 869f6ef10dff -r 27ceddce8d29 sys/nfs/nfsdiskless.h
--- a/sys/nfs/nfsdiskless.h Thu May 21 01:29:13 2015 +0000
+++ b/sys/nfs/nfsdiskless.h Thu May 21 02:04:22 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfsdiskless.h,v 1.31 2015/03/27 07:18:11 hikaru Exp $ */
+/* $NetBSD: nfsdiskless.h,v 1.32 2015/05/21 02:04:22 rtr Exp $ */
/*-
* Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
int nfs_boot_setrecvtimo (struct socket *);
int nfs_boot_enbroadcast (struct socket *);
int nfs_boot_sobind_ipport (struct socket *, uint16_t, struct lwp *);
-int nfs_boot_sendrecv (struct socket *, struct mbuf *,
+int nfs_boot_sendrecv (struct socket *, struct sockaddr_in *,
int (*)(struct mbuf*, void*, int), struct mbuf*,
int (*)(struct mbuf**, void*), struct mbuf**,
struct mbuf**, void*, struct lwp *);
Home |
Main Index |
Thread Index |
Old Index