Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #35982

Re: Counted string

Path csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From "Rod Pemberton" <buzz@notnotnontnooatno.cmm>
Newsgroups comp.lang.forth
Subject Re: Counted string
Date Fri, 23 Jan 2015 20:17:25 -0500
Organization Aioe.org NNTP Server
Lines 37
Message-ID <op.xsx0jbi0v6dtjm@localhost> (permalink)
References <174b22de-2454-4e17-ac18-6a1333ec408f@googlegroups.com>
NNTP-Posting-Host i+Urkql2cL38hhKqzSWEjg.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed; delsp=yes
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Opera Mail/12.16 (Linux)
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.forth:35982

Show key headers only | View raw


On Mon, 19 Jan 2015 02:54:49 -0500, Marek Brunda <marekb@phoenics.org>  
wrote:

> Hi, can anyone explain me, what's wrong with counted strings? Maybe it's  
> a stupid question, but I've never understood it. Thanks

This has been discussed many times here in the past.
You can search the Google Groups archive of this Usenet group.

Nul-terminated strings replaced counted strings for the most part
many decades ago in most programming languages, e.g., 1970's or 1980's.

The problem back then with counted strings was that the count could
be changed, but the length of the string wouldn't be.  I.e., there
is a mismatch in the size of the count and the actual length of the
string.  If the count is too short, then the string is truncated.
This isn't a problem.  If the count is too large, then you have a
very serious issue.  More space for a new larger string wasn't
allocated.  The string is the same size, but the count is larger.
So, the oversized count value allows you to access data PAST the
actual end-of-string.  I.e., you can read data you shouldn't have
access to, or write to variables you shouldn't have access to.
This is the same technique used by hackers for buffer overflow.

(FYI, to prevent flame war, there are those here who claim that
can't actually happen in Forth ...)

Languages like C which use nul-terminated strings frequently
only need to detect the end-of-string.  They generally don't
need to know the string's length.  So, not counting the length
of a string and just appending a nul-terminator to create a
string increased code speed.  Of course, not terminating
a string in C, which happens with some string functions under
certain conditions, can cause overruns or unintended access too.


Rod Pemberton

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-18 23:54 -0800
  Re: Counted string "Elizabeth D. Rather" <erather@forth.com> - 2015-01-18 22:08 -1000
    Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-19 09:36 +0000
      Re: Counted string "HAA" <someone@microsoft.com> - 2015-01-20 00:21 +1100
        Re: Counted string Coos Haak <chforth@hccnet.nl> - 2015-01-19 14:44 +0100
      Re: Counted string Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-01-20 00:45 -0800
        Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-20 13:12 +0000
          Re: Counted string Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-01-21 01:05 -0800
            Re: Counted string albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-01-21 10:54 +0000
    Re: Counted string lehs <skydda.barnen@gmail.com> - 2015-01-30 11:18 -0800
  Re: Counted string Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2015-01-21 11:58 +0100
    Re: Counted string "HAA" <someone@microsoft.com> - 2015-01-22 11:49 +1100
  Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-23 20:17 -0500
    Re: Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-26 11:21 -0800
      Re: Counted string Mark Wills <markwills1970@gmail.com> - 2015-01-26 12:11 -0800
        Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-26 21:55 -0500
          Re: Counted string Julian Fondren <julian.fondren@gmail.com> - 2015-01-26 19:46 -0800
            Re: Counted string albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-01-27 12:07 +0000
              Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:13 -0500
            Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-27 15:43 +0000
              Re: Counted string Marek Brunda <marekb@phoenics.org> - 2015-01-27 13:28 -0800
                Re: Counted string Elizabeth D Rather <erather@forth.com> - 2015-01-27 13:06 -1000
                Re: Counted string anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 17:33 +0000
            Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:07 -0500
              Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-28 20:16 -0500
              Re: Counted string Coos Haak <chforth@hccnet.nl> - 2015-01-29 03:14 +0100
      Re: Counted string Pablo Hugo Reda <pabloreda@gmail.com> - 2015-01-26 12:14 -0800
        Re: Counted string "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-26 21:55 -0500
        Re: Counted string Ron Aaron <rambamist@gmail.com> - 2015-01-27 06:55 +0200
          Re: Counted string "Alex McDonald" <blog@rivadpm.com> - 2015-01-27 14:46 +0000
      Re: Counted string "Elizabeth D. Rather" <erather@forth.com> - 2015-01-26 11:25 -1000

csiph-web