Skip to Content.
Sympa Menu

freetds - Re: Crash in tsql

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Varley, David(CBorn at Alcoa)" <David.Varley AT alcoa.com.au>
  • To: 'TDS Development Group' <freetds AT franklin.oit.unc.edu>
  • Subject: Re: Crash in tsql
  • Date: Wed, 14 Aug 2002 12:04:59 +0800


Brian,

I went ahead and made the changes to iconv.c et al as suggested, works
for me with minimal disruption, feel free to use or ignore as you wish.

Only 3 files change, iconv.c is the main one, I'll attach a zip as well
as diffs from the cvs. mem.c is a 1-line mod.
tds.h is changed such that the HAVE_ICONV code is removed, and the three
iconv related elements in the TDSSOCKET structure is replaced by a single

void *pIconv;

I'll leave the actual changes in tds.h.in to you, resulting tail end of
TDSSOCKET will look like:

int emul_little_endian;
void *pIconv;
char *date_fmt;
TDSCONTEXT *tds_ctx;
} TDSSOCKET;


Diffs to mem.c and iconv.c follow, for iconv.c might be easier just
to grab the complete attached zipped file.

David Varley mailto:David.Varley AT ieee.org


Index: src/tds/mem.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/mem.c,v
retrieving revision 1.14
diff -r1.14 mem.c
395c395
< if (tds->use_iconv) tds_iconv_close(tds);
---
> tds_iconv_close(tds); /* call will check if iconv was used
or not. DAV */


