svn commit: r344408 - in stable/11/stand/libsa: . zfs

Kyle Evans kevans at FreeBSD.org
Thu Feb 21 02:43:51 UTC 2019


Author: kevans
Date: Thu Feb 21 02:43:48 2019
New Revision: 344408
URL: https://svnweb.freebsd.org/changeset/base/344408

Log:
  MFC various libsa fixes: r337037-r337039, r337065, r337412-r337413, r337874,
  r338535, r338540, r339651, r339992-r339993, r340026
  
  r337037:
  libsa: pointer differs in signedness
  
  A small cleanup, fix the argument type and while there, replace (char *)0 with
  NULL.
  
  r337038:
  libsa: bootp is using pointers with different sign
  
  Just change bp_file to char and same for variable s.
  
  r337039:
  libsa: assignment to char * from u_char *
  
  Cast to char * instead of u_char *
  
  r337065:
  libsa: dereferencing type-punned pointer in cd9660
  
  The warning is given by gcc build, but it is good to fix anyhow.
  use bcopy instead of direct assignment.
  
  r337412:
  libsa: dos_checksum() should take unsigned chars
  
  Fix pointers to integers with different sign issue.
  
  r337413:
  libsa: gzipfs.c converts pointers to integer types with different sign
  
  Signed versus unsigned char.
  
  r337874:
  libsa: zfs_probe() needs to set spa to NULL
  
  Silence the warning about possibly uninitialized use of spa.
  
  r338535:
  libsa: memory leak in tftp_open()
  
  tftpfile is allocated just above and needs to be freed.
  
  r338540:
  libsa: validate tftp_makereq() after we did reset the read
  
  The name check referred in the comment is not the only possible error source,
  we need to validate the result.
  
  r339651:
  libsa: re-send ACK for older data packets in tftp
  
  In current tftp code we drop out-of-order packets; however, we should play
  nice and re-send ACK for older data packets we are receiving. This will
  hopefully stop server repeating those packets we already have received.
  Note we do not answer duplicates from "previous" session (that is, session
  with different port number), those will eventually time out.
  
  r339992:
  libsa: tftp should not read past file end
  
  When we have the file size via tsize option, use it to make sure we
  will not attempt to read past file end.
  
  r339993:
  libsa: tftp should use calloc
  
  instead of malloc() memset(), use calloc().
  
  r340026:
  libsa: cstyle cleanup tftp.c
  
  No functinal changes intended.

Modified:
  stable/11/stand/libsa/bootp.c
  stable/11/stand/libsa/bootp.h
  stable/11/stand/libsa/cd9660.c
  stable/11/stand/libsa/cd9660read.c
  stable/11/stand/libsa/dosfs.c
  stable/11/stand/libsa/gzipfs.c
  stable/11/stand/libsa/net.c
  stable/11/stand/libsa/nfs.c
  stable/11/stand/libsa/tftp.c
  stable/11/stand/libsa/zfs/zfs.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/stand/libsa/bootp.c
