Skip to content

Commit bcc92e7

Browse files
authored
Merge pull request #55 from Azq2/patch-12
fix serialization segfault
2 parents 7a710b8 + 7725ed2 commit bcc92e7

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

source/myhtml/serialization.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,59 @@ mystatus_t myhtml_serialization_node_callback(myhtml_tree_node_t* node, mycore_c
137137
if(callback("<!DOCTYPE", 9, ptr))
138138
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
139139

140+
if(callback(" ", 1, ptr))
141+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
142+
140143
if(node->token) {
141144
myhtml_tree_attr_t* attr = node->token->attr_first;
142145

143-
if(attr->key.data && attr->key.length) {
144-
if(callback(" ", 1, ptr))
145-
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
146-
146+
if(attr && attr->key.data && attr->key.length) {
147147
if(callback(attr->key.data, attr->key.length, ptr))
148148
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
149+
150+
attr = attr->next;
151+
152+
if(attr) {
153+
myhtml_tree_attr_t *system_id = NULL, *public_id = NULL;
154+
155+
if(attr->value.length == 6) {
156+
if(mycore_strcasecmp(attr->value.data, "SYSTEM") == 0) {
157+
system_id = attr->next;
158+
} else if(mycore_strcasecmp(attr->value.data, "PUBLIC") == 0) {
159+
public_id = attr->next;
160+
system_id = public_id ? public_id->next : NULL;
161+
}
162+
}
163+
164+
if(public_id && public_id->value.length > 0) {
165+
if(callback(" PUBLIC \"", 9, ptr))
166+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
167+
168+
if(callback(public_id->value.data, public_id->value.length, ptr))
169+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
170+
171+
if(callback("\"", 1, ptr))
172+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
173+
}
174+
175+
if(system_id && system_id->value.length > 0) {
176+
if(!public_id || public_id->value.length == 0) {
177+
if(callback(" SYSTEM", 7, ptr))
178+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
179+
}
180+
181+
if(callback(" \"", 2, ptr))
182+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
183+
184+
if(system_id->value.data && system_id->value.length) {
185+
if(callback(system_id->value.data, system_id->value.length, ptr))
186+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
187+
}
188+
189+
if(callback("\"", 1, ptr))
190+
return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION;
191+
}
192+
}
149193
}
150194
}
151195

0 commit comments

Comments
 (0)