More tftp improvements
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 7 Jan 2017 07:33:47 +0000 (08:33 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 7 Jan 2017 07:33:47 +0000 (08:33 +0100)
tftp.c

diff --git a/tftp.c b/tftp.c
index 689bd9d80e3e0f605dfb22bc5781b0f9609997a1..f5ad35a75c996c7bf8c6d61e7bd69e614fae9d22 100644 (file)
--- a/tftp.c
+++ b/tftp.c
@@ -240,6 +240,7 @@ static ssize_t tftp_sendto(int sock, char *pkt, size_t len,
        switch (pkt_num(pkt)) {
                case RRQ:
                case WRQ:
+               case OACK:
                        len = pkt_xrqlen(pkt);
                        break;
                case DATA:
@@ -310,7 +311,7 @@ int tftp_put(struct nmrpd_args *args)
        int fd, sock, ret, timeout, errors, ackblock;
        char rx[2048], tx[2048];
        const char *file_remote = args->file_remote;
-       char *p;
+       char *val, *end;
 
        sock = -1;
        ret = -1;
@@ -384,8 +385,13 @@ int tftp_put(struct nmrpd_args *args)
                                ackblock = pkt_num(rx + 2);
                        } else if (op == OACK) {
                                ackblock = 0;
-                               if ((p = pkt_optval(rx, "blksize"))) {
-                                       blksize = atoi(p);
+                               if ((val = pkt_optval(rx, "blksize"))) {
+                                       blksize = strtol(val, &end, 10);
+                                       if (!blksize || (*end != '\0')) {
+                                               fprintf(stderr, "Error: invalid blksize in OACK: %s\n", val);
+                                               ret = -1;
+                                               goto cleanup;
+                                       }
                                }
                        }
                }