Date: Thu, 14 Mar 2019 12:25:16 +0000 (UTC) From: Eugene Grosbein <eugen@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345130 - head/usr.sbin/trim Message-ID: <201903141225.x2ECPGI3042548@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eugen Date: Thu Mar 14 12:25:16 2019 New Revision: 345130 URL: https://svnweb.freebsd.org/changeset/base/345130 Log: trim(8): add another safety net It is quite easy make a mistake and run something like this: trim -f /dev/da0 -r rfile This would trim the whole device then emit an error on non-existing file -r. Add another check to prevent this while allowing this form still for real object names beginning from dash: trim -f -- /dev/da0 -r rfile MFC after: 1 week Modified: head/usr.sbin/trim/trim.c Modified: head/usr.sbin/trim/trim.c ============================================================================== --- head/usr.sbin/trim/trim.c Thu Mar 14 10:06:46 2019 (r345129) +++ head/usr.sbin/trim/trim.c Thu Mar 14 12:25:16 2019 (r345130) @@ -40,6 +40,7 @@ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sysexits.h> #include <unistd.h> @@ -103,6 +104,23 @@ main(int argc, char **argv) usage(name); /* NOTREACHED */ } + + /* + * Safety net: do not allow mistakes like + * + * trim -f /dev/da0 -r rfile + * + * This would trim whole device then error on non-existing file -r. + * Following check prevents this while allowing this form still: + * + * trim -f -- /dev/da0 -r rfile + */ + + if (strcmp(argv[optind-1], "--") != 0) { + for (ch = optind; ch < argc; ch++) + if (argv[ch][0] == '-') + usage(name); + } argv += optind; argc -= optind;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903141225.x2ECPGI3042548>