Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157590194
D57072.id178137.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D57072.id178137.diff
View Options
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -62,7 +62,6 @@
#include "tftp-options.h"
#include "tftp.h"
-#define MAXLINE (2 * MAXPATHLEN)
#define TIMEOUT 5 /* secs between rexmt's */
typedef struct sockaddr_storage peeraddr;
@@ -72,7 +71,7 @@
static int txrx_error;
static int peer;
-#define MAX_MARGV 20
+#define MAX_MARGV 32
static int margc;
static char *margv[MAX_MARGV];
@@ -106,7 +105,7 @@
static void urihandling(char *URI);
static void getusage(char *);
-static void makeargv(char *line);
+static void makeargv(char *argv0, char *line);
static void putusage(char *);
static void settftpmode(const char *);
@@ -331,18 +330,20 @@
}
freeaddrinfo(res0);
+ free(port);
+ port = strdup(lport);
}
static void
setpeer(int argc, char *argv[])
{
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
if (argc < 2) {
- strcpy(line, "Connect ");
printf("(to) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
- makeargv(line);
+ getline(&line, &sz, stdin);
+ makeargv(argv[0], line);
argc = margc;
argv = margv;
}
@@ -350,10 +351,9 @@
printf("usage: %s [host [port]]\n", argv[0]);
return;
}
- if (argc == 3) {
- port = argv[2];
+ if (argc == 3)
setpeer0(argv[1], argv[2]);
- } else
+ else
setpeer0(argv[1], NULL);
}
@@ -420,17 +420,16 @@
static void
put(int argc, char *argv[])
{
- int fd;
- int n;
- char *cp, *targ, *path;
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
+ int fd, n;
+ char *cp, *targ, *path;
struct stat sb;
if (argc < 2) {
- strcpy(line, "send ");
printf("(file) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
- makeargv(line);
+ getline(&line, &sz, stdin);
+ makeargv(argv[0], line);
argc = margc;
argv = margv;
}
@@ -530,17 +529,15 @@
static void
get(int argc, char *argv[])
{
- int fd;
- int n;
- char *cp;
- char *src;
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
+ int fd, n;
+ char *cp, *src;
if (argc < 2) {
- strcpy(line, "get ");
printf("(files) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
- makeargv(line);
+ getline(&line, &sz, stdin);
+ makeargv(argv[0], line);
argc = margc;
argv = margv;
}
@@ -620,14 +617,14 @@
static void
settimeoutpacket(int argc, char *argv[])
{
+ static char *line;
+ static size_t sz;
int t;
- char line[MAXLINE];
if (argc < 2) {
- strcpy(line, "Packet timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
- makeargv(line);
+ getline(&line, &sz, stdin);
+ makeargv(argv[0], line);
argc = margc;
argv = margv;
}
@@ -647,14 +644,14 @@
static void
settimeoutnetwork(int argc, char *argv[])
{
+ static char *line;
+ static size_t sz;
int t;
- char line[MAXLINE];
if (argc < 2) {
- strcpy(line, "Network timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
- makeargv(line);
+ getline(&line, &sz, stdin);
+ makeargv(argv[0], line);
argc = margc;
argv = margv;
}
@@ -730,23 +727,22 @@
static void
command(bool interactive, EditLine *el, History *hist, HistEvent *hep)
{
+ static char *line;
+ static size_t sz;
const struct cmd *c;
const char *bp;
- char *cp;
- int len, num;
- char line[MAXLINE];
+ int len;
for (;;) {
if (interactive) {
- if ((bp = el_gets(el, &num)) == NULL || num == 0)
+ if ((bp = el_gets(el, &len)) == NULL || len == 0)
exit(0);
- len = MIN(MAXLINE, num);
- memcpy(line, bp, len);
- line[len - 1] = '\0';
- history(hist, hep, H_ENTER, bp);
+ if ((size_t)len >= sz)
+ line = realloc(line, sz = len + 1);
+ strlcpy(line, bp, sz);
+ history(hist, hep, H_ENTER, line);
} else {
- line[0] = 0;
- if (fgets(line, sizeof line , stdin) == NULL) {
+ if ((len = getline(&line, &sz, stdin)) <= 0) {
if (feof(stdin)) {
exit(txrx_error);
} else {
@@ -754,11 +750,11 @@
}
}
}
- if ((cp = strchr(line, '\n')))
- *cp = '\0';
+ if (line[len - 1] == '\n')
+ line[--len] = '\0';
if (line[0] == 0)
continue;
- makeargv(line);
+ makeargv(NULL, line);
if (margc == 0)
continue;
c = getcmd(margv[0]);
@@ -807,12 +803,16 @@
* Slice a string up into argc/argv.
*/
static void
-makeargv(char *line)
+makeargv(char *argv0, char *line)
{
char *cp;
char **argp = margv;
margc = 0;
+ if (argv0 != NULL) {
+ *argp++ = argv0;
+ margc++;
+ }
if ((cp = strchr(line, '\n')) != NULL)
*cp = '\0';
for (cp = line; margc < MAX_MARGV - 1 && *cp != '\0';) {
@@ -821,13 +821,14 @@
if (*cp == '\0')
break;
*argp++ = cp;
- margc += 1;
+ margc++;
while (*cp != '\0' && !isspace(*cp))
cp++;
if (*cp == '\0')
break;
*cp++ = '\0';
}
+ /* XXX warn about truncation if *cp != '\0'? */
*argp++ = 0;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 24, 3:38 AM (13 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33357413
Default Alt Text
D57072.id178137.diff (4 KB)
Attached To
Mode
D57072: tftp: Replace fgets with getline
Attached
Detach File
Event Timeline
Log In to Comment