473,883 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listing the most dangerous parts of C

I am looking for a wish list of things which should be removed from
the C (C99) - due to feature's bad security track record <OT>or
Multithreading unsafety. I need this list for a project intending to
build another (easiest & most powerful) programming language, which
has a two page definition document stating: "... includes C
programming language (C99), except its famous
"avoid-using-this-functions". </OT>

If you would not want to remove a whole function but only the use of
it with certain arguments / parameters, what would those combinations
be like? (Like scanf with %s or %[ arguments )

Probably there are official not to use recommendation lists.
( million times better than this)
http://tele3d.com/wiki/index.php/Par...ncluded_in_t3d

Please, do not circumvent the question by saying all functions except
gets() are safe if used properly. That would be like teaching that
"the ideology of Soviet Union was right, it was the Soviet peoples
fault that the system didn't work.

Juuso Hukkanen
(to reply by e-mail set addresses month and year to correct)
www.tele3d.com

May 10 '06
62 4158
Keith Thompson wrote:
Keith Thompson <ks***@mib.or g> writes:
[...]
Right. Mnemonic identifiers are also a crutch for the weak-minded.
Objects should be identified by serial numbers, preferably in
hexadecimal. I mean, we can't very well trust computers to keep track
of things like this; most of them are prorammed by lazy people.


In particular, some of them are "prorammed" by people who are too lazy
to proofread before posting.


I wonder. Some rammers are consumate professionals. Or billy goats.

--
Some informative links:
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

May 11 '06 #41
On 2006-05-11, Robert Latest <bo*******@yaho o.com> wrote:
On 11 May 2006 03:58:29 GMT,
Jordan Abel <ra*******@gmai l.com> wrote
in Msg. <sl************ **********@rand om.yi.org>
Alternatively, strncpy() could just work in the way we expect :-) I
always have to resort to a reference to remind myself that strncpy is,
in fact, a bit of a charlatan.
Changing it will create problems for code that _does_ use it for what
it's intended to do.


Can you think of a meaningful piece of code that would break if
strncpy() were made safe, and where strncpy could not trivially be
replaced by memcpy?


Doesn't matter if it can be replaced by memcpy - it's still a silent
change.
I think it is a design flaw that a str* function can
return illegal data upon being passed valid parameters ("illegal"
meaning an array of char that is not a valid C string)

robert

May 11 '06 #42
Richard Heathfield <in*****@invali d.invalid> wrote:
(For those who don't know - in Java, *everything* is a pointer.)


I was obviously included in the "those who don't know" category :-)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
May 11 '06 #43
qed <us********@azi llionmonkeys.co m> wrote:
You are recommending strncpy and strncat. These are slow functions that
occasionally leave off the terminating '\0'.


Once again you demonstrate your exquisite detailed knowledge of C string
handling.

strncpy() behaves as you say; strncat() does not, and is a very useful
function.

Richard
May 11 '06 #44
On Thu, 11 May 2006 00:04:15 GMT,
qed <us********@azi llionmonkeys.co m> wrote
in Msg. <3c************ *******@newssvr 11.news.prodigy .com>
You are recommending strncpy and strncat. These are slow functions that
occasionally leave off the terminating '\0'.
Apart from the fact that strncat never leaves off the trailing zero,
what do you know about the execution speed of these functions?
fgets is not an ideal substitute for gets as explained here:
http://www.pobox.com/~qed/userInput.html
That "explanatio n" lumps together several pathological cases of
fgets()'s shortcomings that never occur simultaneously.
The complex number type from C99


is bullshit, like many C99 "features".

robert
May 11 '06 #45
On Thu, 11 May 2006 10:09:38 +0100,
Flash Gordon <sp**@flash-gordon.me.uk> wrote
in Msg. <dj************ @news.flash-gordon.me.uk>
It's a shame because there are a few things from C99
that I might otherwise like to use.


Like what? I'm genuinely interested. So far I haven't met anybody who
found much of C99 useful.

robert
May 11 '06 #46
On 11 May 2006 10:38:24 GMT,
Jordan Abel <ra*******@gmai l.com> wrote
in Msg. <sl************ **********@rand om.yi.org>
Doesn't matter if it can be replaced by memcpy - it's still a silent
change.


True.
May 11 '06 #47
Robert Latest wrote:
On Thu, 11 May 2006 10:09:38 +0100,
Flash Gordon <sp**@flash-gordon.me.uk> wrote
in Msg. <dj************ @news.flash-gordon.me.uk>
It's a shame because there are a few things from C99
that I might otherwise like to use.


