Mercurial > hg > graal-jvmci-8
comparison src/share/vm/utilities/utf8.cpp @ 8851:8c03fc47511d
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
author | iklam |
---|---|
date | Mon, 01 Apr 2013 14:05:41 -0700 |
parents | bd7a7ce2e264 |
children |
comparison
equal
deleted
inserted
replaced
8849:e458120c6e1a | 8851:8c03fc47511d |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
178 } | 178 } |
179 return result; | 179 return result; |
180 } | 180 } |
181 | 181 |
182 // converts a utf8 string to quoted ascii | 182 // converts a utf8 string to quoted ascii |
183 void UTF8::as_quoted_ascii(const char* utf8_str, char* buf, int buflen) { | 183 void UTF8::as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen) { |
184 const char *ptr = utf8_str; | 184 const char *ptr = utf8_str; |
185 const char *utf8_end = ptr + utf8_length; | |
185 char* p = buf; | 186 char* p = buf; |
186 char* end = buf + buflen; | 187 char* end = buf + buflen; |
187 while (*ptr != '\0') { | 188 while (ptr < utf8_end) { |
188 jchar c; | 189 jchar c; |
189 ptr = UTF8::next(ptr, &c); | 190 ptr = UTF8::next(ptr, &c); |
190 if (c >= 32 && c < 127) { | 191 if (c >= 32 && c < 127) { |
191 if (p + 1 >= end) break; // string is truncated | 192 if (p + 1 >= end) break; // string is truncated |
192 *p++ = (char)c; | 193 *p++ = (char)c; |
194 if (p + 6 >= end) break; // string is truncated | 195 if (p + 6 >= end) break; // string is truncated |
195 sprintf(p, "\\u%04x", c); | 196 sprintf(p, "\\u%04x", c); |
196 p += 6; | 197 p += 6; |
197 } | 198 } |
198 } | 199 } |
200 assert(p < end, "sanity"); | |
199 *p = '\0'; | 201 *p = '\0'; |
200 } | 202 } |
201 | 203 |
202 | 204 |
203 const char* UTF8::from_quoted_ascii(const char* quoted_ascii_str) { | 205 const char* UTF8::from_quoted_ascii(const char* quoted_ascii_str) { |