Bizarre date wraparound bug

Lowden, James K LowdenJK at bernstein.com
Wed Oct 17 15:11:41 EDT 2001


Brian, 

I've attached a file of what'd I say is an improved version of
tds_convert_datetime. It dereferences the source pointer instead of assuming
the structure and copying the locations.  And it fails if it can't convert
the date.  (I like my errors noisy.)

I'll work on extra-epoch date handling to replace the error branch.  The
within-epoch branch will no doubt be faster and should remain.  

What's the preferred way for tdslib to notify the user it can't do
something?  Write to stderr?  Write to the system log?  Shut up and pray?  

--jkl


-----Original Message-----
From: Brian Bruns [mailto:camber at ais.org]
Sent: October 16, 2001 7:09 PM
To: TDS Development Group
Subject: [freetds] Re: Bizarre date wraparound bug


from src/tds/convert.c:

TDS_INT tds_convert_datetime(int srctype,unsigned char *src,int
desttype,unsigned char *dest,TDS_INT destlen)
{
TDS_INT dtdays, dttime;
time_t tmp_secs_from_epoch;
  
     switch(desttype) {
          case SYBCHAR:
          case SYBVARCHAR:
          /* FIX ME -- This fails for dates before 1902 or after 2038 */
               if (destlen<0) {
                         memset(dest,' ',30);
               } else {
                    memset(dest,' ',destlen);
               }
               if (!src) {
                    *dest='\0';
                    return 0;
               }
               memcpy(&dtdays, src, 4);
               memcpy(&dttime, src+4, 4);


Anybody wanna take a crack at fixing it?

On Tue, 16 Oct 2001, Craig Davison wrote:

> On Tue, 16 Oct 2001, Michael Peppler wrote:
> 
> > I guess FreeTDS takes a short cut and converts the data to standard
> > time_t format (which is OK for most things, of course).
> 
> Sorry for the numerous posts, but maybe this should be in the FAQ?
> 
> Thanks for your reply.
> 
> 


---
You are currently subscribed to freetds as: [LowdenJK at bernstein.com]
To unsubscribe, forward this message to
$subst('Email.Unsub')

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tds_convert_datetime.c
Type: application/octet-stream
Size: 1108 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20011017/c9f7073c/attachment.obj 


More information about the FreeTDS mailing list