blob: 6b8ceaaeba08faae4827f2718e56437e6ba70b12 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001Patch originally from Fedora
2
3http://pkgs.fedoraproject.org/cgit/tftp.git/
4
5Upstream-Status: Pending
6
7diff -up tftp-hpa-0.49/config.h.cmd_arg tftp-hpa-0.49/config.h
8--- tftp-hpa-0.49/config.h.cmd_arg 2010-04-19 15:29:10.567331454 +0200
9+++ tftp-hpa-0.49/config.h 2010-04-20 07:33:03.133232772 +0200
10@@ -291,6 +291,7 @@ typedef int socklen_t;
11 /* Prototypes for libxtra functions */
12
13 void *xmalloc(size_t);
14+void *xrealloc(void *, size_t);
15 char *xstrdup(const char *);
16
17 #ifndef HAVE_BSD_SIGNAL
18diff -up tftp-hpa-0.49/configure.in.cmd_arg tftp-hpa-0.49/configure.in
19--- tftp-hpa-0.49/configure.in.cmd_arg 2008-10-21 00:08:31.000000000 +0200
20+++ tftp-hpa-0.49/configure.in 2010-04-19 11:05:12.387340698 +0200
21@@ -152,6 +152,7 @@ OBJROOT=`pwd`
22
23 XTRA=false
24 PA_SEARCH_LIBS_AND_ADD(xmalloc, iberty)
25+PA_SEARCH_LIBS_AND_ADD(xrealloc, iberty)
26 PA_SEARCH_LIBS_AND_ADD(xstrdup, iberty)
27 PA_SEARCH_LIBS_AND_ADD(bsd_signal, bsd, bsdsignal)
28 PA_SEARCH_LIBS_AND_ADD(getopt_long, getopt, getopt_long)
29diff -up tftp-hpa-0.49/lib/xrealloc.c.cmd_arg tftp-hpa-0.49/lib/xrealloc.c
30--- tftp-hpa-0.49/lib/xrealloc.c.cmd_arg 2010-04-19 11:05:12.387340698 +0200
31+++ tftp-hpa-0.49/lib/xrealloc.c 2010-04-19 11:05:12.387340698 +0200
32@@ -0,0 +1,20 @@
33+/*
34+ * xrealloc.c
35+ *
36+ * Simple error-checking version of realloc()
37+ *
38+ */
39+
40+#include "config.h"
41+
42+void *xrealloc(void *ptr, size_t size)
43+{
44+ void *p = realloc(ptr, size);
45+
46+ if (!p) {
47+ fprintf(stderr, "Out of memory!\n");
48+ exit(128);
49+ }
50+
51+ return p;
52+}
53diff -up tftp-hpa-0.49/tftp/main.c.cmd_arg tftp-hpa-0.49/tftp/main.c
54--- tftp-hpa-0.49/tftp/main.c.cmd_arg 2008-10-21 00:08:31.000000000 +0200
55+++ tftp-hpa-0.49/tftp/main.c 2010-04-19 11:05:12.389329337 +0200
56@@ -89,11 +89,14 @@ int connected;
57 const struct modes *mode;
58 #ifdef WITH_READLINE
59 char *line = NULL;
60+char *remote_pth = NULL;
61 #else
62 char line[LBUFLEN];
63+char remote_pth[LBUFLEN];
64 #endif
65 int margc;
66-char *margv[20];
67+char **margv;
68+int sizeof_margv=0;
69 const char *prompt = "tftp> ";
70 sigjmp_buf toplevel;
71 void intr(int);
72@@ -379,6 +382,10 @@ static void getmoreargs(const char *part
73 free(line);
74 line = NULL;
75 }
76+ if (remote_pth) {
77+ free(remote_pth);
78+ remote_pth = NULL;
79+ }
80 line = xmalloc(len + elen + 1);
81 strcpy(line, partial);
82 strcpy(line + len, eline);
83@@ -535,6 +542,7 @@ void put(int argc, char *argv[])
84 int fd;
85 int n, err;
86 char *cp, *targ;
87+ long dirlen, namelen, lastlen=0;
88
89 if (argc < 2) {
90 getmoreargs("send ", "(file) ");
91@@ -588,9 +596,22 @@ void put(int argc, char *argv[])
92 }
93 /* this assumes the target is a directory */
94 /* on a remote unix system. hmmmm. */
95- cp = strchr(targ, '\0');
96- *cp++ = '/';
97+ dirlen = strlen(targ)+1;
98+#ifdef WITH_READLINE
99+ remote_pth = xmalloc(dirlen+1);
100+#endif
101+ strcpy(remote_pth, targ);
102+ remote_pth[dirlen-1] = '/';
103+ cp = remote_pth + dirlen;
104 for (n = 1; n < argc - 1; n++) {
105+#ifdef WITH_READLINE
106+ namelen = strlen(tail(argv[n])) + 1;
107+ if (namelen > lastlen) {
108+ remote_pth = xrealloc(remote_pth, dirlen + namelen + 1);
109+ cp = remote_pth + dirlen;
110+ lastlen = namelen;
111+ }
112+#endif
113 strcpy(cp, tail(argv[n]));
114 fd = open(argv[n], O_RDONLY | mode->m_openflags);
115 if (fd < 0) {
116@@ -600,9 +621,9 @@ void put(int argc, char *argv[])
117 }
118 if (verbose)
119 printf("putting %s to %s:%s [%s]\n",
120- argv[n], hostname, targ, mode->m_mode);
121+ argv[n], hostname, remote_pth, mode->m_mode);
122 sa_set_port(&peeraddr, port);
123- tftp_sendfile(fd, targ, mode->m_mode);
124+ tftp_sendfile(fd, remote_pth, mode->m_mode);
125 }
126 }
127
128@@ -801,6 +822,10 @@ static void command(void)
129 free(line);
130 line = NULL;
131 }
132+ if (remote_pth) {
133+ free(remote_pth);
134+ remote_pth = NULL;
135+ }
136 line = readline(prompt);
137 if (!line)
138 exit(0); /* EOF */
139@@ -872,7 +897,13 @@ struct cmd *getcmd(char *name)
140 static void makeargv(void)
141 {
142 char *cp;
143- char **argp = margv;
144+ char **argp;
145+
146+ if (!sizeof_margv) {
147+ sizeof_margv = 20;
148+ margv = xmalloc(sizeof_margv * sizeof(char *));
149+ }
150+ argp = margv;
151
152 margc = 0;
153 for (cp = line; *cp;) {
154@@ -882,6 +913,11 @@ static void makeargv(void)
155 break;
156 *argp++ = cp;
157 margc += 1;
158+ if (margc == sizeof_margv) {
159+ sizeof_margv += 20;
160+ margv = xrealloc(margv, sizeof_margv * sizeof(char *));
161+ argp = margv + margc;
162+ }
163 while (*cp != '\0' && !isspace(*cp))
164 cp++;
165 if (*cp == '\0')