-
Notifications
You must be signed in to change notification settings - Fork 178
Open
Labels
Description
🐛 Bug report
Programs (e.g. sflpef, sfhpef) that uses sf_putints and sf_putfloats may occur buffer overflow.
In (current version) api/c/file.c, Lines 998, 1000, 1037, 1039:
(L998 as example:)
// v defined as char val[1024], *v=val
// Some iterations of i
/* L998 */ v += snprintf(v,1024,"%g,",par[i]);the pointer v moves forwards when iteration goes on, while the length of snprintf always being 1024, this could lead to buffer overlow.
To Reproduce
Steps to reproduce the behavior:
- Use some programs that employs sf_putints (or sf_putfloats)
- It happens.
Debugging:
Desktop (please complete the following information):
- OS: Ubuntu 24.04.02 LTS
- GCC Version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Suggestions
Use a smaller length in snprintf, like:
// Some iterations of i
v+=snprintf(v,1023-i*11,"%g,",par[i]);
//...
snprintf(v,1023-n*11,"%d",par[n-1]);
// I use 11 because maxlen 2147483647 = 10 digits plus 1 char ','
// Actually maybe some const value like 20 is ok.
// Or if the list is overlength, use a dynamic char array.
