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