Using fseek and ftell to determine the size of a file has a vulnerability?

后端 未结 5 1555
天涯浪人
天涯浪人 2020-12-11 16:01

I\'ve read posts that show how to use fseek and ftell to determine the size of a file.

FILE *fp;
long file_size;
char *buffer;

fp = fopen(\"foo.bin\", \"r\         


        
5条回答
  •  盖世英雄少女心
    2020-12-11 16:26

    The reason to not use fstat is that fstat is POSIX, but fopen, ftell and fseek are part of the C Standard.

    There may be a system that implements the C Standard but not POSIX. On such a system fstat would not work at all.

提交回复
热议问题