rongqing.li at windriver.com
2013-Sep-03 07:02 UTC
[syslinux] [PATCH v2] tftp-hpa: add error check for disk filled up
From: "Roy.Li" <rongqing.li at windriver.com> Add error check when write file, the caller can detect if the disk filled up (or had an i/o error) and return a NOSAPCE nak to the other side. Signed-off-by: Ming Liu <ming.liu at windriver.com> Signed-off-by: Roy.Li <rongqing.li at windriver.com> --- common/tftpsubs.c | 4 +++- tftpd/tftpd.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/tftpsubs.c b/common/tftpsubs.c index 8c999f6..172776c 100644 --- a/common/tftpsubs.c +++ b/common/tftpsubs.c @@ -215,7 +215,9 @@ int write_behind(FILE * file, int convert) goto skipit; /* just skip over the putc */ /* else just fall through and allow it */ } - putc(c, file); + if (putc(c, file) == EOF) { + return -1; + } skipit: prevchar = c; } diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 1873e70..c2adbda 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -1681,7 +1681,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac syslog(LOG_WARNING, "tftpd: write(ack): %m"); goto abort; } - write_behind(file, pf->f_convert); + if(write_behind(file, pf->f_convert) < 0) { + nak(ENOSPACE, NULL); + (void)fclose(file); + goto abort; + } for (;;) { n = recv_time(peer, dp, PKTSIZE, 0, &r_timeout); if (n < 0) { /* really? */ @@ -1712,7 +1716,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac goto abort; } } while (size == segsize); - write_behind(file, pf->f_convert); + if(write_behind(file, pf->f_convert) < 0) { + nak(ENOSPACE, NULL); + (void)fclose(file); + goto abort; + } (void)fclose(file); /* close data file */ ap->th_opcode = htons((u_short) ACK); /* send the "final" ack */ -- 1.7.10.4
H. Peter Anvin
2013-Sep-04 03:49 UTC
[syslinux] [PATCH v2] tftp-hpa: add error check for disk filled up
On 09/03/2013 12:02 AM, rongqing.li at windriver.com wrote:> diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c > index 1873e70..c2adbda 100644 > --- a/tftpd/tftpd.c > +++ b/tftpd/tftpd.c > @@ -1681,7 +1681,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac > syslog(LOG_WARNING, "tftpd: write(ack): %m"); > goto abort; > } > - write_behind(file, pf->f_convert); > + if(write_behind(file, pf->f_convert) < 0) { > + nak(ENOSPACE, NULL); > + (void)fclose(file); > + goto abort; > + } > for (;;) { > n = recv_time(peer, dp, PKTSIZE, 0, &r_timeout); > if (n < 0) { /* really? */ > @@ -1712,7 +1716,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac > goto abort; > } > } while (size == segsize); > - write_behind(file, pf->f_convert); > + if(write_behind(file, pf->f_convert) < 0) { > + nak(ENOSPACE, NULL); > + (void)fclose(file); > + goto abort; > + } > (void)fclose(file); /* close data file */ > > ap->th_opcode = htons((u_short) ACK); /* send the "final" ack */ >For the terminal block, you *have* to call fflush(), then check ferror(), before sending the ACK. Also, you are sending ENOSPACE without actually considering other error conditions... not that it is all that essential. Passing NULL in as the human error string is also a bit obnoxious. -hpa
Reasonably Related Threads
- [PATCH] tftp-hpa: add error check for disk filled up
- [PATCH tftpd-hpa] tftpd: don't use AI_CANONNAME and AI_ADDRCONFIG to resolve addresses for bind
- Bug#771441: [PATCH tftpd-hpa] tftpd: don't use AI_CANONNAME and AI_ADDRCONFIG to resolve addresses for bind
- Bug#771441: [PATCH tftpd-hpa] tftpd: don't use AI_CANONNAME and AI_ADDRCONFIG to resolve addresses for bind
- failure when trying to build on OpenBSD 2.8