The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a4b17594181502cea38ab0d8b2a9a10782286334

commit a4b17594181502cea38ab0d8b2a9a10782286334
Author:     Dag-Erling Smørgrav <[email protected]>
AuthorDate: 2026-05-22 17:57:08 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
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);
 }
 

Reply via email to