Skip to content

Commit f3a119a

Browse files
committed
Fix json library to throw instead of assert (can segfault)
1 parent 6635326 commit f3a119a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/json.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
#include "json.hpp"
3030

31+
// include utf8 library used by libsass
32+
// ToDo: replace internal json utf8 code
33+
#include "utf8.h"
34+
3135
#include <assert.h>
3236
#include <stdint.h>
3337
#include <stdio.h>
@@ -1141,6 +1145,13 @@ void emit_string(SB *out, const char *str)
11411145
const char *s = str;
11421146
char *b;
11431147

1148+
// make assertion catchable
1149+
#ifndef NDEBUG
1150+
if (!utf8_validate(str)) {
1151+
throw utf8::invalid_utf8(0);
1152+
}
1153+
#endif
1154+
11441155
assert(utf8_validate(str));
11451156

11461157
/*

0 commit comments

Comments
 (0)