Skip to Content.
Sympa Menu

freetds - Re: [freetds] dblib patch

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] dblib patch
  • Date: Fri, 1 Jul 2005 16:08:47 +0200

>
> 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




Archive powered by MHonArc 2.6.24.

Top of Page