Index: src/tds/iconv.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/iconv.c,v
retrieving revision 1.9
diff -r1.9 iconv.c
22a23,24
> **
> ** Modified for better localization 14AUG02 David Varley
34a37,45
> #if HAVE_ICONV
> typedef struct tds_iconv_info
> {
> /* int use_iconv; (Not needed ?) */
> iconv_t cdto;
> iconv_t cdfrom;
> } TDSICONVINFO;
> #endif
>
38,46c49,62
< tds->cdto = iconv_open("UCS-2",charset);
< if (tds->cdto == (iconv_t)-1) {
< tds->use_iconv = 0;
< return;
< }
< tds->cdfrom = iconv_open(charset, "UCS-2");
< if (tds->cdfrom == (iconv_t)-1) {
< tds->use_iconv = 0;
< return;
---
> TDSICONVINFO *pIconv;
> iconv_t cdto, cdfrom;
>
> if(pIconv = calloc(sizeof(TDSICONVINFO),1)) {
> if((cdto = iconv_open("UCS-2",charset)) != (iconv_t) -1) {
> if((cdfrom = iconv_open(charset, "UCS-2")) !=
(iconv_t) -1) {
> pIconv->cdto = cdto;
> pIconv->cdfrom = cdfrom;
> tds->pIconv = pIconv;
> return;
> }
> iconv_close(cdto);
> }
> free(pIconv);
48,52d63
< tds->use_iconv = 1;
< /* temporarily disable */
< /* tds->use_iconv = 0; */
< #else
< tds->use_iconv = 0;
58,62c69,74
< if (tds->cdto != (iconv_t)-1) {
< iconv_close(tds->cdto);
< }
< if (tds->cdfrom != (iconv_t)-1) {
< iconv_close(tds->cdfrom);
---
> TDSICONVINFO *pIconv;
> if(pIconv = (TDSICONVINFO *) tds->pIconv) {
> iconv_close(pIconv->cdto);
> iconv_close(pIconv->cdfrom);
> free(pIconv);
> tds->pIconv = 0;
75a88
> TDSICONVINFO *pIconv;
84c97
< if (tds->use_iconv) {
---
> if(pIconv = (TDSICONVINFO *) tds->pIconv) {
89,90c102,103
< iconv(tds->cdfrom, &in_ptr, &in_bytes, &out_ptr, &out_bytes);
< out_string[len] = '\0';
---
> iconv(pIconv->cdfrom, &in_ptr, &in_bytes, &out_ptr, &out_bytes);
> out_string[len] = '\0';
115a129
> TDSICONVINFO *pIconv;
125c139
< if (tds->use_iconv) {
---
> if(pIconv = (TDSICONVINFO *) tds->pIconv) {
130c144
< iconv(tds->cdto, &in_ptr, &in_bytes, &out_ptr, &out_bytes);
---
> iconv(pIconv->cdto, &in_ptr, &in_bytes, &out_ptr, &out_bytes);


================ End of Diffs ======================

> -----Original Message-----
> From: Lowden, James K [mailto:LowdenJK AT bernstein.com]
> Sent: Wednesday, 14 August 2002 2:53 AM
> To: TDS Development Group
> Subject: [freetds] Re: Crash in tsql
>
>
> > From: Brian Bruns [mailto:camber AT ais.org]
> > Sent: August 13, 2002 12:10 PM
> >
> > > > Actually, this fix is bad, since we don't distribute config.h
> > > > (nor should we) things won't build.
> > >
> > > I don't understand that sentence. Could you unpack it for
> > > me, please?
> >
> > Ok, config.h is a build time header that doesn't not end up in
> > /usr/local/freetds/include. It's only there to avoid having
> > a million -D HAVE_FOO arguments on the make line.
> >
> > Now, take an application like tsql that may be compiled
> outside of the
> > freetds tree. Obviously, it can not rely on the HAVE_* macros being
> > defined. Since tds.h is distributed (ends up in
> > freetds/include) and used
> > by third party apps, this is a problem.
> >
> > > > We simply can't be checking HAVE_ICONV in tds.h (or any
> > distributable
> > > > header). We could substitute from configure but that
> > strikes me as
> > > > sloppy. Any other options?
> >
> > The basic problem is we conditionally define part of
> > TDSSOCKET based on a
> > compile time #define, bad form on my part. So, the iconv
> checking in
> > configure.in is just fine, how we use it during build is
> flawed. This
> > wouldn't be a problem except that iconv_t relies on iconv.h
> > and therefore may not be available.
>
> I think I get it, and I have a suggestion for you.
>
> 1. Define the type inconv_t in much the same way you define
> smallint/int/real in configure.in. If HAVE_ICONV is true,
> use it, else make
> one up (hold that thought).
>
> 2. Define a structure in tds.h.in:
>
> struct _inconv_io
> {
> iconv_t cdto, cdfrom;
> } ICONV_IO;
>
> 3. Change TDSSOCKET to include a pointer to an ICONV_IO
> structure. In
> the socket initialization code, you'll have to allocate that
> structure on
> the heap, but that's what you're doing anyway for other stuff. If
> HAVE_ICONV is false, of course, you set the pointer to null,
> or possibly to
> some static structure useful for iconvless byte stripping.
>
> Would that do the trick?
>
> --jkl
>
>
> The information contained in this transmission may contain
> privileged and
> confidential information and is intended only for the use of
> the person(s)
> named above. If you are not the intended recipient, or an
> employee or agent
> responsible for delivering this message to the intended recipient, any
> review, dissemination, distribution or duplication of this
> communication is
> strictly prohibited. If you are not the intended recipient,
> please contact
> the sender immediately by reply e-mail and destroy all copies of the
> original message. Please note that for certain accounts we do
> not accept
> orders and/or instructions by e-mail, and for those accounts
> we will not be
> responsible for carrying out such orders and/or instructions.
> Kindly refrain
> from sending orders or instructions by e-mail unless you have
> confirmed that
> we accept such communications for your account. Please also
> note that to
> satisfy regulatory requirements we review the outgoing and
> incoming e-mail
> correspondence of staff members serving certain functions.
>
>
>
> ---
> You are currently subscribed to freetds as:
> [David.Varley AT alcoa.com.au]
> To unsubscribe, forward this message to
> $subst('Email.Unsub')
>

Attachment: iconv.zip
Description: Binary data




Archive powered by MHonArc 2.6.24.

Top of Page