Skip to Content.
Sympa Menu

freetds - RE: Losing last character of TEXT fields

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • 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




Archive powered by MHonArc 2.6.24.

Top of Page