473,785 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2773
ch**@moniqueand chad.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
7321
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 use: 'replace carriage returns with BRs comment=Replace(comment, chr(13), "<br>") but obviously net.! The <pre> tag doesn't sem to help either as the embedded return is
2
2952
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 note field contains carriage returns. When I import a note field that has carriage returns, what shows up in the Access field are vertical black lines where the carriage return should be.
2
2339
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 when pulling data from an SQL database. The thing that frustrates me the most, is that when I use Enterprise Manager, the carriage returns ARE THERE. It looks fine until I pull it out.
8
2224
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 Browser. I want to then display this text within <p> tags when requested from the database. However, the test is formatted without the carriage returns.
10
5675
by: Protoman | last post by:
What does getenv() do and why would you use it?
2
4608
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 namespace std; #define MW_DEBUG "TEST"
7
11206
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 comment through a pop-up that contains a textarea. When the user hits OK on the pop-up, the text in the textarea is sent to a function on the main page. The function inserts the text into the div's text node. Please don't ask why I'm making this...
0
1541
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 error: "The signature or decryption failed". If the carriage returns are removed, the same web service call is successful. I tried replicating the situation with a WSE client. I created a WSE client that adds a SOAP header element that contains a...
11
12602
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 so the user can edit the default email message body before sending the message. But when I populate the large text box (txtBody), I can't get it to include the carriage returns. I've tried vbNewLine, vbCrLf, Chr(10) and Chr(13). I've got the...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.