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 @@ -507,10 +507,10 @@ } /* this assumes the target is a directory */ /* on a remote unix system. hmmmm. */ - cp = strchr(targ, '\0'); - *cp++ = '/'; for (n = 1; n < argc - 1; n++) { - strcpy(cp, tail(argv[n])); + if (asprintf(&targ, "%s/%s", argv[argc-1], tail(argv[n])) < 0) + err(1, "malloc"); + fd = open(argv[n], O_RDONLY); if (fd < 0) { warn("%s", argv[n]); @@ -519,6 +519,7 @@ if (fstat(fd, &sb) < 0) { warn("%s", argv[n]); + close(fd); continue; } asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); @@ -527,6 +528,9 @@ printf("putting %s to %s:%s [%s]\n", argv[n], hostname, targ, mode); xmitfile(peer, port, fd, targ, mode); + close(fd); + + free(targ); } }