You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Do not use deprecated or obsolsecent functions when more secure equivalent functions are available.
Deprecated functions are defined by the C99 standard and Technical Corrigenda. Obsolescent functions are defined by this guideline.

Deprecated Functions

The gets() function was deprecated by Technical Corrigendum 3.

Obsolescent Functions

The following functions are obsolescent.

asctime()

atof()

atoi()

atol()

atoll()

bsearch()

ctime()

fopen()

fprintf()

freopen()

fscanf()

fwprintf()

fwscanf()

getenv()

gmtime()

localtime()

mbsrtowcs()

mbstowcs()

memcpy()

memmove()

printf()

qsort()

remove()

rename()

rewind()

setbuf()

snprintf()

sprintf()

sscanf()

strcat()

strcpy()

strerror()

strncat()

strncpy()

strtok()

swprintf()

swscanf()

tmpfile()

tmpfile_s()

tmpnam()

tmpnam_s()

vfprintf()

vfscanf()

vfwprintf()

vfwscanf()

vprintf()

vscanf()

vsnprintf()

vsprintf()

vsscanf()

vswprintf()

vswscanf()

vwprintf()

vwscanf()

wcrtomb()

wcscat()

wcscpy()

wcsncat()

wcsncpy()

wcsrtombs()

wcstok()

wcstombs()

wctomb()

wmemcpy()

wmemmove()

wprintf()

wscanf ()

 

 

 

Noncompliant Code Example

In this noncompliant code example, strcat() and strcpy() are used.

enum { BUFFERSIZE=256 };

void complain(const char *msg) {
  static const char prefix[] = "Error: ";
  static const char suffix[] = "\n";
  char buf[BUFFERSIZE];

  strcpy(buf, prefix);
  strcat(buf, msg);
  strcat(buf, suffix);
  fputs(buf, stderr);
}

Compliant Solution

In this compliant solution, strcat() and strcpy() are replaced by strcat_s() and strcpy_s().

enum { BUFFERSIZE=256 };

void complain(const char *msg) {
  static const char prefix[] = "Error: ";
  static const char suffix[] = "\n";
  char buf[BUFFERSIZE];

  strcpy_s(buf, BUFFERSIZE, prefix);
  strcat_s(buf, BUFFERSIZE, msg);
  strcat_s(buf, BUFFERSIZE, suffix);
  fputs(buf, stderr);
}

Risk Assessment

The deprecated and obsolescent enumerated in this guideline are commonly associated with software vulnerabilities.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

MSC33-C

high

high

medium

P9

L2

Automated Detection

Unknown.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

[[Burch 06]]
[[CERT 06c]]
[[ISO/IEC 9945:2003]]
[[ISO/IEC 9899:1999]] Section 7.21, "String handling <string.h>"
[[ISO/IEC 23360-1:2006]]
[[ISO/IEC TR 24731-1:2007]]
[[ISO/IEC PDTR 24731-2]]
[[MISRA 04]] Rule 20.4
[[Seacord 05a]] Chapter 2, "Strings"


      49. Miscellaneous (MSC)      50. POSIX (POS)

  • No labels