On Mon, May 28, 2012 at 07:34:28PM +0200, Michal Kubecek wrote:
> 
> I did experiment a bit and it seems that locale (most likely LC_CTYPE,
> unfortunately the one that needs to be set for libedit to work), affects
> only output with "set list off", with "set list on", the output seems to
> be OK. So the interference might be with the code responsible for column
> formatting - and the output looks as if all non-printable characters
> (according to locale setting) were omitted.

This is proposed patch for HEAD.

When testing it, I noticed that setting a column wider than its natural
width can result in segfault, second patch should solve this issue.

                                                         Michal Kubecek

From: Michal Kubecek <[email protected]>
Date: Tue, 29 May 2012 00:23:42 +0200
Subject: isql: fix output if charset is different from locale

Align strings manually instead of using sprintf() so that column
alignment works as intended even if LC_CTYPE is set to something
else than "C".

Also set only LC_CTYPE according to environment variables rather
than LC_ALL to prevent number formatting to be affected by
locale settings.
---
 src/isql/isql.epp |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/isql/isql.epp b/src/isql/isql.epp
index 5300db6..b891637 100644
--- a/src/isql/isql.epp
+++ b/src/isql/isql.epp
@@ -221,7 +221,18 @@ namespace IcuUtil
 			if (len > width)
 				len = width;
 
-			sprintf(buffer, (right ? "%*.*s" : "%-*.*s"), width, len, str);
+			if (right) {
+				memcpy(buffer + width - len, str, len);
+				if (width > len)
+					memset(buffer, ' ', width - len);
+			}
+			else
+			{
+				memcpy(buffer, str, len);
+				if (width > len)
+					memset(buffer + len, ' ', width - len);
+			}
+			buffer[width] = '\0';
 			return;
 		}
 
@@ -562,7 +573,7 @@ int ISQL_main(int argc, char* argv[])
 	}
 #endif	// MU_ISQL
 
-	setlocale(LC_ALL, "");
+	setlocale(LC_CTYPE, "");
 
 	TEXT tabname[WORDLENGTH];
 	tabname[0] = '\0';
-- 
1.7.7

From: Michal Kubecek <[email protected]>
Date: Tue, 29 May 2012 00:42:16 +0200
Subject: isql: count explicit column widths into line length

If column's width is set explicitly via "set width", this width
must be counted into line length, otherwise a buffer overflow
can occur as result.
---
 src/isql/isql.epp |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/isql/isql.epp b/src/isql/isql.epp
index b891637..abdeca6 100644
--- a/src/isql/isql.epp
+++ b/src/isql/isql.epp
@@ -8430,6 +8430,7 @@ static SLONG process_sqlda_display(XSQLDA* const sqlda, SLONG buffer[], int pad[
 		{
 			if (!global_Cols.find(var->aliasname, &pad[i]) && global_Col_default)
 				pad[i] = global_Col_default;
+			disp_length = pad[i];
 		}
 
 		if ((type == SQL_TEXT || type == SQL_VARYING) && var->sqlsubtype == 4)
-- 
1.7.7

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to