Skip to Content.
Sympa Menu

freetds - Re: [freetds] dblib patch

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] dblib patch
  • Date: Fri, 1 Jul 2005 15:34:05 +0100

Thanks Freddy,

As ever, I'll defer to your expertise.
Apply your version of the rtrim function if it does the job.

Bill

-----Original Message-----
From: freetds-bounces AT lists.ibiblio.org
[mailto:freetds-bounces AT lists.ibiblio.org] On Behalf Of ZIGLIO,
Frediano, VF-IT
Sent: 01 July 2005 15:09
To: FreeTDS Development Group
Subject: Re: [freetds] dblib patch


>
> Hi guys,
>
> I haven't been around much lately - too much (unrelated) work to do
> elsewhere.
>

Never mind.

> Here's a little patch to dblib for a couple of issues. I've applied it
> to my version of 0.63.
>
> The first change is for (free)bcp.
>
> This fixes a problem where we attempt to bcp in from file to
> a NOT NULL
> (var)char column.
> If the host file contains just blanks, we "rtrim" the data down to a
> zero length string.
> bcp then interprets this as a NULL and we get an error
>
> "attempt to copy NULL to a NOT NULL column"
>
> or somesuch.
>
> The second change is for dbresults.
>
> If our sql command is to "exec stored_procedure", and the stored
> procedure has no result set(s), we are failing to generate a SUCCEED
> return from dbresults, just returning NO_MORE_RESULTS.
>
> here's the patch from my version of 0.63:
>
> diff -u -r freetds-0.63/src/dblib/bcp.c
> freetds-0.63.mine/src/dblib/bcp.c
> --- freetds-0.63/src/dblib/bcp.c 2005-02-07
> 10:28:25.000000000 +0000
> +++ freetds-0.63.mine/src/dblib/bcp.c 2005-06-29 15:49:12.784615000
> +0100
> @@ -2826,6 +2826,10 @@
> return bufpos;
> }
>
> +/**
> + * Trim trailing blanks from an input string,
> + * Always leaving ONE blank in an entirely blank string.
> + */
> static int
> rtrim(char *istr, int ilen)
> {
> @@ -2836,6 +2840,14 @@
> *t = '\0';
> olen--;
> }
> +
> + /* put back a single blank, if we've got rid of them all */
> +
> + if (ilen && !olen) {
> + *t = ' ';
> + olen = 1;
> + }
> +
> return olen;
> }
>

Mmmm...

static int
rtrim(char *istr, int ilen)
{
char *t;
int olen = ilen;

for (t = istr + (ilen - 1); *t == ' '; t--) {
*t = '\0';
olen--;
}
return olen;
}

this contain a buffer underflow...

Perhaps it would better to rewrite like

static int
rtrim(char *istr, int ilen)
{
char *t;

for (t = istr + ilen; --t > istr && *t == ' '; ) {
*t = '\0';
--ilen;
}
return ilen;
}

(it solve also '' problem)

> diff -u -r freetds-0.63/src/dblib/dblib.c
> freetds-0.63.mine/src/dblib/dblib.c
> --- freetds-0.63/src/dblib/dblib.c 2005-01-07
> 16:34:39.000000000 +0000
> +++ freetds-0.63.mine/src/dblib/dblib.c 2005-04-20 12:57:44.643915000
> +0100
> @@ -1345,6 +1345,7 @@
> break;
>
> case TDS_DONE_RESULT:
> + case TDS_DONEPROC_RESULT:
>
> /* A done token signifies the end of a
> logical command.
> * There are three possibilities:
> @@ -1375,7 +1376,6 @@
> }
>
>
> - case TDS_DONEPROC_RESULT:
> case TDS_DONEINPROC_RESULT:
>
> /* We should only return SUCCEED on a command within a
> */

Mmm... I'll commit ASAP. I don't know why but this last patch reminds me
ODBC...

freddy77
_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
--------------------------------------------------------

If you are not an intended recipient of this e-mail, please notify the
sender, delete it and do not read, act upon, print, disclose, copy, retain or
redistribute it. Click here for important additional terms relating to this
e-mail. http://www.ml.com/email_terms/
--------------------------------------------------------




Archive powered by MHonArc 2.6.24.

Top of Page