Forum OpenACS Q&A: nsv_incr segfault bug

Request notifications

Collapse
Posted by Andrew Piskorski on
FYI, an annoying litle bug in AOLserver 3.3+ad13 just wasted some of my time, hopefully this info will prevent it from wasting yours: If you nsv_incr a non-existant nsv key, AOLserver will segfault. This is easy to demonstrate:
nsv_set foo bar baz 
nsv_incr foo nosuchkey 

The bug is fixed in AOLserver 3.5 beta 4, and is probably present in all earlier 3.x versions. It does not exist in 4.0. It's easy to fix though, it's just one or two lines. In "aolserver/nsd/tclvar.c", edit the end of NsTclVIncrCmd so it reads like so:

if (hPtr == NULL) { 
    result = TCL_ERROR; 
    Tcl_AppendResult(interp, "no such key: ", argv[2], NULL); 
} else if (result == TCL_OK) { 

The bug was the missing NULL at the end of Tcl_AppendResult - very simple. I also added the "result = TCL_ERROR;", as it looked to me like it would otherwise be returning an uninitialized result, although the official fix to the 3.5.x series does not include that.

Here's the changelog for the bugfix from SourceForge cvs:

symbolic names:
        aolserver_v35_b5: 1.5.4.1
        aolserver_v35_b4: 1.5.4.1

revision 1.5.4.1
date: 2003/01/24 20:17:47;  author: shmooved;  state: Exp;  lines: +2 -2
Added NULL as last argument to Tcl_AppendResult for nsv_incr error
message handling the case of an array which exists, and a key that does
not exist.