==============================================================================
--- stable/11/stand/libsa/bootp.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/bootp.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -735,7 +735,7 @@ setenv_(u_char *cp,  u_char *ep, struct dhcp_opt *opts
 	    bcopy(cp, buf, size);	/* cannot overflow */
 	    buf[size] = '\0';
 	    for (endv = buf; endv; endv = vp) {
-		u_char *s = NULL;	/* semicolon ? */
+		char *s = NULL;	/* semicolon ? */
 
 		/* skip leading whitespace */
 		while (*endv && strchr(" \t\n\r", *endv))

Modified: stable/11/stand/libsa/bootp.h
==============================================================================
--- stable/11/stand/libsa/bootp.h	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/bootp.h	Thu Feb 21 02:43:48 2019	(r344408)
@@ -39,7 +39,7 @@ struct bootp {
 	struct in_addr	bp_giaddr;	/* gateway IP address */
 	unsigned char	bp_chaddr[16];	/* client hardware address */
 	unsigned char	bp_sname[64];	/* server host name */
-	unsigned char	bp_file[128];	/* boot file name */
+	char		bp_file[128];	/* boot file name */
 #ifdef SUPPORT_DHCP
 #define BOOTP_VENDSIZE 312
 #else

Modified: stable/11/stand/libsa/cd9660.c
==============================================================================
--- stable/11/stand/libsa/cd9660.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/cd9660.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -304,7 +304,7 @@ cd9660_open(const char *path, struct open_file *f)
 	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
 		goto out;
 
-	rec = *(struct iso_directory_record *) vd->root_directory_record;
+	bcopy(vd->root_directory_record, &rec, sizeof(rec));
 	if (*path == '/') path++; /* eat leading '/' */
 
 	first = 1;

Modified: stable/11/stand/libsa/cd9660read.c
==============================================================================
--- stable/11/stand/libsa/cd9660read.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/cd9660read.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -241,7 +241,7 @@ cd9660_lookup(const char *path)
 			break;
 	}
 
-	rec = *(struct iso_directory_record *) vd->root_directory_record;
+	bcopy(vd->root_directory_record, &rec, sizeof(rec));
 	if (*path == '/') path++; /* eat leading '/' */
 
 	first = 1;

Modified: stable/11/stand/libsa/dosfs.c
==============================================================================
--- stable/11/stand/libsa/dosfs.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/dosfs.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -403,7 +403,7 @@ dos_stat(struct open_file *fd, struct stat *sb)
 }
 
 static int
-dos_checksum(char *name, char *ext)
+dos_checksum(unsigned char *name, unsigned char *ext)
 {
     int x, i;
     char buf[11];

Modified: stable/11/stand/libsa/gzipfs.c
==============================================================================
--- stable/11/stand/libsa/gzipfs.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/gzipfs.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -40,7 +40,7 @@ struct z_file
     int			zf_rawfd;
     off_t		zf_dataoffset;
     z_stream		zf_zstream;
-    char		zf_buf[Z_BUFSIZE];
+    unsigned char	zf_buf[Z_BUFSIZE];
     int			zf_endseen;
 };
 

Modified: stable/11/stand/libsa/net.c
==============================================================================
--- stable/11/stand/libsa/net.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/net.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -267,7 +267,7 @@ intoa(n_long addr)
 }
 
 static char *
-number(char *s, int *n)
+number(char *s, n_long *n)
 {
 	for (*n = 0; isdigit(*s); s++)
 		*n = (*n * 10) + *s - '0';
@@ -280,7 +280,7 @@ ip_convertaddr(char *p)
 #define IP_ANYADDR	0
 	n_long addr = 0, n;
 
-	if (p == (char *)0 || *p == '\0')
+	if (p == NULL || *p == '\0')
 		return IP_ANYADDR;
 	p = number(p, &n);
 	addr |= (n << 24) & 0xff000000;

Modified: stable/11/stand/libsa/nfs.c
==============================================================================
--- stable/11/stand/libsa/nfs.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/nfs.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -837,7 +837,7 @@ nfs_readdir(struct open_file *f, struct dirent *d)
 	fp->off = cookie = ((uint64_t)ntohl(rent->nameplus[pos]) << 32) |
 	    ntohl(rent->nameplus[pos + 1]);
 	pos += 2;
-	buf = (u_char *)&rent->nameplus[pos];
+	buf = (char *)&rent->nameplus[pos];
 	return (0);
 
 err:

Modified: stable/11/stand/libsa/tftp.c
==============================================================================
--- stable/11/stand/libsa/tftp.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/tftp.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -63,30 +63,29 @@ __FBSDID("$FreeBSD$");
 struct tftp_handle;
 struct tftprecv_extra;
 
-static ssize_t recvtftp(struct iodesc *d, void **pkt, void **payload,
-    time_t tleft, void *recv_extra);
-static int	tftp_open(const char *path, struct open_file *f);
-static int	tftp_close(struct open_file *f);
-static int	tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len);
-static int	tftp_read(struct open_file *f, void *buf, size_t size, size_t *resid);
-static off_t	tftp_seek(struct open_file *f, off_t offset, int where);
-static int	tftp_set_blksize(struct tftp_handle *h, const char *str);
-static int	tftp_stat(struct open_file *f, struct stat *sb);
+static ssize_t recvtftp(struct iodesc *, void **, void **, time_t, void *);
+static int tftp_open(const char *, struct open_file *);
+static int tftp_close(struct open_file *);
+static int tftp_parse_oack(struct tftp_handle *, char *, size_t);
+static int tftp_read(struct open_file *, void *, size_t, size_t *);
+static off_t tftp_seek(struct open_file *, off_t, int);
+static int tftp_set_blksize(struct tftp_handle *, const char *);
+static int tftp_stat(struct open_file *, struct stat *);
 
 struct fs_ops tftp_fsops = {
-	"tftp",
-	tftp_open,
-	tftp_close,
-	tftp_read,
-	null_write,
-	tftp_seek,
-	tftp_stat,
-	null_readdir
+	.fs_name = "tftp",
+	.fo_open = tftp_open,
+	.fo_close = tftp_close,
+	.fo_read = tftp_read,
+	.fo_write = null_write,
+	.fo_seek = tftp_seek,
+	.fo_stat = tftp_stat,
+	.fo_readdir = null_readdir
 };
 
 extern struct in_addr servip;
 