Like what? I'm genuinely interested. So far I haven't met anybody who
found much of C99 useful.


Off the top of my head:

compound literals -
passing a constant to a function expecting a struct

stdint.h -
I'm doing database stuff with an old fashioned database where the
data has to be compatible across multiple machines. So defined
width integer types would be useful, as would the fast types.
Still have to handle endianness, of course.

snprintf -
The MS implementation of _snprintf is *not* the same

Increase in the mimimum number of significant characters in
identifiers (I rely on more than the C89 minimum anyway)

long long (a 64 bit or wider integer type would be of use)
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 11 '06 #48
On Wed, 10 May 2006 12:14:56 -0400, "P.J. Plauger"
<pj*@dinkumware .com> wrote:
"Juuso Hukkanen" <ju***********@ tele3d.net> wrote in message
news:bm******* *************** **********@4ax. com...
I am looking for a wish list of things which should be removed from
the C (C99) - due to feature's bad security track record <OT>or
Multithreading unsafety. I need this list for a project intending to
build another (easiest & most powerful) programming language, which
has a two page definition document stating: "... includes C
programming language (C99), except its famous
"avoid-using-this-functions". </OT>

If you would not want to remove a whole function but only the use of
it with certain arguments / parameters, what would those combinations
be like? (Like scanf with %s or %[ arguments )

Probably there are official not to use recommendation lists.
( million times better than this)
http://tele3d.com/wiki/index.php/Par...ncluded_in_t3d

Please, do not circumvent the question by saying all functions except
gets() are safe if used properly. That would be like teaching that
"the ideology of Soviet Union was right, it was the Soviet peoples
fault that the system didn't work.
One very popular wish list is Misra C. (Actuall two, since there's a
revision out too.) It endeavors to tame C by outlawing all sorts of
usages that some people think *might* be misused.


70 pages full of recommndations - That does not leave programmes much
room for making disasterous error - booring. Besides they charge 50$
for their can't-touch-this list.
Another is Microsoft's secure/safer/bounded C, a version of which is
now shipping with VC++ V8. It supplies alternatives to many functions
that can be better bounds checked to avoid storage overwrites. This
work is based on Microsoft's massive bug hunt stimulated by all the
viral attacks on Microsoft software largely written in C.
Good stuff summarizing: MS is advancing the C. They identify C's null
terminated strings as the biggest source of problems and suggest a
whole pattern of safer string functions. Noteworthly MS is also
suggesting a successor for strlen - which has not been suggested in
this thread earlier. MS has (in 9/2005) made a draft to C working
group about these _s safer functions
http://www.open-std.org/jtc1/sc22/wg...docs/n1135.pdf
Quick scanning tells the amount of suggested 'safer functions' appears
to be atleast 68.

The list of suggested safer functions is below. Basically that list
then gives a list of C's problem functions /defines /macros:

asctime_s
bsearch_s
ctime_s
fopen_s
fprintf_s
freopen_s
fscanf_s
fwprintf_s
fwscanf_s
getenv_s
gets_s
gmtime_s
L_tmpnam_s
localtime_s
mbsrtowcs_s
mbstowcs_s
memcpy_s
memmove_s
printf_s
qsort_s
scanf_s
snprintf_s
snwprintf_s
sprintf_s
sscanf_s
strcat_s
strcpy_s
strerror_s
strerrorlen_s
strncat_s
strncpy_s
strnlen_s
strtok_s
swprintf_s
swscanf_s
TMP_MAX_S
tmpfile_s
tmpnam_s
wcrtomb_s
wcrtoms_s
wcscat_s
wcscpy_s
wcsncat_s
wcsncpy_s
wcsnlen_s
wcsrtombs
wcsrtombs_s
wcstok_s
wcstombs_s
wctomb_s
vfprintf_s
vfscanf_s
vfwprintf_s
vfwscanf_s
wmemcpy_s
wmemmove_s
vprintf_s
wprintf_s
vscanf_s
wscanf_s
vsnprintf_s
vsnwprintf_s
vsprintf_s
vsscanf_s
vswprintf_s
vswscanf_s
vwprintf_s
vwscanf_s
Neither is anywhere near perfect, nor universally accepted. Both are
places to start.


hmm, I'll try to spot the worst ones
Thank you
Juuso Hukkanen
(to reply by e-mail set addresses month and year to correct)
www.tele3d.com
May 11 '06 #49

"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:44******** *************** @news.wanadoo.f r...
Rod Pemberton a écrit :

If you really want to get crazy with C, do some of these:
1) eliminate pointers in main
????


