From nobody@FreeBSD.org  Fri Nov 18 09:29:01 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 64ECA106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 18 Nov 2011 09:29:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 3ACF28FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 18 Nov 2011 09:29:01 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pAI9T00G074978
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 18 Nov 2011 09:29:00 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pAI9T0mA074977;
	Fri, 18 Nov 2011 09:29:00 GMT
	(envelope-from nobody)
Message-Id: <201111180929.pAI9T0mA074977@red.freebsd.org>
Date: Fri, 18 Nov 2011 09:29:00 GMT
From: Valentin Davydov <cs@soi.spb.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sqlite3 command shell incorrectly handles some blobs
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         162650
>Category:       ports
>Synopsis:       databases/sqlite3 command shell incorrectly handles some blobs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    rm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 18 09:30:10 UTC 2011
>Closed-Date:    Thu Dec 22 18:23:38 UTC 2011
>Last-Modified:  Thu Dec 22 18:23:38 UTC 2011
>Originator:     Valentin Davydov
>Release:        RELENG_8_2
>Organization:
State Optical Institute
>Environment:
FreeBSD hostname.domain 8.2-STABLE FreeBSD 8.2-STABLE #13: Fri Apr 29 12:54:43 MSD 2011     user@hostname.domain:/usr/obj/usr/src/sys/KOR  i386

>Description:
When the commadline shell supplied with databases/sqlite3 (any version of year 2010 and later) is asked to output database content in the form of SQL statement (by issuing .mode insert), and actual data contains blobs, some of them gets corrupted in the output. This is due to the datatype/format mismatch in one of the internal functions of the shell called output_hex_blob().
>How-To-Repeat:
Take FreeBSD 8.x (bug was tested on several various versions, both i386 and amd64). Install port databases/sqlite3, either compiling from ports or through binary package. Then launch sqlite3 shell and give it commands as shown below (shell responses are indented for clarity):

$ sqlite3 db.tmp
   SQLite version 3.7.9 2011-11-01 00:52:41
   Enter ".help" for instructions
   Enter SQL statements terminated with a ";"
sqlite> create table t(v blob);
sqlite> insert into t values(X'0123456789');
sqlite> .mode insert
sqlite> select * from t;
   INSERT INTO table VALUES(X'01234567ffffff89');

>Fix:
Following patch helps (save it as databases/sqlite3/files/patch-src-shell.c)

--- src/shell.c.orig    2011-11-01 16:31:18.000000000 +0400
+++ src/shell.c 2011-11-10 22:45:11.000000000 +0400
@@ -490,7 +490,7 @@
 */
 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
   int i;
-  char *zBlob = (char *)pBlob;
+  unsigned char *zBlob = (unsigned char *)pBlob;
   fprintf(out,"X'");
   for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]); }
   fprintf(out,"'");

Perhaps one should take another strategy (for example, replace "%02x" format
with "%02hhx" of even reimplement necessary fprinf() functionality) depending on the policy (it seems that using signed datatypes for semanticaly non-negative data is the policy of the sqlite developers team).

>Release-Note:
>Audit-Trail:

From: Ruslan Mahmatkhanov <cvs-src@yandex.ru>
To: Valentin Davydov <cs@soi.spb.ru>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: ports/162650: sqlite3 command shell incorrectly handles some
 blobs
Date: Fri, 18 Nov 2011 16:37:06 +0400

 Hi, Valentin!
 
 I can confirm the problem, and that your patch fix it. Since this is not
 FreeBSD-specific problem, would you please submit upstream bug-report
 and provide us with link here? I can do it for you, but you know better
 and have all details to discuss. Thanks.
 
 -- 
 Regards,
 Ruslan
 
 Tinderboxing kills... the drives.

From: Pavel Volkov <pavelivolkov@googlemail.com>
To: bug-followup@freebsd.org, cs@soi.spb.ru
Cc:  
Subject: Re: ports/162650: sqlite3 command shell incorrectly handles some blobs
Date: Thu, 22 Dec 2011 13:37:43 +0400

 --20cf30562f214d375204b4ab0e05
 Content-Type: text/plain; charset=UTF-8
 
 Hello. You are right. I applaud your patch. I also request to increase
 PORTREVISION. Thank you.
 
 --20cf30562f214d375204b4ab0e05--