-static int      tftpport = 2000;
+static int	tftpport = 2000;
 static int	is_open = 0;
 
 /*
@@ -94,21 +93,21 @@ static int	is_open = 0;
  * TFTP_REQUESTED_BLKSIZE of 1428 is (Ethernet MTU, less the TFTP, UDP and
  * IP header lengths).
  */
-#define TFTP_REQUESTED_BLKSIZE 1428
+#define	TFTP_REQUESTED_BLKSIZE 1428
 
 /*
  * Choose a blksize big enough so we can test with Ethernet
  * Jumbo frames in the future.
  */
-#define TFTP_MAX_BLKSIZE 9008
+#define	TFTP_MAX_BLKSIZE 9008
 
 struct tftp_handle {
 	struct iodesc  *iodesc;
-	int             currblock;	/* contents of lastdata */
-	int             islastblock;	/* flag */
-	int             validsize;
-	int             off;
-	char           *path;	/* saved for re-requests */
+	int		currblock;	/* contents of lastdata */
+	int		islastblock;	/* flag */
+	int		validsize;
+	int		off;
+	char		*path;	/* saved for re-requests */
 	unsigned int	tftp_blksize;
 	unsigned long	tftp_tsize;
 	void		*pkt;
@@ -117,7 +116,7 @@ struct tftp_handle {
 
 struct tftprecv_extra {
 	struct tftp_handle	*tftp_handle;
-	unsigned short		 rtype;		/* Received type */
+	unsigned short		rtype;		/* Received type */
 };
 
 #define	TFTP_MAX_ERRCODE EOPTNEG
@@ -141,42 +140,42 @@ tftp_senderr(struct tftp_handle *h, u_short errcode, c
 {
 	struct {
 		u_char header[HEADER_SIZE];
-		struct tftphdr  t;
+		struct tftphdr t;
 		u_char space[63]; /* +1 from t */
 	} __packed __aligned(4) wbuf;
-	char           *wtail;
-	int             len;
+	char *wtail;
+	int len;
 
 	len = strlen(msg);
 	if (len > sizeof(wbuf.space))
 		len = sizeof(wbuf.space);
 
-	wbuf.t.th_opcode = htons((u_short) ERROR);
-	wbuf.t.th_code   = htons(errcode);
+	wbuf.t.th_opcode = htons((u_short)ERROR);
+	wbuf.t.th_code = htons(errcode);
 
 	wtail = wbuf.t.th_msg;
 	bcopy(msg, wtail, len);
 	wtail[len] = '\0';
 	wtail += len + 1;
 
-	sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
+	sendudp(h->iodesc, &wbuf.t, wtail - (char *)&wbuf.t);
 }
 
 static void
-tftp_sendack(struct tftp_handle *h)
+tftp_sendack(struct tftp_handle *h, u_short block)
 {
 	struct {
 		u_char header[HEADER_SIZE];
 		struct tftphdr  t;
 	} __packed __aligned(4) wbuf;
-	char           *wtail;
+	char *wtail;
 
-	wbuf.t.th_opcode = htons((u_short) ACK);
-	wtail = (char *) &wbuf.t.th_block;
-	wbuf.t.th_block = htons((u_short) h->currblock);
+	wbuf.t.th_opcode = htons((u_short)ACK);
+	wtail = (char *)&wbuf.t.th_block;
+	wbuf.t.th_block = htons(block);
 	wtail += 2;
 
-	sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
+	sendudp(h->iodesc, &wbuf.t, wtail - (char *)&wbuf.t);
 }
 
 static ssize_t
@@ -190,7 +189,7 @@ recvtftp(struct iodesc *d, void **pkt, void **payload,
 	ssize_t len;
 
 	errno = 0;
-	extra = (struct tftprecv_extra *)recv_extra;
+	extra = recv_extra;
 	h = extra->tftp_handle;
 
 	len = readudp(d, &ptr, (void **)&t, tleft);
@@ -205,28 +204,36 @@ recvtftp(struct iodesc *d, void **pkt, void **payload,
 	case DATA: {
 		int got;
 
-		if (htons(t->th_block) != (u_short) d->xid) {
+		if (htons(t->th_block) < (u_short)d->xid) {
 			/*
-			 * Expected block?
+			 * Apparently our ACK was missed, re-send.
 			 */
+			tftp_sendack(h, htons(t->th_block));
 			free(ptr);
 			return (-1);
 		}
+		if (htons(t->th_block) != (u_short)d->xid) {
+			/*
+			 * Packet from the future, drop this.
+			 */
+			free(ptr);
+			return (-1);
+		}
 		if (d->xid == 1) {
 			/*
 			 * First data packet from new port.
 			 */
 			struct udphdr *uh;
-			uh = (struct udphdr *) t - 1;
+			uh = (struct udphdr *)t - 1;
 			d->destport = uh->uh_sport;
-		} /* else check uh_sport has not changed??? */
+		}
 		got = len - (t->th_data - (char *)t);
 		*pkt = ptr;
 		*payload = t;
 		return (got);
 	}
 	case ERROR:
-		if ((unsigned) ntohs(t->th_code) > TFTP_MAX_ERRCODE) {
+		if ((unsigned)ntohs(t->th_code) > TFTP_MAX_ERRCODE) {
 			printf("illegal tftp error %d\n", ntohs(t->th_code));
 			errno = EIO;
 		} else {
@@ -241,8 +248,8 @@ recvtftp(struct iodesc *d, void **pkt, void **payload,
 		struct udphdr *uh;
 		int tftp_oack_len;
 
-		/* 
-		 * Unexpected OACK. TFTP transfer already in progress. 
+		/*
+		 * Unexpected OACK. TFTP transfer already in progress.
 		 * Drop the pkt.
 		 */
 		if (d->xid != 1) {
@@ -254,9 +261,9 @@ recvtftp(struct iodesc *d, void **pkt, void **payload,
 		 * Remember which port this OACK came from, because we need
 		 * to send the ACK or errors back to it.
 		 */
-		uh = (struct udphdr *) t - 1;
+		uh = (struct udphdr *)t - 1;
 		d->destport = uh->uh_sport;
-		
+
 		/* Parse options ACK-ed by the server. */
 		tftp_oack_len = len - sizeof(t->th_opcode);
 		if (tftp_parse_oack(h, t->th_u.tu_stuff, tftp_oack_len) != 0) {
@@ -288,9 +295,9 @@ tftp_makereq(struct tftp_handle *h)
 		u_char space[FNAME_SIZE + 6];
 	} __packed __aligned(4) wbuf;
 	struct tftprecv_extra recv_extra;
-	char           *wtail;
-	int             l;
-	ssize_t         res;
+	char *wtail;
+	int l;
+	ssize_t res;
 	void *pkt;
 	struct tftphdr *t;
 	char *tftp_blksize = NULL;
@@ -304,7 +311,7 @@ tftp_makereq(struct tftp_handle *h)
 		tftp_set_blksize(h, tftp_blksize);
 	}
 
-	wbuf.t.th_opcode = htons((u_short) RRQ);
+	wbuf.t.th_opcode = htons((u_short)RRQ);
 	wtail = wbuf.t.th_stuff;
 	l = strlen(h->path);
 #ifdef TFTP_PREPEND_PATH
@@ -329,7 +336,6 @@ tftp_makereq(struct tftp_handle *h)
 	bcopy("0", wtail, 2);
 	wtail += 2;
 
-	/* h->iodesc->myport = htons(--tftpport); */
 	h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
 	h->iodesc->destport = htons(IPPORT_TFTP);
 	h->iodesc->xid = 1;	/* expected block */
@@ -340,8 +346,8 @@ tftp_makereq(struct tftp_handle *h)
 
 	pkt = NULL;
 	recv_extra.tftp_handle = h;
-	res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
-		       (void *)&recvtftp, &pkt, (void **)&t, &recv_extra);
+	res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *)&wbuf.t,
+	    &recvtftp, &pkt, (void **)&t, &recv_extra);
 	if (res == -1) {
 		free(pkt);
 		return (errno);
@@ -364,7 +370,7 @@ tftp_makereq(struct tftp_handle *h)
 			h->islastblock = 0;
 			if (res < h->tftp_blksize) {
 				h->islastblock = 1;	/* very short file */
-				tftp_sendack(h);
+				tftp_sendack(h, h->currblock);
 			}
 			return (0);
 		}
@@ -376,7 +382,7 @@ tftp_makereq(struct tftp_handle *h)
 }
 
 /* ack block, expect next */
-static int 
+static int
 tftp_getnextblock(struct tftp_handle *h)
 {
 	struct {
@@ -384,21 +390,22 @@ tftp_getnextblock(struct tftp_handle *h)
 		struct tftphdr t;
 	} __packed __aligned(4) wbuf;
 	struct tftprecv_extra recv_extra;
-	char           *wtail;
-	int             res;
+	char *wtail;
+	int res;
 	void *pkt;
 	struct tftphdr *t;
-	wbuf.t.th_opcode = htons((u_short) ACK);
-	wtail = (char *) &wbuf.t.th_block;
-	wbuf.t.th_block = htons((u_short) h->currblock);
+
+	wbuf.t.th_opcode = htons((u_short)ACK);
+	wtail = (char *)&wbuf.t.th_block;
+	wbuf.t.th_block = htons((u_short)h->currblock);
 	wtail += 2;
 
 	h->iodesc->xid = h->currblock + 1;	/* expected block */
 
 	pkt = NULL;
 	recv_extra.tftp_handle = h;
-	res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
-		       (void *)&recvtftp, &pkt, (void **)&t, &recv_extra);
+	res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *)&wbuf.t,
+	    &recvtftp, &pkt, (void **)&t, &recv_extra);
 
 	if (res == -1) {		/* 0 is OK! */
 		free(pkt);
@@ -414,8 +421,8 @@ tftp_getnextblock(struct tftp_handle *h)
 		h->islastblock = 1;	/* EOF */
 
 	if (h->islastblock == 1) {
-		/* Send an ACK for the last block */ 
-		wbuf.t.th_block = htons((u_short) h->currblock);
+		/* Send an ACK for the last block */
+		wbuf.t.th_block = htons((u_short)h->currblock);
 		sendudp(h->iodesc, &wbuf.t, wtail - (char *)&wbuf.t);
 	}
 
@@ -426,10 +433,10 @@ static int
 tftp_open(const char *path, struct open_file *f)
 {
 	struct tftp_handle *tftpfile;
-	struct iodesc  *io;
-	int             res;
-	size_t          pathsize;
-	const char     *extraslash;
+	struct iodesc	*io;
+	int		res;
+	size_t		pathsize;
+	const char	*extraslash;
 
 	if (netproto != NET_TFTP)
 		return (EINVAL);
@@ -440,15 +447,16 @@ tftp_open(const char *path, struct open_file *f)
 	if (is_open)
 		return (EBUSY);
 
-	tftpfile = (struct tftp_handle *) malloc(sizeof(*tftpfile));
+	tftpfile = calloc(1, sizeof(*tftpfile));
 	if (!tftpfile)
 		return (ENOMEM);
 
-	memset(tftpfile, 0, sizeof(*tftpfile));
 	tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE;
-	tftpfile->iodesc = io = socktodesc(*(int *) (f->f_devdata));
-	if (io == NULL)
+	tftpfile->iodesc = io = socktodesc(*(int *)(f->f_devdata));
+	if (io == NULL) {
+		free(tftpfile);
 		return (EINVAL);
+	}
 
 	io->destip = servip;
 	tftpfile->off = 0;
@@ -456,7 +464,7 @@ tftp_open(const char *path, struct open_file *f)
 	tftpfile->path = malloc(pathsize);
 	if (tftpfile->path == NULL) {
 		free(tftpfile);
-		return(ENOMEM);
+		return (ENOMEM);
 	}
 	if (rootpath[strlen(rootpath) - 1] == '/' || path[0] == '/')
 		extraslash = "";
@@ -467,7 +475,7 @@ tftp_open(const char *path, struct open_file *f)
 	if (res < 0 || res > pathsize) {
 		free(tftpfile->path);
 		free(tftpfile);
-		return(ENOMEM);
+		return (ENOMEM);
 	}
 
 	res = tftp_makereq(tftpfile);
@@ -478,7 +486,7 @@ tftp_open(const char *path, struct open_file *f)
 		free(tftpfile);
 		return (res);
 	}
-	f->f_fsdata = (void *) tftpfile;
+	f->f_fsdata = tftpfile;
 	is_open = 1;
 	return (0);
 }
@@ -488,8 +496,19 @@ tftp_read(struct open_file *f, void *addr, size_t size
     size_t *resid /* out */)
 {
 	struct tftp_handle *tftpfile;
-	tftpfile = (struct tftp_handle *) f->f_fsdata;
+	size_t res;
+	int rc;
 
+	rc = 0;
+	res = size;
+	tftpfile = f->f_fsdata;
+
+	/* Make sure we will not read past file end */
+	if (tftpfile->tftp_tsize > 0 &&
+	    tftpfile->off + size > tftpfile->tftp_tsize) {
+		size = tftpfile->tftp_tsize - tftpfile->off;
+	}
+
 	while (size > 0) {
 		int needblock, count;
 
@@ -499,19 +518,19 @@ tftp_read(struct open_file *f, void *addr, size_t size
 
 		if (tftpfile->currblock > needblock) {	/* seek backwards */
 			tftp_senderr(tftpfile, 0, "No error: read aborted");
-			tftp_makereq(tftpfile);	/* no error check, it worked
-						 * for open */
+			rc = tftp_makereq(tftpfile);
+			if (rc != 0)
+				break;
 		}
 
 		while (tftpfile->currblock < needblock) {
-			int res;
 
-			res = tftp_getnextblock(tftpfile);
-			if (res) {	/* no answer */
+			rc = tftp_getnextblock(tftpfile);
+			if (rc) {	/* no answer */
 #ifdef TFTP_DEBUG
 				printf("tftp: read error\n");
 #endif
-				return (res);
+				return (rc);
 			}
 			if (tftpfile->islastblock)
 				break;
@@ -537,6 +556,7 @@ tftp_read(struct open_file *f, void *addr, size_t size
 			addr = (char *)addr + count;
 			tftpfile->off += count;
 			size -= count;
+			res -= count;
 
 			if ((tftpfile->islastblock) && (count == inbuffer))
 				break;	/* EOF */
@@ -549,16 +569,16 @@ tftp_read(struct open_file *f, void *addr, size_t size
 
 	}
 
-	if (resid)
-		*resid = size;
-	return (0);
+	if (resid != NULL)
+		*resid = res;
+	return (rc);
 }
 
-static int 
+static int
 tftp_close(struct open_file *f)
 {
 	struct tftp_handle *tftpfile;
-	tftpfile = (struct tftp_handle *) f->f_fsdata;
+	tftpfile = f->f_fsdata;
 
 	/* let it time out ... */
 
@@ -571,17 +591,17 @@ tftp_close(struct open_file *f)
 	return (0);
 }
 
-static int 
+static int
 tftp_stat(struct open_file *f, struct stat *sb)
 {
 	struct tftp_handle *tftpfile;
-	tftpfile = (struct tftp_handle *) f->f_fsdata;
+	tftpfile = f->f_fsdata;
 
 	sb->st_mode = 0444 | S_IFREG;
 	sb->st_nlink = 1;
 	sb->st_uid = 0;
 	sb->st_gid = 0;
-	sb->st_size = (off_t) tftpfile->tftp_tsize;
+	sb->st_size = tftpfile->tftp_tsize;
 	return (0);
 }
 
@@ -589,7 +609,7 @@ static off_t
 tftp_seek(struct open_file *f, off_t offset, int where)
 {
 	struct tftp_handle *tftpfile;
-	tftpfile = (struct tftp_handle *) f->f_fsdata;
+	tftpfile = f->f_fsdata;
 
 	switch (where) {
 	case SEEK_SET:
@@ -608,7 +628,7 @@ tftp_seek(struct open_file *f, off_t offset, int where
 static int
 tftp_set_blksize(struct tftp_handle *h, const char *str)
 {
-        char *endptr;
+	char *endptr;
 	int new_blksize;
 	int ret = 0;
 
@@ -623,8 +643,8 @@ tftp_set_blksize(struct tftp_handle *h, const char *st
 	 * RFC2348 specifies that acceptable values are 8-65464.
 	 * Let's choose a limit less than MAXRSPACE.
 	 */
-	if (*endptr == '\0' && new_blksize >= 8
-	    && new_blksize <= TFTP_MAX_BLKSIZE) {
+	if (*endptr == '\0' && new_blksize >= 8 &&
+	    new_blksize <= TFTP_MAX_BLKSIZE) {
 		h->tftp_blksize = new_blksize;
 		ret = 1;
 	}
@@ -655,10 +675,10 @@ tftp_set_blksize(struct tftp_handle *h, const char *st
  *    optN, valueN
  *       The final option/value acknowledgment pair.
  */
-static int 
+static int
 tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
 {
-	/* 
+	/*
 	 *  We parse the OACK strings into an array
 	 *  of name-value pairs.
 	 */
@@ -668,7 +688,7 @@ tftp_parse_oack(struct tftp_handle *h, char *buf, size
 	int option_idx = 0;
 	int blksize_is_set = 0;
 	int tsize = 0;
-	
+
 	unsigned int orig_blksize;
 
 	while (option_idx < 128 && i < len) {
@@ -685,26 +705,30 @@ tftp_parse_oack(struct tftp_handle *h, char *buf, size
 	/* Save the block size we requested for sanity check later. */
 	orig_blksize = h->tftp_blksize;
 
-	/* 
+	/*
 	 * Parse individual TFTP options.
 	 *    * "blksize" is specified in RFC2348.
 	 *    * "tsize" is specified in RFC2349.
-	 */ 
+	 */
 	for (i = 0; i < option_idx; i += 2) {
-	    if (strcasecmp(tftp_options[i], "blksize") == 0) {
-		if (i + 1 < option_idx)
-			blksize_is_set =
-			    tftp_set_blksize(h, tftp_options[i + 1]);
-	    } else if (strcasecmp(tftp_options[i], "tsize") == 0) {
-		if (i + 1 < option_idx)
-			tsize = strtol(tftp_options[i + 1], (char **)NULL, 10);
-		if (tsize != 0)
-			h->tftp_tsize = tsize;
-	    } else {
-		/* Do not allow any options we did not expect to be ACKed. */
-		printf("unexpected tftp option '%s'\n", tftp_options[i]);
-		return (-1);
-	    }
+		if (strcasecmp(tftp_options[i], "blksize") == 0) {
+			if (i + 1 < option_idx)
+				blksize_is_set =
+				    tftp_set_blksize(h, tftp_options[i + 1]);
+		} else if (strcasecmp(tftp_options[i], "tsize") == 0) {
+			if (i + 1 < option_idx)
+				tsize = strtol(tftp_options[i + 1], NULL, 10);
+			if (tsize != 0)
+				h->tftp_tsize = tsize;
+		} else {
+			/*
+			 * Do not allow any options we did not expect to be
+			 * ACKed.
+			 */
+			printf("unexpected tftp option '%s'\n",
+			    tftp_options[i]);
+			return (-1);
+		}
 	}
 
 	if (!blksize_is_set) {
@@ -726,5 +750,5 @@ tftp_parse_oack(struct tftp_handle *h, char *buf, size
 	printf("tftp_blksize: %u\n", h->tftp_blksize);
 	printf("tftp_tsize: %lu\n", h->tftp_tsize);
 #endif
-	return 0;
+	return (0);
 }

Modified: stable/11/stand/libsa/zfs/zfs.c
==============================================================================
--- stable/11/stand/libsa/zfs/zfs.c	Thu Feb 21 02:41:57 2019	(r344407)
+++ stable/11/stand/libsa/zfs/zfs.c	Thu Feb 21 02:43:48 2019	(r344408)
@@ -467,6 +467,7 @@ zfs_probe(int fd, uint64_t *pool_guid)
 	spa_t *spa;
 	int ret;
 
+	spa = NULL;
 	ret = vdev_probe(vdev_read, (void *)(uintptr_t)fd, &spa);
 	if (ret == 0 && pool_guid != NULL)
 		*pool_guid = spa->spa_guid;


More information about the svn-src-stable mailing list