473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

getenv and carriage returns

Hi,
We have a legacy cgi app that's written in C. We are encountering
an error when we try to retrieve a cgi environment variable. The
variable we are getting contains a Base64 encoded distinguished name.
If the distinguished is greater than 57 characters in length, a
carriage return is appended to the 58th character. This of course
causes the Base64 decoder to bomb because a carriage return is not a
valid Base64 character. We are using the getenv() function. Is there
some sort of limit on the size of string getenv can return without
placeing a CR?

Any help would be appreciated.

Thanks

Chad
Nov 14 '05 #1
5 2754
ch**@moniqueandchad.com (Chad Paquette) writes:
We have a legacy cgi app that's written in C. We are encountering
an error when we try to retrieve a cgi environment variable. The
variable we are getting contains a Base64 encoded distinguished name.
If the distinguished is greater than 57 characters in length, a
carriage return is appended to the 58th character. This of course
causes the Base64 decoder to bomb because a carriage return is not a
valid Base64 character. We are using the getenv() function. Is there
some sort of limit on the size of string getenv can return without
placeing a CR?


No. `getenv' just returns whatever is provided by the host enviroment;
it never modifies it in any way.

Most likely, whatever sets the envrionment variable (the web server?)
already sets it to a string which contains the carriage return
character.

Martin
Nov 14 '05 #2
Chad Paquette wrote:

Hi,
We have a legacy cgi app that's written in C. We are encountering
an error when we try to retrieve a cgi environment variable. The
variable we are getting contains a Base64 encoded distinguished name.
If the distinguished is greater than 57 characters in length, a
carriage return is appended to the 58th character. This of course
causes the Base64 decoder to bomb because a carriage return is not a
valid Base64 character. We are using the getenv() function. Is there
some sort of limit on the size of string getenv can return without
placeing a CR?


This is off-topic for c.l.c, but...

getenv() isn't modifying the string. If it's returning a string with
CRs in it, it's because CRs are in the environment variable's value.

As for your decoder bombing on this, your decoder is broken. You are
supposed to skip whitespace, as I understand it. Reread the specs.

--

+---------+----------------------------------+-----------------------------+
| Kenneth | kenbrody at spamcop.net | "The opinions expressed |
| J. | http://www.hvcomputer.com | herein are not necessarily |
| Brody | http://www.fptech.com | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+

Nov 14 '05 #3
nrk
Chad Paquette wrote:
Hi,
We have a legacy cgi app that's written in C. We are encountering
an error when we try to retrieve a cgi environment variable. The
variable we are getting contains a Base64 encoded distinguished name.
If the distinguished is greater than 57 characters in length, a
carriage return is appended to the 58th character. This of course
causes the Base64 decoder to bomb because a carriage return is not a
valid Base64 character. We are using the getenv() function. Is there
some sort of limit on the size of string getenv can return without
placeing a CR?

Any help would be appreciated.

No, getenv shouldn't be imposing such any limits, other than the
implementation limits. Keep in mind that you shouldn't try to modify the
string pointer returned by getenv.

<OT>
Looks like its your base64 decoder that's broken. base64 encoding means
lines of 76 characters or less (and yes, you can insert a line break at 58
if you desire). Your decoder should ignore line breaks and other
whitespace and any other character not part of the base64 encoding
(although you should flag an error in the last case). Even if you find the
problem elsewhere, considering you are using it in a CGI environment, I
would fix the decoder to be RFC 1521 compliant.
</OT>

-nrk.
Thanks

Chad


--
Remove devnull for email
Nov 14 '05 #4
Martin Dickopp <ex****************@zero-based.org> wrote in message news:<bv*************@news.t-online.com>...

... `getenv' just returns whatever is provided by the host enviroment;
it never modifies it in any way.


Do you have chapter and verse on that?

From a C89 draft...

"The getenv function searches an environment list, provided by the
host environment, for a string that matches the string pointed to
by name . The set of environment names and the method for
altering
the environment list are implementation-defined."

Of course, it rather depends on what you mean by 'modify', but the
getenv function certainly doesn't return the entire 'environment list'
(whatever that may be); it has to perform _some_ sort of translation.
What that translation is isn't specified by the standard.

But consider if the 'environment list' is stored in unicode, in that
case a getenv function may have to modify the result for characters
not representable by char objects.

--
Peter
Nov 14 '05 #5
ai***@acay.com.au (Peter Nilsson) writes:
Martin Dickopp <ex****************@zero-based.org> wrote in message news:<bv*************@news.t-online.com>...

... `getenv' just returns whatever is provided by the host enviroment;
it never modifies it in any way.
Do you have chapter and verse on that?


C99 7.20.4.5#2, which is the same as the text you quoted.
From a C89 draft...

"The getenv function searches an environment list, provided by the
host environment, for a string that matches the string pointed to
by name. The set of environment names and the method for altering
the environment list are implementation-defined."
IMHO, the "provided by the host environment" part means that if the host
evironment doesn't already impose a requirement that environment strings
must contain certain characters at certain points, the C implementation
is not allowed to insert such characters (as the OP was suspecting might
be happening). There is certainly no requirement in the C language that
strings must contain a carriage return character after the inital 58
characters. :)
Of course, it rather depends on what you mean by 'modify', but the
getenv function certainly doesn't return the entire 'environment list'
(whatever that may be);
Conceptually, the environment list is a list of key-value-pairs (that
follows from the "a string that matches the string" part and the
statement "The getenv function returns a pointer to a string associated
with the matched list member." in paragraph #4, IMHO). The `getenv'
function just returns a value-item from the list.
it has to perform _some_ sort of translation.


I don't see why. In fact, there is at least one implementation where
the environment list is passed to the program as a consecutive list of
('\0' terminated) strings followed by an empty string. Each string
contains at least one '=' character; everthing up to, but not including,
the first '=' character is the key, and everything following it is the
associated value.

In this implementation, no translation of any kind is performed; the
`getenv' function simply returns a pointer to the character after the
'=' character.

Martin
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
2
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
2
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
8
by: TheDude5B | last post by:
Hi, I have some data which is stored in my MySQL database as TEXT. when the data is entered in, it has some carriage returns in it, and this can be seen when querying the data using MySQL Query...
10
by: Protoman | last post by:
What does getenv() do and why would you use it?
2
by: silrandir | last post by:
When calling getenv() globally, the function returns NULL, yet when called from main, returns an appropriate value. #include <stdlib.h> #include <stdio.h> #include <unistd.h> //using...
7
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the...
0
by: markus.shure | last post by:
Hi, I'm noticed a problem testing a JAX-WS client with a WSE server. The JAX-WS client adds carriage returns to a SOAP header element that is signed. This causes the WSE server to raise an...
11
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.