Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: INT05 compliance via ambiguity

...

Code Block
bgColor#FFCCCC
enum { NO_FILE_POS_VALUES = 3 };

int opener(
  FILE* file, 
  unsigned int *width, 
  unsigned int *height, 
  unsigned int *data_offset
/* ... */ ) {
  unsigned int file_wrc;
  unsigned int file_h;
  unsigned int file_o;fpos_t offset;

  int rc;
  fpos_t offset;/* ... */

  memset(&offset, 0, sizeof(offset));

  if (file == NULL) { return EINVAL; }

  if (fscanf(file, "%u %u %u", &file_w, &file_h, &file_o)  
      != NO_FILE_POS_VALUES) { return EIO; }

/* Read in data from file */

  rc = fsetpos(file, &offset);
  if (rc != 0 ) { return rc; }

  /*width = file_w;
  *height = file_h;
  *data_offset = file_o;... */

  return 0;
}

However, because only the return value of a fgetpos() call is a valid argument to fsetpos(); passing an fpos_t value that was created in any other way may not work. It is possible that the position will be set to an arbitrary location in the file.

...

Code Block
bgColor#CCCCFF
enum { NO_FILE_POS_VALUES = 3 };

int opener(
  FILE* file, 
  unsigned int *width, 
  unsigned int *height, 
  unsigned int *data_offset
/* ... */) {
  unsigned int file_wrc;
  unsigned int file_h;
  unsigned int file_o;fpos_t offset;

  int rc;
  fpos_t offset;/* ... */

  if (file == NULL) { return EINVAL; }

  rc = fgetpos(file, &offset);
  if (rc != 0 ) { return rc; }

  if (fscanf(file, "%u %u %u", &file_w, &file_h, &file_o)  
      != NO_FILE_POS_VALUES) { return EIO; }/* Read in data from file */

  rc = fsetpos(file, &offset);
  if (rc != 0 ) { return rc; }

  /*width = file_w;
  *height = file_h;
  *data_offset = file_o;... */

  return 0;
}

Risk Assessment

...