Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:45:07+00:00 2026-05-15T15:45:07+00:00

Which is an error-free way to get a http POST in CGI in C?

  • 0

Which is an error-free way to get a http POST in CGI in C?

I’m currently using this. Is it ok? What if “CONTENT_LENGTH” is incorrect and is larger than stdin is; how will read behave then?


char *STDIN = NULL;
char *pointer = getenv("CONTENT_LENGTH");
if(pointer != NULL)
{
    char charlength[5] = "";
    strncat(charlength, pointer, 4); // limit length to a reasonable number
    unsigned long int length = strtoul(charlength, NULL, 0);
    STDIN = malloc(length + 2);
    ssize_t readbytes = read(0, STDIN, length);
    STDIN[readbytes] = '&'; // for use later on in my program
    memset(STDIN + readbytes + 1, (int)'\0', (length + 2) - (size_t)(readbytes + 1));
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:45:08+00:00Added an answer on May 15, 2026 at 3:45 pm

    read(2) will return no more bytes than you asked for. This might leave more data in the stdin file descriptor for reading (in case the client sends a CONTENT_LENGTH of 0 but hands you their /dev/urandom) but that’s okay. Your process is free to go away without reading it all.

    read(2) may return fewer bytes than you ask for. This could be because not all the data has arrived yet and the kernel is tired of blocking, or it could be that the content is smaller than the CONTENT_LENGTH. I’m glad you’re limiting the length to something ‘reasonable’, as it’d be pretty easy to pass in a CONTENT_LENGTH that is the maximum size_t value, or that value minus one, or that value minus two, and play games with your malloc() allocating 0, 1, or 2 bytes, and let you happily scribble all over your memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes in execution I get this error message in VS2010 when trying to free
I am receiving a parse error which is this: Parse error: syntax error, unexpected
This time I have an error which I have been trying again to figure
I get the above error message (which I googled and found is something to
Is there a way to get the address of an object? This is for
I'm using a mysql memory table as a way to cache data rows which
I'm using IntelliJ 11 CE (which is fantastic by the way), but I'm having
I know how to handle error which RecordNotFound But how can I handle Routing
I just encountered a weird error which saying that find is not a member
Here is my manifest file which shows error string types not allowed at android:configChanges

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.