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