Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 2000 09:27:46 -0400 (EDT)
From:      Mikhail Teterin <mi@privatelabs.com>
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        tdarugar@binevolve.com
Subject:   ports/20058: ugly bug in tcl-Mysql -- old code's legacy
Message-ID:  <200007201327.JAA17056@misha.privatelabs.com>

next in thread | raw e-mail | index | archive | help

>Number:         20058
>Category:       ports
>Synopsis:       ugly bug in tcl-Mysql -- old code's legacy
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 20 06:40:03 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Mikhail Teterin
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
Virtual Estates, Inc.
>Environment:

>Description:

	In what  is surely a  bug in  the original code,  if the
	query  handle  is  ommitted from  the  subsequent  calls
	to  fetchrow, numrows,  endquery, those  procedures will
	operate on the  query number 0, which may or  may not be
	the  last  or  the  first  query  you  make,  but  don't
	yet  end. Worse  -- the  documentation --  api.html does
	not  even document  passing  the query  handle to  those
	function, essentially implying, that  only one query can
	be "active"  per connection at  a time, even  though the
	code  has  a  compiled  time limit  of  16  queries  per
	connection and is ready to accept the query handle.

	In my  earlier submitted  (and committed)  conversion of
	the code to the TCL  objects, I overlooked this scenario
	and my  code will crash  or act erraticaly if  the query
	argument is ommitted.

	The submitted  mod to  patches/patch-aa fixes  the code,
	and the new patches/patch-ab modifies api.html to insist
	on  the  query  handle  being passed  to  the  functions
	that  use it  (leaving its  ommittance an  intentionally
	undocumented "feature").  It also cleans up  api.html to
	pass weblint's scrutiny.

>How-To-Repeat:

	set connection handle [sql connect db operator <password>]
	sql selectdb $connection <database>
	set query [sql query $connection "select * from <table>"]
	puts "<table> has [sql numrows $connection]"
	-> crash, because $query is not given to ``sql numrows'' <-

>Fix:

	The full port (with patches) can also be found at
		http://virtual-estates.net/tcl-Mysql.port.tar.bz2

--- patches/patch-aa	Tue Jul 18 16:17:13 2000
+++ patches/patch-aa	Thu Jul 20 09:07:42 2000
@@ -111,3 +105,3 @@
  		return TCL_ERROR;
-@@ -133,75 +93,84 @@
+@@ -133,58 +93,58 @@
  	Manager_sql *mgr = (Manager_sql *)clientData;
@@ -209,3 +203,2 @@
 -			Tcl_AppendResult(interp, "sql: unknown sql command: ", argv[1], NULL);
--			return TCL_ERROR;
 +	// take care of the command:
@@ -213,3 +206,4 @@
 +		/* get the "result handle" returned previously */
-+		if (Tcl_GetIntFromObj(NULL, objv[3], &res) != TCL_OK ||
++		if (objc < 4) res = 0; /* oddly, this is how it was -- bug? */
++		else if (Tcl_GetIntFromObj(NULL, objv[3], &res) != TCL_OK ||
 +				res < 0) {
@@ -218,4 +212,4 @@
 +				" handle", NULL);
-+			return TCL_OK;
- 		}
+ 			return TCL_ERROR;
+@@ -192,16 +152,26 @@
  	}
@@ -258,3 +252,3 @@
  }
-@@ -226,7 +195,7 @@
+@@ -226,7 +196,7 @@
  
@@ -268,3 +262,3 @@
 +	// Provide a package called ``sql'' 
-+	if (Tcl_PkgProvide(interp, "sql", "1.0") == TCL_ERROR)
++	if (Tcl_PkgProvide(interp, "sql", "1.1") == TCL_ERROR)
  		return TCL_ERROR;

New patch patches/patch-ab:

--- docs/api.html	Wed Jul 22 21:54:38 1998
+++ docs/api.html	Wed Jul 19 17:19:34 2000
@@ -1,2 +1,5 @@
+<HTML>
+<HEAD>
 <title>Generic Tcl Database Interface API</title>
+</HEAD>
 <BODY BGCOLOR="#ffffff" LINK="#0000ff" ALINK="#ff0000" TEXT="#000000">
@@ -55,3 +58,3 @@
 	    statement). Use with <code><font color="#000099">fetchrow</font></code> and <code><font color="#000099">endquery</font></code>. <br>
-	 <code><font color="#000099">sql query $conn "select * from sample where x > 3"</font></code>
+	 <code><font color="#000099">set query [sql query $conn "select * from sample where x &gt; 3"]</font></code>
 
@@ -62,3 +65,3 @@
 			is returned.<br>
-	 <code><font color="#000099">while {[set row [sql fetchrow $conn]] != ""} { puts $row }</font></code>
+	 <code><font color="#000099">while {[set row [sql fetchrow $conn $query]] != ""} { puts $row }</font></code>
 	 
@@ -66,4 +69,4 @@
 <p>
-<hr width=50%>
-<a name=sample><h3>Sample Usage:</h3></a>
+<hr width="50%">
+<h3><a name=sample>Sample Usage:</a></h3>
 Also see 
@@ -86,3 +89,3 @@
 # Put some dummy data in:
-for {set i 0} {$i < 10} {incr i} {
+for {set i 0} {$i &lt; 10} {incr i} {
 	sql exec $conn "insert into junk values ($i, $i.01, 'xx $i xx')"
@@ -91,5 +94,5 @@
 # Do a select and display the results
-sql query $conn "select * from junk where i > 3" 
+set query [sql query $conn "select * from junk where i &gt; 3"]
 
-while {[set row [sql fetchrow $conn]] != ""} {
+while {[set row [sql fetchrow $conn $query]] != ""} {
 	puts "row = $row"
@@ -97,3 +100,3 @@
 
-sql endquery $conn
+sql endquery $conn $query
 
@@ -113 +116,3 @@
 </pre>
+</BODY>
+</HTML>

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007201327.JAA17056>