Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-09-27
16:52 • Closed ticket [3413857fff]: Tcl_ParseArgsObjv segfaults plus 7 other changes artifact: 6bf84832a0 user: dkf
16:08 • Ticket [3413857fff]: 1 change artifact: 5c351b8e1e user: dkf
16:07 • Ticket [3413857fff]: 1 change artifact: b78d34aad3 user: dkf
16:07 • Ticket [3413857fff]: 4 changes artifact: 114cce80ee user: dkf
05:35 • Ticket [3413857fff]: 4 changes artifact: aa9dbde861 user: ropuls
05:20 • Ticket [3413857fff]: 4 changes artifact: 9cb704a11e user: ropuls
04:13 • Ticket [3413857fff]: 4 changes artifact: 4f7619a90f user: ferrieux
04:06 • Ticket [3413857fff]: 4 changes artifact: e8a12b0da4 user: dkf
2011-09-26
23:06 • Ticket [3413857fff]: 4 changes artifact: b75b6cb12a user: ferrieux
23:04 • Ticket [3413857fff]: 4 changes artifact: f4724614bb user: ferrieux
17:51 • Ticket [3413857fff]: 4 changes artifact: 42e3031504 user: dkf
17:43 • Ticket [3413857fff]: 4 changes artifact: af6643834a user: ropuls
17:11 • Ticket [3413857fff]: 4 changes artifact: 69125a359b user: dkf
04:59 • Ticket [3413857fff]: 4 changes artifact: f7f7c1df30 user: ferrieux
04:59 • Add attachment parseargs.patch to ticket [3413857fff] artifact: 51127b8601 user: ferrieux
04:59 • Ticket [3413857fff] Tcl_ParseArgsObjv segfaults status still Open with 4 oth... artifact: f32a2ea80a user: ferrieux
04:44 • Ticket [3413857fff]: 1 change artifact: 357e6a98af user: ferrieux
04:44 • Ticket [3413857fff]: 4 changes artifact: c27d742c51 user: ferrieux
2011-09-25
21:17 • New ticket [3413857fff]. artifact: 8e4aa232d9 user: ferrieux

Tcl_ParseArgsObjv segfaults

Closed / Fixed3413857fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2011-09-25 21:17:44
Kindly reported and analyzed by Roman Puls on tcl-core. The cleanup of the returned-extra-args array involves the following sequence:

   ckfree(leftovers);
   leftovers[nrem] = NULL;
 
This is just plain wrong, and has been so since the first implementation (TIP 265).
The purpose of this ckfree (at this place, where nrem might be nonzero) is unclear to me.
Assigning to the initial committer.
ferrieuxplain2011-09-26 04:44:01
High prio as low-hanging fruit.

BTW, why NULL-terminated the remObjPtr array ? No such contract appears in the manpage, and it is unneeded since the length is transmitted elsewhere.
ferrieux Ticket [3413857fff]: 1 change [History diff]2011-09-26 04:44:02
ferrieuxplain2011-09-26 04:59:28
File Added - 424492: parseargs.patch
ferrieuxplain2011-09-26 04:59:47
Please review attached patch.
dkfplain2011-09-26 17:11:48
Try what I've committed to the bug-3413857 branch; we could do with a test before merging back into trunk. (I think there was an off-by-one bug in the code; for example, if the only thing left was the command name, *objcPtr should only be set to 1, not to 2, as the trailing NULL is not counted.)
ropulsplain2011-09-26 17:43:21
Could you assist? The patch fails for me, and I cannot find the branch in sf cvs:

patch --dry-run --strip 1 < parseargs.patch
patching file tclIndexObj.c
Hunk #1 FAILED at 1111.
Hunk #2 FAILED at 1180.
Hunk #3 FAILED at 1293.

Thanks, R.
dkfplain2011-09-26 17:51:39
It's in fossil on http://core.tcl.tk/ (All our development has been there for about 6 months or so.) Download link...

http://core.tcl.tk/tcl/zip/Tcl%20Source%20Code-8edb5ef770d0de1f.zip?uuid=8edb5ef770d0de1f32ba001970f32a71554f1197
ferrieuxplain2011-09-26 23:04:10
Roman, the patch I attached is against 8.6 trunk tip.
ferrieuxplain2011-09-26 23:06:47
To be clear: you can just as well download Donal's commit, which is equivalent AFAICT (right, Donal ?)
dkfplain2011-09-27 04:06:24
Not quite. I reviewed the patch and made some small adjustments (hence my comment below about an off-by-one error).

What we need though is a test that detects the problems (possibly only during a memdebug/valgrind run, but even so) so that we can be _sure_ that this is fixed. I've no problem with that requiring more things in tclTest.c if necessary, of course...
ferrieuxplain2011-09-27 04:13:37
Oops, right. Missed your comment in the flow, sorry.
ropulsplain2011-09-27 05:20:47
Thanks for clarification. I have taken dkf's version and ported back to 8.6b1.1, which seems to work as expected. However, I kept the non-memcpy assignment at the end for the sake of readability (instead of performance).
ropulsplain2011-09-27 05:35:00
and a last one: does it make sense to downsize the leftovers / remObjv array?

    leftovers[nrem] = NULL;
    *objcPtr = nrem++;
    *remObjv = (Tcl_Obj **)ckrealloc((char *)leftovers, nrem * sizeof(Tcl_Obj *));

I'd probably pass it back as is:
- ckrealloc might fail and is "relatively" expensive
- memory saving is expected to be relatively low, maximum is : objc * sizeof(Tcl_Obj *), which would typically be some 40 bytes or so.

... but of course this is a serious question of style :)
dkfplain2011-09-27 16:07:37
Downsizing is probably not very important, and should be quick (the memory manager can just note the change in used size in its metadata block; it doesn't need to actually allocate). It does help with subsequent use of valgrind though. :-)

The take-home message: as long as we have some tests, we're good to go.
dkf Ticket [3413857fff]: 1 change [History diff]2011-09-27 16:07:52
dkf Ticket [3413857fff]: 1 change [History diff]2011-09-27 16:08:07
dkfplain2011-09-27 16:52:03
allow_comments - 1

Tests added. Everything merged back to trunk. (And TCL_ARGV_AUTO_REST macro now works! Found that during testing.)

Download link for version with merge done: https://core.tcl.tk/tcl/zip/Tcl%20Source%20Code-06c0436f0421b3ee.zip?uuid=06c0436f0421b3ee5c7fac0bd919e7dde362d3a6
Log in (anonymous is fine) to add a comment.

Attachments: