Re: Hi, and a question
by "Steve Mount" <steve(at)saltyrain.com>
|
| Date: |
Wed, 25 Jul 2001 09:49:58 -0400 |
| To: |
"Stephan M. Sprenger" <sms(at)prosoniq.com> |
| Cc: |
<hwg-servers(at)hwg.org> |
| References: |
prosoniq prosoniq2 yerpso |
| |
todo: View
Thread,
Original
|
|
I didn't see the original post, so I'm entering into this late ... sorry...
anytime you get anything from the environment, you have to test it to make
sure it didn't fail. Not doing so is not a big deal, but using a string
pointer that you THINK is pointing to something but is really pointing to
NULL can be a bad thing. I suspect that you are getting a segmentation
violation, and that is causing the server error.
To test this, set one or more of the pointers to NULL by hand and see which
one causes the error. Then you can handle it better. In any case, your
calls to getenv should be immediately followed by a test to handle the error
condition:
client_addr=getenv("REMOTE_ADDR");
remote_host=getenv("REMOTE_HOST");
if (client_addr == NULL && remote_host == NULL) fail();
if (client_addr == NULL) client_addr = remote_host;
else if (remote_host == NULL) remote_host = client_addr;
// or some such kind of error handling
user_agent=getenv("HTTP_USER_AGENT");
if (user_agent == NULL) fail(); // or set it to a default
-------------------------------------------------------------
Steve Mount, Software Engineer steve(at)saltyrain.com
Home Site http://www.saltyrain.com
US Constitution Online http://www.usconstitution.net
Clear your Soul http://www.anonymousconfession.com
----- Original Message -----
From: "Hank Marquardt" <hmarq(at)yerpso.net>
To: "Stephan M. Sprenger" <sms(at)prosoniq.com>
Cc: <hwg-servers(at)hwg.org>
Sent: Wednesday, July 25, 2001 8:04 AM
Subject: Re: Hi, and a question
> Fact is I can't remember the last time I coded for the web in C -- but
> certainly if you're getting memory errors, you've some debugging to do
> and that is certainly what's causing your incomplete header problem --
>
> ... I don't have your source in front of me at the moment, but I'd guess
> you'll have to look at how/where your using the assignments to
> remote_host and user_agent -- just having them assigned NULL shouldn't
> give you an error, but if you blindly start using them you could have
> a problem.
>
> You're assumption that your environment will be differnet from ISP to ISP
> is correct and I have seen the REMOTE_ADDR not set and/or called something
> different.
>
> Frankly this was a good thing to look at as it reminds me how many of
> the niceties are handled for you by scripting languages that you have to
> do yourself in C -- I definitely didn't have my "chase errant memory
> pointers" hat on when I looked at this the first time.
>
> On Wed, Jul 25, 2001 at 08:39:51AM +0200, Stephan M. Sprenger wrote:
> >
> > First off, thanks to all who responded with helpful hints.
> >
> > I might have solved the problem myself, but I'm not quite sure because
> > noone in our company could reproduce it so it's really hard to tell
> > until someone complains about it not working. I will be closely watching
> > our error log and the comments our webmaster gets from our users over
> > the next few days.
> >
> > Here's what I found: when I was trying the suggestion of our webmaster,
> > who suggested calling the CGI program directly from the command line, I
> > noticed that it exits with a memory error after printing the header.
> >
> > Now, what I found out was that this happens right after the following
> > code fragment
> >
> > "Stephan M. Sprenger" schrieb:
> > >
> > > // get user data from environment
> > > client_addr=getenv("REMOTE_ADDR");
> > > remote_host=getenv("REMOTE_HOST");
> > > user_agent=getenv("HTTP_USER_AGENT");
> >
> > When I was accessing the char pointers client_addr, remote_host and
> > user_agent (assuming they were valid) to print them to stdout using my
> > marker find-and-replace routine, the program quits. Of course, these
> > pointers are nil when I call the program from the command line, and I
> > should have checked this in the first place so it's really my stupid
mistake.
> >
> > BUT: Is my assumption true that some ISPs do not assign REMOTE_ADDR and
> > REMOTE_HOST any value so the getenv() call could indeed be returning a
> > NULL pointer? This would explain a lot and could be an explanation for
> > both the mysterious error and its dependency on the ISP rather than the
client.
> >
> > Could this indeed be the cause of the problem, or do you think this is
> > rather unlikely? Any thoughts would be appreciated.
> >
> > --sms
> >
> > Stephan M. Sprenger
> > CTO, Prosoniq Products Software
> > http://www.prosoniq.com
>
> --
> Hank Marquardt <hank(at)yerpso.net>
> http://web.yerpso.net
>
> Web & Database Development in PHP, MySQL/PostgreSQL
> Small Office Networking Solutions - Debian GNU/Linux & FreeBSD
> PHP Instructor - HTML Writers Guild </>
> *** PHP II "The Cool Stuff" starts July 16, 2001
> *** /services/classes/p181.1.html
HWG: hwg-servers mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.