Message ID | 160505548377.1389938.2367585875193826371.stgit@magnolia (mailing list archive) |
---|---|
State | Accepted, archived |
Headers | show |
Series | xfstests: fix compiler warnings with fsx/fsstress | expand |
On Tue, Nov 10, 2020 at 04:44:43PM -0800, Darrick J. Wong wrote: > From: Darrick J. Wong <darrick.wong@oracle.com> > > We shouldn't feed sizeof() to strncpy as the string length. Just use > snprintf, which at least doesn't have the zero termination problems. Looks good, Reviewed-by: Christoph Hellwig <hch@lst.de>
diff --git a/ltp/fsx.c b/ltp/fsx.c index 0abd7de1..cd0bae55 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -2769,8 +2769,7 @@ main(int argc, char **argv) randomoplen = 0; break; case 'P': - strncpy(dname, optarg, sizeof(dname)); - strcat(dname, "/"); + snprintf(dname, sizeof(dname), "%s/", optarg); dirpath = strlen(dname); break; case 'R': @@ -2799,7 +2798,7 @@ main(int argc, char **argv) break; case 255: /* --record-ops */ if (optarg) - strncpy(opsfile, optarg, sizeof(opsfile)); + snprintf(opsfile, sizeof(opsfile), "%s", optarg); recordops = opsfile; break; case 256: /* --replay-ops */