Public bug reported:

Hi,
I am learning C and had a strange bug when allocating values into some calloc'd 
memory with fscanf.
Later calls to fscanf would overwrite previously set values to zero.  I am 
using an AMD athlon 64 bit cpu on
a 32bit Fiesty Fawn version of Ubuntu and I think that the std library must be 
ignoring the type conversion modifier
and just writing a larger type into the memory.
Attached is a simple program called fscanfbug.c which reproduces the problem.
Is this something I should just work around or should this be fixed in glibc?
Thanks,
     Alysander

//Number 5
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int main (int argc, char *argv[]) {
  int8_t *numarray = NULL;
  FILE *numfile = NULL;
  numarray = calloc(10, sizeof(int8_t));
  numfile = fopen("fscanfbug.c", "r");
  fscanf(numfile, "//Number %"PRId8, &numarray[8]);
  fscanf(numfile, "//Number %"PRId8, &numarray[7]);
  printf("The 8th number is: %"PRId8"\n", numarray[8]);
  printf("The 7th number is: %"PRId8" (shouldn't this be the same as above?) 
\n", numarray[7]);  
  fclose(numfile);
  free(numarray);
  return 1;
}

** Affects: glibc (Ubuntu)
     Importance: Undecided
         Status: Unconfirmed

-- 
fscanf out of bounds write
https://bugs.launchpad.net/bugs/110917
You received this bug notification because you are a member of Ubuntu
Bugs, which is the bug contact for Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to