summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-26 06:13:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-26 06:13:15 +0000
commit993f22cb1bba82be52e08e7132af003ae432163e (patch)
treea010dc21a323f496e16e9a2f7fe208c6ac1d0b97 /ext/json
parented316bcfad804c272c64fe70d1a360b0a8226bef (diff)
parser.rl: check before use
* ext/json/parser/parser.rl (unescape_unicode): check if valid before bit-or assignments. reported by Denis Denisov <denji0k AT gmail.com>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/parser/parser.c8
-rw-r--r--ext/json/parser/parser.rl10
2 files changed, 9 insertions, 9 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 560aa89..f9d0d19 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -28,16 +28,16 @@ static UTF32 unescape_unicode(const unsigned char *p)
UTF32 result = 0;
b = digit_values[p[0]];
if (b < 0) return UNI_REPLACEMENT_CHAR;
- result = (result << 4) | b;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[1]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[2]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[3]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
return result;
}
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index 34e30f4..3d7b5a6 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -26,16 +26,16 @@ static UTF32 unescape_unicode(const unsigned char *p)
UTF32 result = 0;
b = digit_values[p[0]];
if (b < 0) return UNI_REPLACEMENT_CHAR;
- result = (result << 4) | b;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[1]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[2]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
b = digit_values[p[3]];
- result = (result << 4) | b;
if (b < 0) return UNI_REPLACEMENT_CHAR;
+ result = (result << 4) | (unsigned char)b;
return result;
}
@@ -883,7 +883,7 @@ static VALUE cParser_quirks_mode_p(VALUE self)
}
-void Init_parser()
+void Init_parser(void)
{
rb_require("json/common");
mJSON = rb_define_module("JSON");