aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/utilities
diff options
context:
space:
mode:
authoriklam <none@none>2013-04-01 14:05:41 -0700
committeriklam <none@none>2013-04-01 14:05:41 -0700
commit9b5cf32073646208268da28aa3ea9dd021ff4d33 (patch)
treeaa5a078946583fde63def5df170f72336c093a80 /src/share/vm/utilities
parentb7cd6b943c3205a4934bfc4b8032734462df88d3 (diff)
8011048: Possible reading from unmapped memory in UTF8::as_quoted_ascii()
Summary: Pass utf_length parameter to UTF8::as_quoted_ascii() Reviewed-by: dcubed, minqi
Diffstat (limited to 'src/share/vm/utilities')
-rw-r--r--src/share/vm/utilities/utf8.cpp8
-rw-r--r--src/share/vm/utilities/utf8.hpp4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/share/vm/utilities/utf8.cpp b/src/share/vm/utilities/utf8.cpp
index da470b18c..8c013c9b3 100644
--- a/src/share/vm/utilities/utf8.cpp
+++ b/src/share/vm/utilities/utf8.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -180,11 +180,12 @@ int UTF8::quoted_ascii_length(const char* utf8_str, int utf8_length) {
}
// converts a utf8 string to quoted ascii
-void UTF8::as_quoted_ascii(const char* utf8_str, char* buf, int buflen) {
+void UTF8::as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen) {
const char *ptr = utf8_str;
+ const char *utf8_end = ptr + utf8_length;
char* p = buf;
char* end = buf + buflen;
- while (*ptr != '\0') {
+ while (ptr < utf8_end) {
jchar c;
ptr = UTF8::next(ptr, &c);
if (c >= 32 && c < 127) {
@@ -196,6 +197,7 @@ void UTF8::as_quoted_ascii(const char* utf8_str, char* buf, int buflen) {
p += 6;
}
}
+ assert(p < end, "sanity");
*p = '\0';
}
diff --git a/src/share/vm/utilities/utf8.hpp b/src/share/vm/utilities/utf8.hpp
index 69710fcce..354941e6d 100644
--- a/src/share/vm/utilities/utf8.hpp
+++ b/src/share/vm/utilities/utf8.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@ class UTF8 : AllStatic {
static int quoted_ascii_length(const char* utf8_str, int utf8_length);
// converts a utf8 string to quoted ascii
- static void as_quoted_ascii(const char* utf8_str, char* buf, int buflen);
+ static void as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen);
// converts a quoted ascii string to utf8 string. returns the original
// string unchanged if nothing needs to be done.