Skip to content

Commit

Permalink
WebIDL: Copy char* before use it, closes libass#77
Browse files Browse the repository at this point in the history
  • Loading branch information
TFSThiagoBR98 committed Feb 14, 2022
1 parent 2599a21 commit fba7b8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion build/WebIDL.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## JavascriptSubtitlesOctopus
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py
## Patched to add IntPtr Type

# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
# rev 501baeb3a034

Expand Down Expand Up @@ -4582,7 +4586,7 @@ def p_SingleTypeIntPtrType(self, p):
SingleType : INTPTR TypeSuffixStartingWithArray
"""
p[0] = self.handleModifiers(BuiltinTypes[IDLBuiltinType.Types.IntPtr], p[2])

def p_UnionType(self, p):
"""
UnionType : LPAREN UnionMemberType OR UnionMemberType UnionMemberTypes RPAREN
Expand Down
11 changes: 10 additions & 1 deletion build/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

## JavascriptSubtitlesOctopus
## Patched to add integer pointers (IntPtr) and fix string setter for structs
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py

"""WebIDL binder
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html
Expand Down Expand Up @@ -719,7 +723,12 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer,
get_sigs = {0: []}
set_sigs = {1: [Dummy({'type': m.type})]}
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
if m.type.isDOMString():
set_call_content = """ char* copy = (char*)malloc(strlen(%s) + 1);
strcpy(copy, %s);
self->%s = copy""" % (deref_if_nonpointer(m) + 'arg0', deref_if_nonpointer(m) + 'arg0', attr)
else:
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'

get_name = 'get_' + attr
mid_js += [r'''
Expand Down

0 comments on commit fba7b8c

Please sign in to comment.