Do not use deprecated or obsolescent 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.
The gets function was deprecated by Technical Corrigendum 3.
| The following functions are obsolescent and should be avoided in favor of either the portable equivalent or, if available, the more secure alternatives defined in \[[ISO/IEC TR 24731-1|AA. Bibliography#ISO/IEC TR 24731-1-2007]\] Extensions to the C Library, --- Part I: Bounds-checking interfaces, and \[[ISO/IEC TR 24731-2|AA. Bibliography#ISO/IEC TR 24731-2-2010]\] Extensions to the C Library, --- Part II: Dynamic Allocation Functions. (Several of the "Portable Equivalent" entries are specified in the POSIX standard.) | 
| Function | Portable Equivalent | Secure Alternative | 
|---|---|---|
|   | 
 |   | 
|   |   | 
 | 
|   |   | 
 | 
|   |   | 
 | 
|   |   | 
 | 
|   | 
 |   | 
|   | 
 |   | 
|   |   |   | 
|   |   | 
 | 
|   | 
 |   | 
|   | 
 |   | 
|   |   |   | 
|   | 
 |   | 
|   |   |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 | 
 | 
|   | 
 | 
 | 
|   |   | 
 | 
|   |   | 
 | 
|   | 
 |   | 
|   |   |   | 
|   | 
 |   | 
|   | 
 |   | 
|   |   |   | 
|   |   |   | 
|   | 
 |   | 
|   |   |   | 
|   |   |   | 
|   |   |   | 
|   | 
 |   | 
|   |   |   | 
|   |   | 
 | 
|   |   |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   |   |   | 
|   | 
 |   | 
|   |   |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
|   | 
 |   | 
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);
}
 | 
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);
}
 | 
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 | 
Unknown.
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
ISO/IEC 9899:1999 Section 7.21, "String handling <string.h>"
MISRA Rule 20.4
| \[[Burch 2006|AA. Bibliography#Burch06]\] \[[CERT 2006c|AA. Bibliography#CERT 06c]\] \[[Seacord 2005a|AA. Bibliography#Seacord 05a]\] Chapter 2, "Strings" | 
      49. Miscellaneous (MSC)      MSC35-C. Do not include any executable statements inside a switch statement before the first case label