summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2022-09-05 10:56:58 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-09-13 13:05:09 +0200
commitfc0afbfc7d1a49078563cc0588f342a9b7ea587c (patch)
treee8863b356220ebc224916e283a6912ab55f28573 /fs
parent84c2f0cd45a6dff23845a6cf2a5a6798d792eec7 (diff)
downloadbarebox-fc0afbfc7d1a49078563cc0588f342a9b7ea587c.tar.gz
tftp: make read() fail in error case
when tftp transfer goes in error state e.g. due to error packets sent from the server or (unexpected) internal problems, let the read() fail instead of ignoring these errors silently and corrupting the output. Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220905085658.3854939-4-enrico.scholz@sigma-chemnitz.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/tftp.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fs/tftp.c b/fs/tftp.c
index ada6ad08de..e0886c49d2 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -1017,7 +1017,7 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
{
struct file_priv *priv = f->priv;
size_t outsize = 0, now;
- int ret;
+ int ret = 0;
pr_vdebug("%s %zu\n", __func__, insize);
@@ -1026,8 +1026,11 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
outsize += now;
buf += now;
insize -= now;
- if (priv->state == STATE_DONE)
- return outsize;
+
+ if (priv->state == STATE_DONE) {
+ ret = priv->err;
+ break;
+ }
/* send the ACK only when fifo has been nearly depleted; else,
when tftp_read() is called with small 'insize' values, it
@@ -1041,9 +1044,12 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
if (ret == TFTP_ERR_RESEND)
tftp_send(priv);
if (ret < 0)
- return ret;
+ break;
}
+ if (ret < 0)
+ return ret;
+
return outsize;
}