]>
Commit | Line | Data |
---|---|---|
5a0e9616 SS |
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 */ | |
6 | ||
7 | void *xmalloc(size_t); | |
8 | +void *xrealloc(void *, size_t); | |
9 | char *xstrdup(const char *); | |
10 | ||
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` | |
16 | ||
17 | XTRA=false | |
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 | |
26 | @@ -0,0 +1,20 @@ | |
27 | +/* | |
28 | + * xrealloc.c | |
29 | + * | |
30 | + * Simple error-checking version of realloc() | |
31 | + * | |
32 | + */ | |
33 | + | |
34 | +#include "config.h" | |
35 | + | |
36 | +void *xrealloc(void *ptr, size_t size) | |
37 | +{ | |
38 | + void *p = realloc(ptr, size); | |
39 | + | |
40 | + if (!p) { | |
41 | + fprintf(stderr, "Out of memory!\n"); | |
42 | + exit(128); | |
43 | + } | |
44 | + | |
45 | + return p; | |
46 | +} | |
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; | |
52 | #ifdef WITH_READLINE | |
53 | char *line = NULL; | |
54 | +char *remote_pth = NULL; | |
55 | #else | |
56 | char line[LBUFLEN]; | |
57 | +char remote_pth[LBUFLEN]; | |
58 | #endif | |
59 | int margc; | |
60 | -char *margv[20]; | |
61 | +char **margv; | |
62 | +int sizeof_margv=0; | |
63 | const char *prompt = "tftp> "; | |
64 | sigjmp_buf toplevel; | |
65 | void intr(int); | |
66 | @@ -379,6 +382,10 @@ static void getmoreargs(const char *part | |
67 | free(line); | |
68 | line = NULL; | |
69 | } | |
70 | + if (remote_pth) { | |
71 | + free(remote_pth); | |
72 | + remote_pth = NULL; | |
73 | + } | |
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[]) | |
78 | int fd; | |
79 | int n, err; | |
80 | char *cp, *targ; | |
81 | + long dirlen, namelen, lastlen=0; | |
82 | ||
83 | if (argc < 2) { | |
84 | getmoreargs("send ", "(file) "); | |
85 | @@ -588,9 +596,22 @@ void put(int argc, char *argv[]) | |
86 | } | |
87 | /* this assumes the target is a directory */ | |
88 | /* on a remote unix system. hmmmm. */ | |
89 | - cp = strchr(targ, '\0'); | |
90 | - *cp++ = '/'; | |
91 | + dirlen = strlen(targ)+1; | |
92 | +#ifdef WITH_READLINE | |
93 | + remote_pth = xmalloc(dirlen+1); | |
94 | +#endif | |
95 | + strcpy(remote_pth, targ); | |
96 | + remote_pth[dirlen-1] = '/'; | |
97 | + cp = remote_pth + dirlen; | |
98 | for (n = 1; n < argc - 1; n++) { | |
99 | +#ifdef WITH_READLINE | |
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; | |
104 | + lastlen = namelen; | |
105 | + } | |
106 | +#endif | |
107 | strcpy(cp, tail(argv[n])); | |
108 | fd = open(argv[n], O_RDONLY | mode->m_openflags); | |
109 | if (fd < 0) { | |
110 | @@ -600,9 +621,9 @@ void put(int argc, char *argv[]) | |
111 | } | |
112 | if (verbose) | |
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); | |
119 | } | |
120 | } | |
121 | ||
122 | @@ -801,6 +822,10 @@ static void command(void) | |
123 | free(line); | |
124 | line = NULL; | |
125 | } | |
126 | + if (remote_pth) { | |
127 | + free(remote_pth); | |
128 | + remote_pth = NULL; | |
129 | + } | |
130 | line = readline(prompt); | |
131 | if (!line) | |
132 | exit(0); /* EOF */ | |
133 | @@ -872,7 +897,13 @@ struct cmd *getcmd(char *name) | |
134 | static void makeargv(void) | |
135 | { | |
136 | char *cp; | |
137 | - char **argp = margv; | |
138 | + char **argp; | |
139 | + | |
140 | + if (!sizeof_margv) { | |
141 | + sizeof_margv = 20; | |
142 | + margv = xmalloc(sizeof_margv * sizeof(char *)); | |
143 | + } | |
144 | + argp = margv; | |
145 | ||
146 | margc = 0; | |
147 | for (cp = line; *cp;) { | |
148 | @@ -882,6 +913,11 @@ static void makeargv(void) | |
149 | break; | |
150 | *argp++ = cp; | |
151 | margc += 1; | |
152 | + if (margc == sizeof_margv) { | |
153 | + sizeof_margv += 20; | |
154 | + margv = xrealloc(margv, sizeof_margv * sizeof(char *)); | |
155 | + argp = margv + margc; | |
156 | + } | |
157 | while (*cp != '\0' && !isspace(*cp)) | |
158 | cp++; | |
159 | if (*cp == '\0') |