fastcgipp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fastcgipp-users] Re: form handler crashing if posts key missing


From: Axel von Bertoldi
Subject: Re: [Fastcgipp-users] Re: form handler crashing if posts key missing
Date: Tue, 5 Jan 2010 17:29:45 -0700

Hi there,

Just looked at the relevant code and have found the problem; it's related to Post::Type. It's not a difficult problem to fix, but might be hard to explain so bare with me. Environment::requestVarExists checks if post data exists for the associated key and will return true if the post data is of type Post::Type::file or Post::Type::form. Environment::requestVarGet also checks if post data exists for the associated key before retrieving it. However, when I wrote requestVarGet I assumed it would only be used for Post::Type::form data. I think that was a faulty assumption. So requestVarGet and requestVarExists are not consistent.

Mike, strangely, in your above example you have made the same mistake I did; you check the existence of post data for the given key, and then assume it's Post::Type::form data. If it's not, environment.posts["name"].value will be undefined (or empty, Eddie?) and you get a crasher.

So, the solution is to make Environment::requestVarExists and Environment::requestVarGet consistent.

Option 1: Change requestVarExists to return true if a value for the key exists AND the data is of type Post::Type::form
Option 2: Change requestVarGet to return the shared array at Post::data if the data for the associated key is of type Post::Type::file.

Eddie, do you have a preference? I suspect #2 would be more useful.

Cheers,
axel.

On Tue, Jan 5, 2010 at 1:31 PM, Eddie Carle <address@hidden> wrote:
On Wed, 2010-01-06 at 00:13 +1030, address@hidden wrote:
> Hmm, looks like I may have solved this one too ..
>
> If I change the form's enctype to 'multipart/form-data', blank form
> fields are no
> longer fatal.
> Does this sound right?
>
> Mike
>
> Note: I've included the original post below as lists.gnu.org seemed to
> be down
> and I'm not sure it ever made it through:
>
> /////////////////////////////////////////////////////////////////
>
> I am having issues with a form handling program crashing whenever an
> expected
> environment.posts[ ] key is not present.
>
> I can test for the existence of the key using
> environment.postVariableExists(),
> but all attempts to handle this so far have not worked and the program
> still crashes.
>
> For example:
>
> std::string input_name;
> if (environment.postVariableExists("name")) {
> input_name = environment.posts["name"].value;
> }
> else {
> input_name = "empty";
> }
>
> // now do something with input_name;
>
>
> Program works fine if key is present, but crashes if not.
> I would expect that the contents of the 'if' block would only be
> examined if the
> key existed, but it appears that maybe that isn't the case.
>
> Any suggestions on how to handle missing POST data gratefully
> accepted.
>
> I am using Nginx + FastCGI is that is relevant.

multipart/form-data and application/x-www-form-urlencoded are the two
types of post data handled. Both are handled by separate handler
functions. See Fastcgipp::Http::Environment<charT>. It would appear as
though the handler for application/x-www-form-urlencoded does not check
for valid keys before looking them up. This is not necessarily a bug,
but it may be.
--
       Eddie Carle





reply via email to

[Prev in Thread] Current Thread [Next in Thread]