[Pkg-tcltk-devel] Bug#746161: tcl8.5: segfault when rand() is used	after closing a db file
    Dave U. Random 
    anonymous at anonymitaet-im-inter.net
       
    Sun Apr 27 12:00:25 UTC 2014
    
    
  
Package: tcl8.5
Version: 8.5.11-2
Severity: normal
Dear Maintainer,
In attempt to implement concurrent access to a db file, there is a
circumstance where a call to rand() triggers a segmentation fault.  A
minimal code example is below.
Note that this example probably demonstrates a bad implementation
approach.  Regardless, a call to rand() should never cause a
segmentation fault.  Also note that this sample code is very similar
to a separate bug recently reported against the libsqlite3-tcl
package.  But it differs in that the other bug does not involve rand()
and is not a segfault.
====8<----------------------------------------
#!/usr/bin/tclsh8.5
package require sqlite3
set script_basename [lindex [file split [info script]] end]
regsub -all -- {[[:punct:]]} $script_basename {_} script_id
set db_filename [exec mktemp --tmpdir=/tmp --suffix=.db ${script_id}_XXX]
proc init_db {} {
    global db_filename
    sqlite3 my_db $db_filename
    my_db timeout 3000
}
init_db
my_db eval {create table if not exists my_tbl (bank             text not null primary key,
					       party_supported  text,
                                               bailed_out       text,
                                               supports_cispa   text)}
my_db eval {insert into my_tbl (bank) values ('bank of america')}
my_db eval {insert into my_tbl (bank) values ('chase')}
my_db eval {insert into my_tbl (bank) values ('citibank')}
my_db eval {insert into my_tbl (bank) values ('pnc')}
my_db eval {insert into my_tbl (bank) values ('suntrust')}
my_db eval {select bank from my_tbl where party_supported is null} {
    my_db eval {update my_tbl set party_supported = 'republican' where bank = $bank}
    my_db eval {update my_tbl set bailed_out      = 'true' 	 where bank = $bank}
    my_db eval {update my_tbl set supports_cispa  = 'true' 	 where bank = $bank}
    # Closing the db is perhaps a bad idea at this point given that we
    # are inside of a query operation.  Regardless, it should not
    # create opportunity for a segmentation fault.
    my_db close; #give other db users a chance to gain access
    # The following use of rand() somehow to contributes to the
    # segmentation fault.  If /after/ is not called (or it is supplied
    # an integer literal instead), then the segmentation fault does
    # not occur.  Instead we later get an erroneous error about a db
    # lock.
    after [expr int(rand()*10000) + 10000]; #make the db available for a random amount of time
    init_db; #take back the db
}
====8<----------------------------------------
-- System Information:
Debian Release: 7.4
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 3.2.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages tcl8.5 depends on:
ii  libc6  2.13-38+deb7u1
tcl8.5 recommends no packages.
Versions of packages tcl8.5 suggests:
pn  tcl-tclreadline  <none>
-- no debconf information
    
    
More information about the Pkg-tcltk-devel
mailing list