473,472 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

easy CGI w/ C

I'm here to promote my C library project for writing CGI progs in C.
The project is called Stutter and can be found at
http://freshmeat.net/projects/stutter

I'm horrible, I know. =)

-Matt
Nov 14 '05 #1
1 1724

On Sat, 17 Apr 2004, Matt Mayers wrote:

I'm here to promote my C library project for writing CGI progs in C.
The project is called Stutter and can be found at
http://freshmeat.net/projects/stutter

I'm horrible, I know. =)


Not at all! We all love topical discussion of real-world standard C
programming! :)

% gcc -W -Wall -ansi -pedantic -O2 -c stutter.c
stutter.c: In function `getParam':
stutter.c:49: warning: implicit declaration of function `strcasecmp'
stutter.c:74: warning: char format, different type arg (arg 3)
% gcc -W -Wall -ansi -pedantic -O2 -c stutter_ex.c
stutter_ex.c:5: initializer element is not constant
stutter_ex.c:6: initializer element is not constant
stutter_ex.c:7: initializer element is not constant

All of gcc's criticisms are right on.
'strcasecmp' needs to be declared before you can call it, and defined
somewhere. More importantly, *you* can't define 'strcasecmp' *anywhere*,
because names beginning with 'str' and another letter are reserved for
the implementation's use only.
You have in "stutter.c" the line
sscanf(__pQueryString, "%s", &__qs);
That's wrong, because 'sscanf' is expecting a pointer to 'char' as its
third argument, and the value of the expression '&__qs' is a pointer
to array[MAX_QS_SIZE] of 'char'. More importantly, you can't use the
name '__qs' either, because the implementation *also* reserves names
beginning with two underscores for its own use. I presume you're worried
that if you use just plain old 'qs' as the identifier, the client code
will come up with naming conflicts. You should read [one of] the
section[s] on the 'static' keyword in a good book; 'static' will help
you make sure "package-local" variables like 'qs' don't escape.
In 'stutter_ex.c', you have some global variables you're trying to
initialize with the results of function calls. A little thought will
show you that you can't do that: when would those functions be called?
Before 'main'? *Nothing* in standard C happens before 'main'! So you
need to move their initializations --- in fact, their entire definitions
--- inside the body of 'main'.

Logic bug: Inside 'getParam', you're assigning the result of 'getenv'
to '__pQueryString', and then immediately calling 'getenv' again. This
will, on many systems, *overwrite* the old string's data, effectively
trashing the value of the string pointed to by '__pQueryString'. This
is a major bug, and needs fixing badly!

Silliness: That 'while' loop with the increment inside it is just a
silly way of writing '__qscount += strlen(__pQSDummy);'

Silliness: Your "check for overflow" inside 'getParam' is kind of
silly. It's really checking whether the user (the web interface)
entered an extra-long line; no "buffer overflow" in the usual sense of
the term will ever occur. Wouldn't it be better to go ahead and handle
long lines, since machine-generated queries often end up really long
anyway? Your users might thank you, and it's a great way to get
introduced to non-trivial uses for 'realloc'. (Also, your line length
is WAAAAY too long in those comments. 80 characters, /please!/)

Slight silliness: 'IntFromHex' is ASCII-specific. This might be
perfectly fine; I wouldn't be surprised if the relevant Internet
standards for CGI specified that all URL-thingies were supposed to
be encoded in ASCII. But you could have replaced the whole thing
with

unsigned hex;
sscanf(__pChars, "%2x", hex);
return hex;

and saved yourself some time and disk space.
I see that you used 'static' correctly on 'IntFromHex', so you should
have known better with all those other variables and functions.

The comment on 'printBasicHeader' shows that you're a little shaky
on what exactly the difference is between arrays and pointers. Google
"'Chris Torek' 'The Rule'".
Also, I've recently converted to the practice of using 'puts' instead
of 'printf' whenever possible. It's a religious issue, I think, but
I'll mention it anyway. One rationale is that 'puts' might shave a few
nanoseconds off your execution time, by bypassing all of 'printf''s
format-specifier interpreter code.

3 is not a portable argument to 'exit', and 'theSize' is never used
in file "stutter_ex.c".

Finally, an ease-of-use suggestion: You might consider adding a
function to the library that would make HTML forms output easier
on the eye. For example, the client could replace

printf("<form action=\"/cgi-bin/stutter_ex\" method=\"GET\">");

with something like

HTMLdump("<form action='/cgi-bin/stutter_ex' method='GET'>");

and then the 'HTMLdump' function would take care of replacing all
's with "s. You could even reuse some of your existing code! ;-)

HTH, and thanks for sharing,
-Arthur
Nov 14 '05 #2

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

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
4
by: NBURGAN | last post by:
We are currently searching for a reporting tool with graphics for our end users who are using Oracle's standard edition. We are not using the Oracle's AS. The tool needs to be easy to use and...
19
by: Canon EOS | last post by:
Hi, I am really new in .net and pocket PC development. My background are purely C/C++/VC++. Have developed on Mobile Java for a year and felt completely insecure with it because all codes can...
8
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the...
2
by: Thomas | last post by:
Hi, I there anybody here that are designing applications with asp.net without html in aspx files? The problem is that aspx files is a dependency, and I would like to avoid having that...
5
by: LedZep | last post by:
What up, All I need to do is enter a last name in a text box, query a MSAccess database and display the name with the corresponding columns. This is no problem, but when there are more than one...
1
by: Mad Scientist Jr | last post by:
can someone explain how to simply populate a grid in .net ? the way i understand it, there is no more msflexgrid, and instead is this new control that has to be tied to a dataset, and it is a real...
13
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. :...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
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...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...

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.