summaryrefslogtreecommitdiff
path: root/stand
diff options
context:
space:
mode:
authorToomas Soome <tsoome@FreeBSD.org>2018-11-01 13:12:05 +0000
committerToomas Soome <tsoome@FreeBSD.org>2018-11-01 13:12:05 +0000
commitf442898fe7814260868fd16bd22e8a91234485d7 (patch)
treee28ae27a4549457e1c968b5a83aba085b28208f6 /stand
parent6999f6975ced6e706fede653528c9aa80e9ba514 (diff)
Notes
Diffstat (limited to 'stand')
-rw-r--r--stand/libsa/tftp.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c
index 8ef012752f02f..e8b2f14c0ef44 100644
--- a/stand/libsa/tftp.c
+++ b/stand/libsa/tftp.c
@@ -498,11 +498,19 @@ tftp_read(struct open_file *f, void *addr, size_t size,
size_t *resid /* out */)
{
struct tftp_handle *tftpfile;
+ size_t res;
int rc;
rc = 0;
+ res = size;
tftpfile = (struct tftp_handle *) 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;
@@ -550,6 +558,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 */
@@ -562,8 +571,8 @@ tftp_read(struct open_file *f, void *addr, size_t size,
}
- if (resid)
- *resid = size;
+ if (resid != NULL)
+ *resid = res;
return (rc);
}