aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-daemons/tftp-hpa/files/tftp-0.49-cmd_arg.patch
blob: 6b8ceaaeba08faae4827f2718e56437e6ba70b12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Patch originally from Fedora

http://pkgs.fedoraproject.org/cgit/tftp.git/

Upstream-Status: Pending

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