[syslinux] [PATCH v2] tftp-hpa: add error check for disk filled up

rongqing.li at windriver.com rongqing.li at windriver.com
Tue Sep 3 00:02:49 PDT 2013


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



More information about the Syslinux mailing list