xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Use const whenever we point to literal strings (take 1)
@ 2021-05-18 14:01 Julien Grall
  2021-05-18 14:01 ` [PATCH v2 1/2] xen/char: console: Use const whenever we point to literal strings Julien Grall
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Julien Grall @ 2021-05-18 14:01 UTC (permalink / raw)
  To: xen-devel
  Cc: julien, Julien Grall, Andrew Cooper, George Dunlap, Ian Jackson,
	Jan Beulich, Stefano Stabellini, Wei Liu

From: Julien Grall <jgrall@amazon.com>

Hi all,

By default, both Clang and GCC will happily compile C code where
non-const char * point to literal strings. This means the following
code will be accepted:

    char *str = "test";

    str[0] = 'a';

Literal strings will reside in rodata, so they are not modifiable.
This will result to an permission fault at runtime if the permissions
are enforced in the page-tables (this is the case in Xen).

I am not aware of code trying to modify literal strings in Xen.
However, there is a frequent use of non-const char * to point to
literal strings. Given the size of the codebase, there is a risk
to involuntarily introduce code that will modify literal strings.

Therefore it would be better to enforce using const when pointing
to such strings. Both GCC and Clang provide an option to warn
for such case (see -Wwrite-strings) and therefore could be used
by Xen.

This series doesn't yet make use of -Wwrite-strings because
the tree is not fully converted. Instead, it contains some easy
and non-controversial use of const in the code.

Julien Grall (2):
  xen/char: console: Use const whenever we point to literal strings
  tools/console: Use const whenever we point to literal strings

 tools/console/client/main.c |  4 ++--
 tools/console/daemon/io.c   | 15 ++++++++-------
 xen/drivers/char/console.c  |  7 ++++---
 3 files changed, 14 insertions(+), 12 deletions(-)

-- 
2.17.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-26 15:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 14:01 [PATCH v2 0/2] Use const whenever we point to literal strings (take 1) Julien Grall
2021-05-18 14:01 ` [PATCH v2 1/2] xen/char: console: Use const whenever we point to literal strings Julien Grall
2021-05-18 14:39   ` Luca Fancellu
2021-05-18 15:08   ` Jan Beulich
2021-05-18 14:01 ` [PATCH v2 2/2] tools/console: " Julien Grall
2021-05-18 16:01   ` Anthony PERARD
2021-05-26 15:22 ` [PATCH v2 0/2] Use const whenever we point to literal strings (take 1) Julien Grall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).