Responsible-Changed-From-To: freebsd-ports-bugs->rm 
Responsible-Changed-By: rm 
Responsible-Changed-When: Thu Dec 22 11:18:47 UTC 2011 
Responsible-Changed-Why:  
I will take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162650 

From: Ruslan Mahmatkhanov <cvs-src@yandex.ru>
To: Pavel Volkov <pavelivolkov@googlemail.com>
Cc: freebsd-ports-bugs@FreeBSD.org, bug-followup@FreeBSD.org
Subject: Re: ports/162650: sqlite3 command shell incorrectly handles some
 blobs
Date: Thu, 22 Dec 2011 15:23:46 +0400

 Pavel Volkov wrote on 22.12.2011 14:10:
 >  Hello. You are right. I applaud your patch. I also request to increase
 >  PORTREVISION. Thank you.
 
 I still insist that this is upstream issue, because, as i wrote to
 Valentin in private email, i'm able to reproduce this in CentOS/RHEL 6.0
 with stock sqlite 3.6.20. So this is actually should be reported upstream.
 
 I'll commit this later this day after yet another testing.
 
 -- 
 Regards,
 Ruslan
 
 Tinderboxing kills... the drives.

From: Pavel Volkov <pavelivolkov@googlemail.com>
To: Ruslan Mahmatkhanov <cvs-src@yandex.ru>
Cc: freebsd-ports-bugs@freebsd.org, bug-followup@freebsd.org
Subject: Re: ports/162650: sqlite3 command shell incorrectly handles some blobs
Date: Thu, 22 Dec 2011 17:37:33 +0400

 I completely agree with you.
 You have already reported the problem and the solution to the mailing
 list sqlite-dev?
 We can use the patch as a temporary solution.
 
 http://www.sqlite.org/src/tktview?name=3D72adc99de9
 http://www.sqlite.org/src/info/a2ad9e6363
 
 FreeBSD ***.*****.ru 9.0-RC2 FreeBSD 9.0-RC2 #0: Fri Nov 11 12:05:44
 MSK 2011=C2=A0=C2=A0=C2=A0=C2=A0 root@***.*****.ru:/usr/obj/usr/src/sys/ext=
 =C2=A0 amd64
 
 SQLite version 3.7.9 2011-11-01 00:52:41
 Enter ".help" for instructions
 Enter SQL statements terminated with a ";"
 sqlite> .mode insert
 sqlite> select X'79';
 INSERT INTO table VALUES(X'79');
 sqlite> select X'80';
 INSERT INTO table VALUES(X'ffffff80');
 
 
 On Thu, Dec 22, 2011 at 15:23, Ruslan Mahmatkhanov <cvs-src@yandex.ru> wrot=
 e:
 >
 > Pavel Volkov wrote on 22.12.2011 14:10:
 > > =C2=A0Hello. You are right. I applaud your patch. I also request to inc=
 rease
 > > =C2=A0PORTREVISION. Thank you.
 >
 > I still insist that this is upstream issue, because, as i wrote to
 > Valentin in private email, i'm able to reproduce this in CentOS/RHEL 6.0
 > with stock sqlite 3.6.20. So this is actually should be reported upstream=
 .
 >
 > I'll commit this later this day after yet another testing.
 >
 > --
 > Regards,
 > Ruslan
 >
 > Tinderboxing kills... the drives.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/162650: commit references a PR
Date: Thu, 22 Dec 2011 18:10:39 +0000 (UTC)

 rm          2011-12-22 18:10:22 UTC
 
   FreeBSD ports repository
 
   Modified files:
     databases/sqlite3    Makefile 
   Added files:
     databases/sqlite3/files patch-src_shell.c 
   Log:
   Add patch that fixes blobs handling in interactive mode.
   
   Looks like this issue is known by upstream since 2009,
   but never was fixed in any release.
   
   PR:             162650
   Submitted by:   Valentin Davydov <cs at soi.spb.ru>
   Approved by:    maintainer, novel (mentor, implicit)
   
   Revision  Changes    Path
   1.68      +1 -0      ports/databases/sqlite3/Makefile
   1.1       +11 -0     ports/databases/sqlite3/files/patch-src_shell.c (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: rm 
State-Changed-When: Thu Dec 22 18:23:36 UTC 2011 
State-Changed-Why:  
Committed, thank you! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162650 
>Unformatted:
