Skip to content

Modern printf format length modifiers lead to garbage output #64

Description

@LeSpocky

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:

#include <fcgi_stdio.h>
#include <stddef.h>

int main( int argc, char *argv[] )
{
    size_t zcntp = 0;

    while ( FCGI_Accept() >= 0 )
    {
        printf( "Content-type: text/html\r\n" 
                "\r\n" );

        puts( "<html><head><title>test fastcgi</title></head><body>" );
        printf( "<p>size_t count (printf): %zu.</p>\n", ++zcntp );
        puts( "</body></html>" );

        fprintf( stderr, "zcntp: %zu\n", zcntp );
    }

    FCGI_Finish();
    
    return 0;
}

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: "

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions