Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider (sch jbop) (X_X)@==(Q_Q)@

The rename() function has the following prototype.

Code Block
int rename(char const char *old, char const char *new);

If the file referenced by new exists prior to calling rename(), the behavior is implementation-defined. For portability, you must ensure that the file referenced by new does not exist when rename() is invoked.

...

Code Block
bgColor#ffcccc
/* program code */
char const char *old = "oldfile.ext";
char const char *new = "newfile.ext";
if (rename(old, new) != 0) {
  /* Handle rename failure */
}
/* program code */

...

Code Block
bgColor#ccccff
/* program code */
char const char *old = "oldfile.ext";
char const char *new = "newfile.ext";
FILE *file = fopen(new, "r");

if (!file) {
  if (rename(old, new) != 0) {
    /* Handle rename failure */
  }
} else {
  fclose(file);
  /* handle error condition */
}
/* program code */

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

FIO10-A

2 ( medium ) 2 (

probable )

2 ( medium )

P8

L2

Related Vulnerabilities

...