[haiku-commits] haiku: hrev43445 - src/servers/registrar

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 9 Dec 2011 15:29:21 +0100 (CET)

hrev43445 adds 1 changeset to branch 'master'
old head: 232ba1d6f62b50b300f5a4c28d931a7b2eb58be7
new head: 6ba5fa4d64c5cdda19404c9d8360d809d9546144

----------------------------------------------------------------------------

6ba5fa4: Ensure 0 termination of the buffer being converted to a string.
  
  The file content isn't normally 0 terminated, so making a string out of
  it would usually result in reading beyond the allocated buffer to find
  the string length, possibly leading to a crash.

                                            [ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev43445
Commit:      6ba5fa4d64c5cdda19404c9d8360d809d9546144
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6ba5fa4
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri Dec  9 14:25:56 2011 UTC

----------------------------------------------------------------------------

1 files changed, 4 insertions(+), 2 deletions(-)
src/servers/registrar/TRoster.cpp |    6 ++++--

----------------------------------------------------------------------------

diff --git a/src/servers/registrar/TRoster.cpp 
b/src/servers/registrar/TRoster.cpp
index e93d560..31d14bd 100644
--- a/src/servers/registrar/TRoster.cpp
+++ b/src/servers/registrar/TRoster.cpp
@@ -1836,15 +1836,17 @@ TRoster::_LoadRosterSettings(const char* path)
        char* data = NULL;
 
        if (!error) {
-               data = new(nothrow) char[size];
+               data = new(nothrow) char[size + 1];
                error = data ? B_OK : B_NO_MEMORY;
        }
        if (!error) {
                ssize_t bytes = file.Read(data, size);
                error = bytes < 0 ? bytes : (bytes == size ? B_OK : 
B_FILE_ERROR);
        }
-       if (!error)
+       if (!error) {
+               data[size] = 0;
                error = stream.SetTo(std::string(data));
+       }
 
        delete[] data;
 


Other related posts:

  • » [haiku-commits] haiku: hrev43445 - src/servers/registrar - mmlr