clausklein / rpms / tftp

Forked from rpms/tftp 5 years ago
Clone

Blame SOURCES/tftp-0.49-cmd_arg.patch

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