freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Lowden, James K" <LowdenJK AT bernstein.com>
- To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
- Subject: RE: Losing last character of TEXT fields
- Date: Tue, 9 Jul 2002 11:12:46 -0400
> > @@ -115,18 +116,20 @@
> >
> > switch(desttype) {
> > case SYBTEXT:
> > - case SYBCHAR:
> > cplen = srclen > destlen ? destlen : srclen;
> > memcpy(dest, src, cplen);
> > - dest[cplen-1] = '\0';
> > + /* 2001-06-15 Deutsch changed [cplen-1] to [cplen] */
> > + dest[cplen] = '\0';
> > return strlen(dest);
> > - case SYBBINARY:
> > + case SYBCHAR:
> > cplen = srclen > destlen ? destlen : srclen;
> > memcpy(dest, src, cplen);
> > - return cplen;
> > + dest[cplen]='\0';
> > + return strlen(dest);
> > }
> >
> I'm not agree. I prefer loosing a character to a buffer overflow.
> Perhaps seem that definition of srclen and destlen is different.
> srclen is the len of input string without counting terminator
> (there is no
> terminator) while destlen if the len of the output buffer
> counting needed terminator.
> Is that right ?
> Then cplen should be the minimun of srclen and (destlen-1)
>
> That for read a varchar(255) we must pass a 256 char buffer.
I think you're right, Frediano; the code is still broken.
We shouldn't null-terminate unless destlen is -1. If the destination buffer
is too small, we should call the error handler and return -1. So say the
docs. Eric?
--jkl
-
Losing last character of TEXT fields,
L J Bayuk, 07/07/2002
- <Possible follow-up(s)>
- RE: Losing last character of TEXT fields, Lowden, James K, 07/08/2002
- RE: Losing last character of TEXT fields, Eric Deutsch, 07/08/2002
- RE: Losing last character of TEXT fields, Brian Bruns, 07/08/2002
- RE: Losing last character of TEXT fields, Lowden, James K, 07/08/2002
- RE: Losing last character of TEXT fields, James K. Lowden, 07/08/2002
- RE: Losing last character of TEXT fields, ZIGLIO Frediano, 07/09/2002
- RE: Losing last character of TEXT fields, Bill Thompson, 07/09/2002
- RE: Losing last character of TEXT fields, Lowden, James K, 07/09/2002
- RE: Losing last character of TEXT fields, Bill Thompson, 07/09/2002
- RE: Losing last character of TEXT fields, Brian Bruns, 07/09/2002
- RE: Losing last character of TEXT fields, Lowden, James K, 07/09/2002
- RE: Losing last character of TEXT fields, Eric Deutsch, 07/09/2002
- RE: Losing last character of TEXT fields, Brian Bruns, 07/09/2002
- RE: Losing last character of TEXT fields, Eric Deutsch, 07/09/2002
- RE: Losing last character of TEXT fields, Michael Peppler, 07/09/2002
- RE: Losing last character of TEXT fields, Lowden, James K, 07/09/2002
- RE: Losing last character of TEXT fields, Eric Deutsch, 07/09/2002
- RE: Losing last character of TEXT fields, Lowden, James K, 07/09/2002
Archive powered by MHonArc 2.6.24.