Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • L libao
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 35
    • Issues 35
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Xiph.Org
  • libao
  • Issues
  • #2196

Closed
Open
Created Apr 23, 2015 by Raúl Salinas-Monteagudo@raulsalinas

ao_open_file: Race condition in checking for file

When "not overwrite" is specified, ao_open_file() will try to first open it for reading and this does not fail, open it for writing.

if (!overwrite) {
  /* Test for file existence */
  file = fopen(filename, "r");
  if (file != NULL) {
    fclose(file);
    errno = AO_EFILEEXISTS;
    return NULL;
  }
}


file = fopen(filename, "w");

There is a TOCTTOU condition, the file could have been created by someone else after the check.

A non-racy way to create it would be to use

file=fopen(filename, "wx");  

and checking for the errno E_EXIST.

If this is not portable enough, open( ... , O_CREAT|O_EXCL) could be used.

Assignee
Assign to
Time tracking