Date: Fri, 22 May 2026 17:58:05 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: a4b175941815 - main - tftp: Simplify URI handling Message-ID: <6a10992d.3a385.1bfa7822@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=a4b17594181502cea38ab0d8b2a9a10782286334 commit a4b17594181502cea38ab0d8b2a9a10782286334 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-05-22 17:57:08 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-05-22 17:57:08 +0000 tftp: Simplify URI handling * No need to copy our argument into a new buffer; it is writeable and will not be reused after we return. * Instead of constructing the string "get path" and then splitting it into an argument vector, just construct the vector directly. This avoid potentially overrunning the buffer. * Call settftpmode() just once, with either the default mode or the user-provided value we already validated. * Use errx() instead of fprintf(stderr) + exit(). Reported by: Moyao, Minghao Fu MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D57070 --- usr.bin/tftp/main.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 8e36c9e04f9b..9b7ea7155d82 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -225,23 +225,18 @@ main(int argc, char *argv[]) static void urihandling(char *URI) { - char uri[ARG_MAX]; + char meth[] = "get"; char *host = NULL; char *path = NULL; char *opts = NULL; const char *tmode = "octet"; char *s; - char line[MAXLINE]; int i; - strlcpy(uri, URI, ARG_MAX); - host = uri + 7; + host = URI + 7; - if ((s = strchr(host, '/')) == NULL) { - fprintf(stderr, - "Invalid URI: Couldn't find / after hostname\n"); - exit(1); - } + if ((s = strchr(host, '/')) == NULL) + errx(1, "Invalid URI: Couldn't find / after hostname"); *s = '\0'; path = s + 1; @@ -253,24 +248,21 @@ urihandling(char *URI) tmode = opts; tmode += 5; - for (i = 0; modes[i].m_name != NULL; i++) { + for (i = 0; modes[i].m_name != NULL; i++) if (strcmp(modes[i].m_name, tmode) == 0) break; - } - if (modes[i].m_name == NULL) { - fprintf(stderr, "Invalid mode: '%s'\n", mode); - exit(1); - } - settftpmode(modes[i].m_mode); + if (modes[i].m_name == NULL) + errx(1, "Invalid mode: '%s'", mode); } - } else { - settftpmode("octet"); } + settftpmode(tmode); setpeer0(host, NULL); - sprintf(line, "get %s", path); - makeargv(line); + margc = 0; + margv[margc++] = meth; + margv[margc++] = path; + margv[margc] = NULL; get(margc, margv); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a10992d.3a385.1bfa7822>
