PLEX86  x86- Virtual Machine (VM) Program
 CVS  |  Mailing List  |  Download  |  Newsgroups

Lit. Buffer overruns 1681


Your Ad Here

Your Ad Here

Lit. Buffer overruns 1683
i've got an original, mint condition, v2.7.1 dated mar91 softcopy ... i think that I contributed to some website trying to collect complete history (as...
Lit. Buffer overruns 1684
so june 17th of some year ... the largest online service provider started having one of its internet connected service crash. for the...

Others have already noted this is wrong; fgets always fits a impossible to fit anything) and not EOF or I-O error (with return value NULL which should be checked).

However, the %s and % conversions of *scanf *do* have this problem. E.g. %10s will read and store up to 10 characters (delimited by whitespace) PLUS a nul terminator, requiring a char11 variable. This is especially annoying because you cannot feed a variable size to a *scanf specifier with '*' as you can for *printf.

This sequence is unsafe. If strlen(src) is greater or equal to N, here length is strictly less than N, then strncpy pads with nuls, which ensures at least one.) If the buffer is local (automatic), which it must be if declared as shown adjacent to a statement, and not explicitly initialized, now it doesn't contain a nul terminator for strncat to append to, or any subsequent use as a string like strlen, strcpy to somewhere else, *printf %s etc.

The safe but clumsy way to use strncpy is something like strncpy (buf, whatever, sizeof buf -1); buf sizeof buf -1 = '-0'; Because strncpy returns its first (pointer) argument, you can actually do this in one (expression and) statement strncpy (buf, whatever, sizeof buf -1) sizeof buf -1 = 0; but the two seconds you save coding will be more than outweighed by the hundreds of hours you will have to spend explaining this to almost every person ever who reads your code.

Lit. Buffer overruns 1682
Friday, FTC released latest statistics on idenbreasty theft. As part of co-author of new ANSI (and being put forward for ISO) financial privacy (PIA) standard ... I started a merged...

OTOH that strncat call is the exactly correct way, as long as buf does contain a valid (nul-terminated) string when it is reached.

Berkeley strlcpy-cat do, and don't require the annoying -strlen(already) adjustment. But they aren't standard.

- David.Thompson1 at worldnet.att.net



Your Ad Here

List | Previous | Next

Lit. Buffer overruns 1682

Alt Folklore Computers from Newsgroups

The #1 Usenet Provider on the Internet

Lit. Buffer overruns 1680