BIND 10 #2272: Improve the perfdhcp command_options_helper code.
BIND 10 Development
do-not-reply at isc.org
Fri Sep 21 08:08:12 UTC 2012
#2272: Improve the perfdhcp command_options_helper code.
-------------------------------------+-------------------------------------
Reporter: | Owner: UnAssigned
marcin | Status: assigned
Type: | Milestone: Sprint-
defect | DHCP-20121004
Priority: | Resolution:
medium | Sensitive: 0
Component: | Sub-Project: DHCP
Unclassified | Estimated Difficulty: 0
Keywords: | Total Hours: 0
Defect Severity: N/A |
Feature Depending on Ticket: |
Add Hours to Ticket: 0 |
Internal?: 0 |
-------------------------------------+-------------------------------------
Changes (by marcin):
* owner: marcin => UnAssigned
* status: new => assigned
Comment:
The command_options_unit tests prepare certain number of perfdhcp command
lines in the string format like "perfdhcp -l eth0 -4 all". Each new
command line is later tokenized and stored in argc, argv variables. The
argc, argv is allocated for each new command line being tested in
command_options_helper.h by CommandOptionsHelper::tokenizeString() and
then it is passed to CommandOptions::parse() for parsing.
The getopt() function used in parse() function keeps its internal state
including optind, opterr etc. during parsing subsequent arguments of the
command line. It also appears that getopt() remembers the pointer of the
previously used argv buffer and if getopt() state is not properly reset
before parsing new command line it will refer to freed memory and that
will eventually lead to undefined behavior and output from getopt().
There are at least two ways to reset the state of the getopt() to prevent
it from trying to access freed buffers. On Linux: the optind must be set
to 0. This however does not work on BSD and MacOS where there is an
additional variable declared: optreset. On those systems both optreset and
optind must be set to 1.
The key of the change being done here is to check if optreset is available
on the OS we are at and if so, define the HAVE_OPTRESET so as the code can
take different reset path based on this. The code also now uses new/delete
instead of malloc/free to allocate the argv table which is more proper
when programming in C++. Some additional minor changes have been made.
Please review.
--
Ticket URL: <http://bind10.isc.org/ticket/2272#comment:2>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development
More information about the bind10-tickets
mailing list