364356
diff -up tftp-hpa-0.49/config.h.cmd_arg tftp-hpa-0.49/config.h
364356
--- tftp-hpa-0.49/config.h.cmd_arg	2010-04-19 15:29:10.567331454 +0200
364356
+++ tftp-hpa-0.49/config.h	2010-04-20 07:33:03.133232772 +0200
364356
@@ -291,6 +291,7 @@ typedef int socklen_t;
364356
 /* Prototypes for libxtra functions */
364356
 
364356
 void *xmalloc(size_t);
364356
+void *xrealloc(void *, size_t);
364356
 char *xstrdup(const char *);
364356
 
364356
 #ifndef HAVE_BSD_SIGNAL
364356
diff -up tftp-hpa-0.49/configure.in.cmd_arg tftp-hpa-0.49/configure.in
364356
--- tftp-hpa-0.49/configure.in.cmd_arg	2008-10-21 00:08:31.000000000 +0200
364356
+++ tftp-hpa-0.49/configure.in	2010-04-19 11:05:12.387340698 +0200
364356
@@ -152,6 +152,7 @@ OBJROOT=`pwd`
364356
 
364356
 XTRA=false
364356
 PA_SEARCH_LIBS_AND_ADD(xmalloc, iberty)
364356
+PA_SEARCH_LIBS_AND_ADD(xrealloc, iberty)
364356
 PA_SEARCH_LIBS_AND_ADD(xstrdup, iberty)
364356
 PA_SEARCH_LIBS_AND_ADD(bsd_signal, bsd, bsdsignal)
364356
 PA_SEARCH_LIBS_AND_ADD(getopt_long, getopt, getopt_long)
364356
diff -up tftp-hpa-0.49/lib/xrealloc.c.cmd_arg tftp-hpa-0.49/lib/xrealloc.c
364356
--- tftp-hpa-0.49/lib/xrealloc.c.cmd_arg	2010-04-19 11:05:12.387340698 +0200
364356
+++ tftp-hpa-0.49/lib/xrealloc.c	2010-04-19 11:05:12.387340698 +0200
364356
@@ -0,0 +1,20 @@
364356
+/*
364356
+ * xrealloc.c
364356
+ *
364356
+ * Simple error-checking version of realloc()
364356
+ *
364356
+ */
364356
+
364356
+#include "config.h"
364356
+
364356
+void *xrealloc(void *ptr, size_t size)
364356
+{
364356
+    void *p = realloc(ptr, size);
364356
+
364356
+    if (!p) {
364356
+        fprintf(stderr, "Out of memory!\n");
364356
+        exit(128);
364356
+    }
364356
+
364356
+    return p;
364356
+}
364356
diff -up tftp-hpa-0.49/tftp/main.c.cmd_arg tftp-hpa-0.49/tftp/main.c
364356
--- tftp-hpa-0.49/tftp/main.c.cmd_arg	2008-10-21 00:08:31.000000000 +0200
364356
+++ tftp-hpa-0.49/tftp/main.c	2010-04-19 11:05:12.389329337 +0200
364356
@@ -89,11 +89,14 @@ int connected;
364356
 const struct modes *mode;
364356
 #ifdef WITH_READLINE
364356
 char *line = NULL;
364356
+char *remote_pth = NULL;
364356
 #else
364356
 char line[LBUFLEN];
364356
+char remote_pth[LBUFLEN];
364356
 #endif
364356
 int margc;
364356
-char *margv[20];
364356
+char **margv;
364356
+int sizeof_margv=0;
364356
 const char *prompt = "tftp> ";
364356
 sigjmp_buf toplevel;
364356
 void intr(int);
364356
@@ -379,6 +382,10 @@ static void getmoreargs(const char *part
364356
         free(line);
364356
         line = NULL;
364356
     }
364356
+    if (remote_pth) {
364356
+        free(remote_pth);
364356
+        remote_pth = NULL;
364356
+    }
364356
     line = xmalloc(len + elen + 1);
364356
     strcpy(line, partial);
364356
     strcpy(line + len, eline);
364356
@@ -535,6 +542,7 @@ void put(int argc, char *argv[])
364356
     int fd;
364356
     int n, err;
364356
     char *cp, *targ;
364356
+    long dirlen, namelen, lastlen=0;
364356
 
364356
     if (argc < 2) {
364356
         getmoreargs("send ", "(file) ");
364356
@@ -588,9 +596,22 @@ void put(int argc, char *argv[])
364356
     }
364356
     /* this assumes the target is a directory */
364356
     /* on a remote unix system.  hmmmm.  */
364356
-    cp = strchr(targ, '\0');
364356
-    *cp++ = '/';
364356
+    dirlen = strlen(targ)+1;
364356
+#ifdef WITH_READLINE
364356
+    remote_pth = xmalloc(dirlen+1);
364356
+#endif
364356
+    strcpy(remote_pth, targ);
364356
+    remote_pth[dirlen-1] = '/';
364356
+    cp = remote_pth + dirlen;
364356
     for (n = 1; n < argc - 1; n++) {
364356
+#ifdef WITH_READLINE
364356
+        namelen = strlen(tail(argv[n])) + 1;
364356
+        if (namelen > lastlen) {
364356
+            remote_pth = xrealloc(remote_pth, dirlen + namelen + 1);
364356
+            cp = remote_pth + dirlen;
364356
+            lastlen = namelen;
364356
+        }
364356
+#endif
364356
         strcpy(cp, tail(argv[n]));
364356
         fd = open(argv[n], O_RDONLY | mode->m_openflags);
364356
         if (fd < 0) {
364356
@@ -600,9 +621,9 @@ void put(int argc, char *argv[])
364356
         }
364356
         if (verbose)
364356
             printf("putting %s to %s:%s [%s]\n",
364356
-                   argv[n], hostname, targ, mode->m_mode);
364356
+                   argv[n], hostname, remote_pth, mode->m_mode);
364356
         sa_set_port(&peeraddr, port);
364356
-        tftp_sendfile(fd, targ, mode->m_mode);
364356
+        tftp_sendfile(fd, remote_pth, mode->m_mode);
364356
     }
364356
 }
364356
 
364356
@@ -801,6 +822,10 @@ static void command(void)
364356
             free(line);
364356
             line = NULL;
364356
         }
364356
+        if (remote_pth) {
364356
+            free(remote_pth);
364356
+            remote_pth = NULL;
364356
+        }
364356
         line = readline(prompt);
364356
         if (!line)
364356
             exit(0);            /* EOF */
364356
@@ -872,7 +897,13 @@ struct cmd *getcmd(char *name)
364356
 static void makeargv(void)
364356
 {
364356
     char *cp;
364356
-    char **argp = margv;
364356
+    char **argp;
364356
+
364356
+    if (!sizeof_margv) {
364356
+        sizeof_margv = 20;
364356
+        margv = xmalloc(sizeof_margv * sizeof(char *));
364356
+    }
364356
+    argp = margv;
364356
 
364356
     margc = 0;
364356
     for (cp = line; *cp;) {
364356
@@ -882,6 +913,11 @@ static void makeargv(void)
364356
             break;
364356
         *argp++ = cp;
364356
         margc += 1;
364356
+        if (margc == sizeof_margv) {
364356
+            sizeof_margv += 20;
364356
+            margv = xrealloc(margv, sizeof_margv * sizeof(char *));
364356
+            argp = margv + margc;
364356
+        }
364356
         while (*cp != '\0' && !isspace(*cp))
364356
             cp++;
364356
         if (*cp == '\0')