commit 16f1f3bfff8671ebbfd9b69928b9427a7fe1fc8a from: Omar Polo date: Fri Jan 21 16:18:52 2022 UTC ftp: truncate the file in woc_file The idea behind woc_file is to create or open a file, but it's always used for writing fresh new content, so it's actually an error that it opens a file for writing without truncating it too. It means that if we write less content than what the file already has, we kepp garbage at the end. This adds an extra argument in send_fid (that is actually used only from woc_file now) so that we can pass KOTRUNC for do_open. commit - 5fe03b5c1758571edfaaa4bef8ebb82245f40618 commit + 16f1f3bfff8671ebbfd9b69928b9427a7fe1fc8a blob - a5ce0072cfc9c598421c1e381b458e6994f63d4b blob + c6d43653826cba945951b69e51ca1d0b9013d135 --- kamiftp/ftp.c +++ kamiftp/ftp.c @@ -728,7 +728,7 @@ fetch_fid(int fid, int fd, const char *name) } static void -send_fid(int fid, const char *fnam, int fd, const char *name) +send_fid(int fid, const char *fnam, int open_flags, int fd, const char *name) { struct progress p = {0}; struct stat sb; @@ -742,7 +742,7 @@ send_fid(int fid, const char *fnam, int fd, const char if (fnam != NULL) do_create(fid, fnam, 0644, KOWRITE); else - do_open(fid, KOWRITE); + do_open(fid, open_flags | KOWRITE); p.max = sb.st_size; for (;;) { @@ -831,7 +831,7 @@ woc_file(int fd, const char *prompt, const char *path) return -1; } - send_fid(nfid, n, fd, prompt); + send_fid(nfid, n, KOTRUNC, fd, prompt); return 0; }