diff options
author | Elliott Hughes <enh@google.com> | 2019-02-05 15:00:13 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2019-02-05 15:00:13 -0800 |
commit | 288465d6e908a4a2b9f8ed27834fc5861bae0ed3 (patch) | |
tree | 60ed2b0f19354c21223fd8539c68a32568fe3c42 /libc/stdio/fmemopen.cpp | |
parent | 5c45c4efb28f103112ed8765386184d802afea73 (diff) |
Avoid writing to a zero-capacity buffer.
Bug: http://b/120752721
Test: ran tests
Change-Id: I3f03ae204ab5de40fd4402a5562c50ffe51ef998
Diffstat (limited to 'libc/stdio/fmemopen.cpp')
-rw-r--r-- | libc/stdio/fmemopen.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libc/stdio/fmemopen.cpp b/libc/stdio/fmemopen.cpp index 9d8c41f12..6e333ba5f 100644 --- a/libc/stdio/fmemopen.cpp +++ b/libc/stdio/fmemopen.cpp @@ -149,7 +149,9 @@ FILE* fmemopen(void* buf, size_t capacity, const char* mode) { } else if (mode[0] == 'w') { ck->size = 0; ck->offset = 0; - ck->buf[0] = '\0'; + if (capacity > 0) { + ck->buf[0] = '\0'; + } } return fp; |