clausklein / rpms / tftp

Forked from rpms/tftp 5 years ago
Clone

Blame SOURCES/tftp-0.49-cmd_arg.patch

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