Search: Home Bugtraq Vulnerabilities Mailing Lists Jobs Tools Beta Programs
Secure Programming
RE: Are bad developer libraries the problem with M$ software? Nov 16 2002 01:00AM
Michael Howard (mikehow microsoft com) (2 replies)
RE: Are bad developer libraries the problem with M$ software? Nov 16 2002 07:03PM
Frank Knobbe (fknobbe knobbeits com) (3 replies)
On Fri, 2002-11-15 at 19:00, Michael Howard wrote:
> "secure" functions are a complete crok - there is no such thing... There
> are some functions that help you get things right, but they do not lead
> to secure code... Anyone who thinks they can do away with the
> "dangerous" functions and replace them with the "safe" 'n' versions (ie;
> strcpy -> strncpy) is kidding themselves.

I disagree. Using strncpy instead of strcpy goes a long way in
preventing buffer overflows. But you are correct, it isn't a magic
bullet that makes code secure. I wouldn't call strncpy 'crok' though.

> if(m_inst.m_fDesktop) {
> wcsncat( szTmp, L"__DESKTOP", MAXSTRLEN(szTmp) );
> wcsncat( szTmp, szExtSrc , MAXSTRLEN(szTmp) );

Wrong use of wcsncat, you are right. wcsncat and strncat append at a
maximum <count> chars. Above example can lead to an overflow since the
second call doesn't take into account the already used chars in <dst>.
Also, MAXSTRLEN is the size of the buffer. Your use ignores the
terminating \0 that strncat will append)

The correct syntax would be:

> wcsncat( szTmp, L"__DESKTOP", MAXSTRLEN(szTmp)-1 );
> wcsncat( szTmp, szExtSrc , MAXSTRLEN(szTmp) - wcsnlen(szTmp) -1 );

As a side note, proper use of snprintf would be:
ret=snprintf(mystr,sizeof(mystr)-1,"Format: %s",var);

Perhaps we should start development of a standardized 'safe' header file
that can contain macros for snprintf, strncat and the like.

Example:
#define safe_snprinf(dst,len,fmt,var)
snprintf(dst,(len>sizeof(dst)-1)?sizeof(dst)-1:len,fmt,var)

#define safe_strcat(dst,src)
strncat(dst,src,sizeof(dst))

#define safe_strncat(dst,src,len)
strncat(dst,src,(len>sizeof(dst)-1-strlen(dst))?
(sizeof(dst)-1-strlen(dst):len)

Although it may be easier to rewrite the libraries with checks
implemented...
My argument is that we should move security into the libraries and tools
and not rely on the developer to implement checks to avoid existing (but
documented) flaws..

Regards,
Frank

[ reply ]
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 07:36PM
Casper Dik (Casper Dik Sun COM) (1 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 11:10PM
Andrew Griffiths (andrewg d2 net au) (1 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 19 2002 03:25AM
Frank Knobbe (fknobbe knobbeits com) (3 replies)
Re: Are bad developer libraries the problem with M$ software? Mar 22 2003 09:56AM
Casper Dik (Casper Dik Sun COM)
Re: Are bad developer libraries the problem with M$ software? Nov 19 2002 10:57PM
Andrew Dalgleish (secprog andrewdalgleish dyndns org) (2 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 22 2002 03:31PM
Frank Knobbe (fknobbe knobbeits com)
Re: Are bad developer libraries the problem with M$ software? Nov 22 2002 07:11AM
Valdis Kletnieks vt edu
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 11:22PM
Andrew Griffiths (andrewg d2 net au)
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 06:54PM
John Viega (viega securesoftware com) (2 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 09:46PM
Frank Knobbe (fknobbe knobbeits com) (1 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 19 2002 09:31AM
Steffen Dettmer (steffen dett de) (1 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 22 2002 03:35PM
Tim van Erven (tripudium chello nl)
Re: Are bad developer libraries the problem with M$ software? Nov 18 2002 06:26PM
Götz Babin-Ebell (babinebell trustcenter de)
Re: Are bad developer libraries the problem with M$ software? Nov 16 2002 03:29PM
Alex Lambert (alambert webmaster com) (1 replies)
Re: Are bad developer libraries the problem with M$ software? Nov 17 2002 01:46AM
Glynn Clements (glynn clements virgin net)







 

Privacy Statement
Copyright 2009, SecurityFocus