From: "Timothy B. Terriberry" <tterribe@xiph.org>
To: Rusty Russell <rusty@rustcorp.com.au>,
David Gibson <david@gibson.dropbear.id.au>
Cc: ccan@lists.ozlabs.org
Subject: Re: [PATCH 4/7] crypto/hmac_sha256: Remove undefined memset()
Date: Mon, 17 Apr 2017 21:22:08 -0700 [thread overview]
Message-ID: <58F59470.4070507@xiph.org> (raw)
In-Reply-To: <87wpap5gf6.fsf@rustcorp.com.au>
Rusty Russell wrote:
>> Well.. more precisely, my understanding is that memset(p, x, 0) can't
>> be counted on not to dereference p.
>
> That seems nonsensical, though.
It is nonsensical, but welcome to standards.
C99 Section 7.21.1 "String function conventions" (which includes memset,
as it is in string.h):
"Where an argument declared as size_t n specifies the length of the
array for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of a
particular function in this subclause, pointer arguments on such a call
shall still have valid values, as described in 7.1.4"
C99 Section 7.1.4 "Use of library functions":
"If an argument to a function has an invalid value (such as a value
outside the domain of the function, or a pointer outside the address
space of the program, or a null pointer, or a pointer to non-modifiable
storage when the corresponding parameter is not const-qualified) or a
type (after promotion) not expected by a function with variable number
of arguments, the behavior is undefined."
C99 Section 7.21.6.1 defines memset() as taking an argument size_t n
that specifies the length of the array for that function, but does not
explicitly state that it can be a null pointer, so people have
interpreted this to mean that passing it NULL is undefined behavior.
C89 said the same thing, albeit more briefly:
C89 Section 4.1.6 "Use of library functions":
"Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow. If an argument to a
function has an invalid value (such as a value outside the domain of the
function, or a pointer outside the address space of the program, or a
null pointer), the behavior is undefined."
The detailed description of memcpy() in Section 4.11.2.1 does not
explicitly state otherwise.
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
next prev parent reply other threads:[~2017-04-18 4:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-03 11:11 [PATCH 0/7] Coverity David Gibson
2017-04-03 11:11 ` [PATCH 1/7] .travis.yml: Add support for Coverity Scan David Gibson
2017-04-03 12:14 ` David Gibson
2017-04-03 11:11 ` [PATCH 2/7] failtest: Remove memory leak David Gibson
2017-04-03 11:11 ` [PATCH 3/7] tools: Remove fd leak David Gibson
2017-04-03 11:11 ` [PATCH 4/7] crypto/hmac_sha256: Remove undefined memset() David Gibson
2017-04-04 2:22 ` Rusty Russell
2017-04-05 12:23 ` David Gibson
2017-04-12 23:56 ` Rusty Russell
2017-04-18 4:22 ` Timothy B. Terriberry [this message]
2017-04-24 2:30 ` Rusty Russell
2017-04-03 11:11 ` [PATCH 5/7] crypto/ripemd160: Correct badly sized union member David Gibson
2017-04-03 11:11 ` [PATCH 6/7] ccanlint: Fix leak in do_reduce_features() David Gibson
2017-04-03 11:11 ` [PATCH 7/7] net: Add check for failure of setsockopt() David Gibson
2017-04-04 2:23 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58F59470.4070507@xiph.org \
--to=tterribe@xiph.org \
--cc=ccan@lists.ozlabs.org \
--cc=david@gibson.dropbear.id.au \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.