You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/03/08 18:57:06 UTC
[trafficserver] branch 7.1.x updated: all or nothing for
readIntoBuffer
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/7.1.x by this push:
new 5aed996 all or nothing for readIntoBuffer
5aed996 is described below
commit 5aed996a3ba2f2f13f11483b59237b316c76c6da
Author: Alan Wang <xf...@gmail.com>
AuthorDate: Mon Mar 5 16:07:47 2018 -0800
all or nothing for readIntoBuffer
(cherry picked from commit ea338f66974192c7ab906a1a4e020a696afb8cd7)
---
lib/ts/MatcherUtils.cc | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/ts/MatcherUtils.cc b/lib/ts/MatcherUtils.cc
index 5c5f32f..10ec663 100644
--- a/lib/ts/MatcherUtils.cc
+++ b/lib/ts/MatcherUtils.cc
@@ -57,10 +57,10 @@ config_parse_error::config_parse_error(const char *fmt, ...)
// int* read_size_ptr)
//
// Attempts to open and read arg file_path into a buffer allocated
-// off the heap (via malloc() ) Returns a pointer to the buffer
+// off the heap (via ats_malloc() ) Returns a pointer to the buffer
// is successful and nullptr otherwise.
//
-// CALLEE is responsibled for deallocating the buffer via free()
+// CALLEE is responsibled for deallocating the buffer via ats_free()
//
char *
readIntoBuffer(const char *file_path, const char *module_name, int *read_size_ptr)
@@ -106,10 +106,12 @@ readIntoBuffer(const char *file_path, const char *module_name, int *read_size_pt
ats_free(file_buf);
file_buf = nullptr;
} else if (read_size < file_info.st_size) {
- // We don't want to signal this error on WIN32 because the sizes
- // won't match if the file contains any CR/LF sequence.
+ // Didn't get the whole file, drop everything. We don't want to return
+ // something partially read because, ie. with configs, the behaviour
+ // is undefined.
Error("%s Only able to read %d bytes out %d for %s file", module_name, read_size, (int)file_info.st_size, file_path);
- file_buf[read_size] = '\0';
+ ats_free(file_buf);
+ file_buf = nullptr;
}
if (file_buf && read_size_ptr) {
--
To stop receiving notification emails like this one, please contact
zwoop@apache.org.