1 diff -up tftp-hpa-0.49/config.h.cmd_arg tftp-hpa-0.49/config.h
2 --- tftp-hpa-0.49/config.h.cmd_arg 2010-04-19 15:29:10.567331454 +0200
3 +++ tftp-hpa-0.49/config.h 2010-04-20 07:33:03.133232772 +0200
4 @@ -291,6 +291,7 @@ typedef int socklen_t;
5 /* Prototypes for libxtra functions */
8 +void *xrealloc(void *, size_t);
9 char *xstrdup(const char *);
11 #ifndef HAVE_BSD_SIGNAL
12 diff -up tftp-hpa-0.49/configure.in.cmd_arg tftp-hpa-0.49/configure.in
13 --- tftp-hpa-0.49/configure.in.cmd_arg 2008-10-21 00:08:31.000000000 +0200
14 +++ tftp-hpa-0.49/configure.in 2010-04-19 11:05:12.387340698 +0200
15 @@ -152,6 +152,7 @@ OBJROOT=`pwd`
18 PA_SEARCH_LIBS_AND_ADD(xmalloc, iberty)
19 +PA_SEARCH_LIBS_AND_ADD(xrealloc, iberty)
20 PA_SEARCH_LIBS_AND_ADD(xstrdup, iberty)
21 PA_SEARCH_LIBS_AND_ADD(bsd_signal, bsd, bsdsignal)
22 PA_SEARCH_LIBS_AND_ADD(getopt_long, getopt, getopt_long)
23 diff -up tftp-hpa-0.49/lib/xrealloc.c.cmd_arg tftp-hpa-0.49/lib/xrealloc.c
24 --- tftp-hpa-0.49/lib/xrealloc.c.cmd_arg 2010-04-19 11:05:12.387340698 +0200
25 +++ tftp-hpa-0.49/lib/xrealloc.c 2010-04-19 11:05:12.387340698 +0200
30 + * Simple error-checking version of realloc()
36 +void *xrealloc(void *ptr, size_t size)
38 + void *p = realloc(ptr, size);
41 + fprintf(stderr, "Out of memory!\n");
47 diff -up tftp-hpa-0.49/tftp/main.c.cmd_arg tftp-hpa-0.49/tftp/main.c
48 --- tftp-hpa-0.49/tftp/main.c.cmd_arg 2008-10-21 00:08:31.000000000 +0200
49 +++ tftp-hpa-0.49/tftp/main.c 2010-04-19 11:05:12.389329337 +0200
50 @@ -89,11 +89,14 @@ int connected;
51 const struct modes *mode;
54 +char *remote_pth = NULL;
57 +char remote_pth[LBUFLEN];
63 const char *prompt = "tftp> ";
66 @@ -379,6 +382,10 @@ static void getmoreargs(const char *part
74 line = xmalloc(len + elen + 1);
75 strcpy(line, partial);
76 strcpy(line + len, eline);
77 @@ -535,6 +542,7 @@ void put(int argc, char *argv[])
81 + long dirlen, namelen, lastlen=0;
84 getmoreargs("send ", "(file) ");
85 @@ -588,9 +596,22 @@ void put(int argc, char *argv[])
87 /* this assumes the target is a directory */
88 /* on a remote unix system. hmmmm. */
89 - cp = strchr(targ, '\0');
91 + dirlen = strlen(targ)+1;
93 + remote_pth = xmalloc(dirlen+1);
95 + strcpy(remote_pth, targ);
96 + remote_pth[dirlen-1] = '/';
97 + cp = remote_pth + dirlen;
98 for (n = 1; n < argc - 1; n++) {
100 + namelen = strlen(tail(argv[n])) + 1;
101 + if (namelen > lastlen) {
102 + remote_pth = xrealloc(remote_pth, dirlen + namelen + 1);
103 + cp = remote_pth + dirlen;
107 strcpy(cp, tail(argv[n]));
108 fd = open(argv[n], O_RDONLY | mode->m_openflags);
110 @@ -600,9 +621,9 @@ void put(int argc, char *argv[])
113 printf("putting %s to %s:%s [%s]\n",
114 - argv[n], hostname, targ, mode->m_mode);
115 + argv[n], hostname, remote_pth, mode->m_mode);
116 sa_set_port(&peeraddr, port);
117 - tftp_sendfile(fd, targ, mode->m_mode);
118 + tftp_sendfile(fd, remote_pth, mode->m_mode);
122 @@ -801,6 +822,10 @@ static void command(void)
130 line = readline(prompt);
133 @@ -872,7 +897,13 @@ struct cmd *getcmd(char *name)
134 static void makeargv(void)
137 - char **argp = margv;
140 + if (!sizeof_margv) {
142 + margv = xmalloc(sizeof_margv * sizeof(char *));
147 for (cp = line; *cp;) {
148 @@ -882,6 +913,11 @@ static void makeargv(void)
152 + if (margc == sizeof_margv) {
153 + sizeof_margv += 20;
154 + margv = xrealloc(margv, sizeof_margv * sizeof(char *));
155 + argp = margv + margc;
157 while (*cp != '\0' && !isspace(*cp))