BIND 10 master, updated. 141b8cb757874ff34e7ae70cab01ee6b0c8f3f60 [master] Workaround for getopt() bug in glibc.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 21 13:53:27 UTC 2012
The branch, master has been updated
via 141b8cb757874ff34e7ae70cab01ee6b0c8f3f60 (commit)
from e6aed22f2653ed33b929438e324e97f6f645d0dd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 141b8cb757874ff34e7ae70cab01ee6b0c8f3f60
Author: Marcin Siodelski <marcin at isc.org>
Date: Thu Jun 21 14:42:13 2012 +0200
[master] Workaround for getopt() bug in glibc.
-----------------------------------------------------------------------
Summary of changes:
tests/tools/perfdhcp/command_options.cc | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
-----------------------------------------------------------------------
diff --git a/tests/tools/perfdhcp/command_options.cc b/tests/tools/perfdhcp/command_options.cc
index 5b4f424..09393bb 100644
--- a/tests/tools/perfdhcp/command_options.cc
+++ b/tests/tools/perfdhcp/command_options.cc
@@ -88,7 +88,25 @@ CommandOptions::parse(int argc, char** const argv) {
// Reset internal variables used by getopt
// to eliminate undefined behavior when
// parsing different command lines multiple times
+
+#ifdef __GLIBC__
+ // Warning: non-portable code. This is due to a bug in glibc's
+ // getopt() which keeps internal state about an old argument vector
+ // (argc, argv) from last call and tries to scan them when a new
+ // argument vector (argc, argv) is passed. As the old vector may not
+ // be main()'s arguments, but heap allocated and may have been freed
+ // since, this becomes a use after free and results in random
+ // behavior. According to the NOTES section in glibc getopt()'s
+ // manpage, setting optind=0 resets getopt()'s state. Though this is
+ // not required in our usage of getopt(), the bug still happens
+ // unless we set optind=0.
+ //
+ // Setting optind=0 is non-portable code.
+ optind = 0;
+#else
optind = 1;
+#endif
+
opterr = 0;
// Reset values of class members
More information about the bind10-changes
mailing list