Think about 1) and 3). If pointers in main are eliminated, then all memory
allocations would need to static or dynamic.
2) make pointers be associated with a variable before use, not with a data type


lcc-win32: done.
References are pointers associated with an object permanently.
3) eliminate malloc, add dynamic allocation and garbage collection


lcc-win32: done.
The gc is standard in the normal distribution.
4) change C to pass by reference


?????
Why?


Much easier to program. Sorry, this comes from my PL/1 experience. Many C
compilers convert the code to pass by reference for assembly anyway...
5) require separation of string (and other) data and flow control
information


Stack allocation is ok if used correctly. Making all objects heap based
would slow done everything without a lot of gain in security.


That depends on how it is implemented. Dual stacks, ala FORTH, have minimal
overhead on certain systems, including IA-32.
6) give up now, and try Walter Bright's D language...


????

With the above improvements, C can be much easier and safer to program.


Go for it!
Rod Pemberton
May 11 '06 #50

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

Similar topics

4
1898
by: Chris | last post by:
Hello Am really worried, so wondered if anyone could help. My site outgrew itself recently so we've had to make changes to the url structure. I have some important url's like this: www.mysite.com/bluewidgets/, Yet now with the expansion of the site and url structure change (had to be done) we also have urls like: www.mysite.com/country1/bluewidgets/ which serves up identical content to the above first url.
3
1544
by: Mr. B | last post by:
In my application which allows a user to open specific AutoCAD script files (SCR extension), I want to intoduce a listing of the 10 most recently opened files. I know of at least two ways that I could do this: 1) Have a text file that contains the information 2) Write the info to the Registry The first is my easiest as I am familiar with TXT type files. I've never used (and have no idea how to use) a XML type file (let alone the...
3
3104
by: David Callaghan | last post by:
Hi I've just joined tesco broadband. I've come from NTL. If I don't put an index.htm on my NTL home page it justs lists the files in there when any browser visites my page. If I don't put an index.htm on my Tesco home page, I get a:
0
1604
by: kristopher | last post by:
Websites of various subjects ranging from computing to entertainment. TrafficRanking.com says that allsitecafe.com is one of the most VISITED internet sites on the web today! There are over 1,700+ sites linked to allsitecafe.com, and every site has been visited by a human being before inclusion into the allsitecafe.com database of links. You won’t find many dead links at allsitecafe.com – the database is faithfully updated every 4-6 months...
2
2917
by: cj | last post by:
Hi, I'm able to get the listing of (or "Index of") a directory on a website/webserver using HttpWebRequest and HttpWebResponse, but it comes back as an HTML page, similar to what IE or Mozilla/Firefox/Netscape would show. Is there anyway to get the listing in some other form, or do I just have to parse the info myself?
7
4754
by: JohnR | last post by:
Couldn't find it in MSDN. Does anybody have a listing of the message constants that would be received in my application.addmessagefilter routine in VB.net? They are referred to all over MSDN but I can't locate the actual listing of the constants and their values. Thanks, John
1
3380
by: Light | last post by:
Re, I'm having 2 problems with the Telerik trial controls. I'm using the latest release. I'm using 2005 studio and most of the controls show up properly in the designer but the RadMenu does not. It says "Error Creating Control" and then a ton of errors. This occurs both when I use it and in the examples but it does render properly when built. If I drag/drop the control then it shows up properly but when I apply a theme and then...
2
3275
by: Juuso Hukkanen | last post by:
I need a list of multithreading unsafe C (C99) functions/features. comp.programming.threads provided an initial list of C:ish functions, with following ANSI C functions: asctime, gmtime, localtime, ctime, tmpnam, strtok http://www.lambdacs.com/cpt/FAQ.html#Q150 However, extra Googling hinted rand() and srand(), also being unsuitable for multi-threading - opinions? And what is the status of
1
1338
by: TahoeKid | last post by:
I need to modify and assemble the assembler listing files generated from the VS 2005 IDE. A test generated listing file did not assmeble 'as is'. Has anyone tried this? It seems to me the listing file should assemble.
0
9932
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
11109
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
10833
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
10405
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...
1
7959
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
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
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4602
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
3
3227
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.