summaryrefslogtreecommitdiffstats
path: root/bin/sh/options.h
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-10-26 17:50:33 +0000
committerjilles <jilles@FreeBSD.org>2014-10-26 17:50:33 +0000
commitbc5702addf6a68dc471c6dd3884ca164587b8271 (patch)
tree8484fb30e43bfd82dc96d44ef76a402bd991793c /bin/sh/options.h
parent0963d8042b3129788a04f3b99596ffeef457dc3f (diff)
downloadFreeBSD-src-bc5702addf6a68dc471c6dd3884ca164587b8271.zip
FreeBSD-src-bc5702addf6a68dc471c6dd3884ca164587b8271.tar.gz
sh: Make getopts memory-safe if with changing arguments.
POSIX does not permit to continuing a getopts loop with different arguments. For parsing the positional parameters, we handle this case by resetting the getopts state when the positional parameters are changed in any way (and the getopts state is local to a function). However, in the syntax getopts <optstring> <var> <arg...>, changes could lead to invalid memory access. In the syntax getopts <optstring> <var> <arg...>, store a copy of the arguments and continue to use them until getopts is reset.
Diffstat (limited to 'bin/sh/options.h')
-rw-r--r--bin/sh/options.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/bin/sh/options.h b/bin/sh/options.h
index acc2a11..0994862 100644
--- a/bin/sh/options.h
+++ b/bin/sh/options.h
@@ -38,6 +38,7 @@ struct shparam {
unsigned char malloc; /* if parameter list dynamically allocated */
unsigned char reset; /* if getopts has been reset */
char **p; /* parameter list */
+ char **optp; /* parameter list for getopts */
char **optnext; /* next parameter to be processed by getopts */
char *optptr; /* used by getopts */
};
OpenPOWER on IntegriCloud