-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modern printf format length modifiers lead to garbage output #64
Comments
for me is not dependant of fcgi, is dependant of the compiler you use. |
Not really. It depends on what C dialect you instruct your compiler to use and what's the default of the compiler. Speaking of GCC, according to https://stackoverflow.com/a/14737642 and the manual C11 (implying the older C99) is default since GCC 5.5 which was released in 2017. I would assume most C code written today uses at least some features of C99. So from my point of view a library not supporting an over 20 years old language standard, is buggy. (FWIW, I do not expect anyone to fix this. You can consider the ticket be the public documentation of what happens, so other users can find the information and don't have to dig by themselves.) |
is what is say, is dependent of the compiler/compiler options or define that interfere on compiler compliance. you tried to do something like that:
cf: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html |
It's not about the options used to build fcgi itself. This works, I don't care about those. It is about the options I build my own application with, which I link against libfcgi then. The special thing libfcgi does is replacing stuff by its own implementations which is usually in the libc. This is the way to go explained in fcgi documentation especially if you migrate cgi code to libfcgi. You should not include stdio.h but fcgi_stdio.h as written here: https://fastcgi-archives.github.io/fcgi2/doc/fcgi-devel-kit.htm#S3 If I build my own application with C99 or newer now (Note: this is default with any recent compiler, gcc switched to C11 by default with version 5 released back in 2015), and link that application to libfcgi, the compiler will happily do so without complaining. If I use the above mentioned C99 format specifiers in my app code, libfcgi will produce wrong results at runtime. In other words: if I start a new webapp today and build and link it against a probably pre-built libfcgi (like libfcgi-dev from Debian) with default compiler options, I will sooner or later run into this problem. I see several solutions to this:
I don't say this is easy and I don't demand a fix from anyone. However I still consider this a problem users of fcgi should be aware of. 😃 |
C99 introduced new length modifiers. In addition to the well known and supported 'l', 'L', and 'h' we have 'hh', 'll', 'j', 'z', and 't' now. (See https://en.cppreference.com/w/c/io/fprintf for reference for example.) Those are not supported by fcgi, however the compiler supporting C99 or newer happily allows to use them without warning. The output is cut off however at the unknown length modifier.
Code example:
In the
printf()
statement the output is cut off at the '%' and you'll never see the.</p>\n
in the output. The output to stderr is also cut off like this without printing any number:"zcntp: "
The text was updated successfully, but these errors were encountered: