From 7a6372a52210355903c2adf7d3e6a73ce4338fc4 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 24 Oct 2019 13:32:59 +0300 Subject: [PATCH] Cnode: replace strcpy with strncpy --- c_src/myhtml_worker.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/c_src/myhtml_worker.c b/c_src/myhtml_worker.c index 33b7cc9..ba2a88b 100644 --- a/c_src/myhtml_worker.c +++ b/c_src/myhtml_worker.c @@ -332,8 +332,10 @@ ETERM* build_tree(prefab_t* prefab, myhtml_tree_t* tree, myhtml_tree_node_t* nod if (tag_ns != MyHTML_NAMESPACE_HTML) { // tag_ns_name_ptr is unmodifyable, copy it in our tag_ns_buffer to make it modifyable. - char tag_ns_buffer[tag_ns_len]; - strcpy(tag_ns_buffer, tag_ns_name_ptr); + // +1 because myhtml uses strlen for length returned, which doesn't include the null-byte + // https://github.com/lexborisov/myhtml/blob/0ade0e564a87f46fd21693a7d8c8d1fa09ffb6b6/source/myhtml/mynamespace.c#L80 + char tag_ns_buffer[tag_ns_len + 1]; + strncpy(tag_ns_buffer, tag_ns_name_ptr, sizeof(tag_ns_buffer)); lowercase(tag_ns_buffer); tag_string_len = tag_ns_len + tag_name_len + 1; // +1 for colon