diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-02-01 01:54:41 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-02-01 01:54:41 +0100 |
commit | 9b41542f4d03c3b59ff458f3569688fbd8fb8bc1 (patch) | |
tree | 686b27f443bde7fb51a3918e70531af7b68e83fd /libguile/strings.c | |
parent | 46f9baf49a8ea4461e8494c75a88b87d0f5c5195 (diff) | |
download | guile-9b41542f4d03c3b59ff458f3569688fbd8fb8bc1.tar.gz |
Fix invalid writes to read-only stringbufs.
* libguile/strings.c (SET_STRINGBUF_SHARED): Don't modify BUF if it's
already marked as shared since it might be a read-only stringbuf.
This error can be caught when linking with GNU ld with "-z relro".
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index d9dc9f009..1839c6ac0 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -86,8 +86,15 @@ #define STRINGBUF_MAX_INLINE_LEN (3*sizeof(scm_t_bits)) -#define SET_STRINGBUF_SHARED(buf) \ - (SCM_SET_CELL_WORD_0 ((buf), SCM_CELL_WORD_0 (buf) | STRINGBUF_F_SHARED)) +#define SET_STRINGBUF_SHARED(buf) \ + do \ + { \ + /* Don't modify BUF if it's already marked as shared since it might be \ + a read-only, statically allocated stringbuf. */ \ + if (SCM_LIKELY (!STRINGBUF_SHARED (buf))) \ + SCM_SET_CELL_WORD_0 ((buf), SCM_CELL_WORD_0 (buf) | STRINGBUF_F_SHARED); \ + } \ + while (0) #if SCM_DEBUG static size_t lenhist[1001]; |