From 829b2255461bbaa79afd120fce02c86fc7c607b0 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 12 Oct 2016 15:30:24 +0200 Subject: [PATCH] webservices: Fix node insertion in the reader when the current node is an end element. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/reader.c | 25 ++++++++++++------------- dlls/webservices/webservices_private.h | 7 ++++++- dlls/webservices/writer.c | 15 +++++++++++---- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c index c364cfffa37..9a82bcd6300 100644 --- a/dlls/webservices/reader.c +++ b/dlls/webservices/reader.c @@ -1400,16 +1400,15 @@ error: return hr; } -static inline BOOL is_valid_parent( const struct node *node ) +static struct node *find_parent( struct reader *reader ) { - if (!node) return FALSE; - return node_type( node ) == WS_XML_NODE_TYPE_ELEMENT || node_type( node ) == WS_XML_NODE_TYPE_BOF; -} - -struct node *find_parent( struct node *node ) -{ - if (is_valid_parent( node )) return node; - if (is_valid_parent( node->parent )) return node->parent; + if (node_type( reader->current ) == WS_XML_NODE_TYPE_END_ELEMENT) + { + if (is_valid_parent( reader->current->parent->parent )) return reader->current->parent->parent; + return NULL; + } + else if (is_valid_parent( reader->current )) return reader->current; + else if (is_valid_parent( reader->current->parent )) return reader->current->parent; return NULL; } @@ -1468,7 +1467,7 @@ static HRESULT read_element( struct reader *reader ) } if (!len) goto error; - if (!(parent = find_parent( reader->current ))) goto error; + if (!(parent = find_parent( reader ))) goto error; hr = E_OUTOFMEMORY; if (!(node = alloc_node( WS_XML_NODE_TYPE_ELEMENT ))) goto error; @@ -1522,7 +1521,7 @@ static HRESULT read_text( struct reader *reader ) len += skip; } - if (!(parent = find_parent( reader->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT; if (!(node = alloc_node( WS_XML_NODE_TYPE_TEXT ))) return E_OUTOFMEMORY; text = (WS_XML_TEXT_NODE *)node; @@ -1693,7 +1692,7 @@ static HRESULT read_comment( struct reader *reader ) len += skip; } - if (!(parent = find_parent( reader->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT; if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY; comment = (WS_XML_COMMENT_NODE *)node; @@ -1717,7 +1716,7 @@ static HRESULT read_startcdata( struct reader *reader ) if (read_cmp( reader, "current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT; if (!(node = alloc_node( WS_XML_NODE_TYPE_CDATA ))) return E_OUTOFMEMORY; if (!(endnode = alloc_node( WS_XML_NODE_TYPE_END_CDATA ))) diff --git a/dlls/webservices/webservices_private.h b/dlls/webservices/webservices_private.h index cdaa4b5ca09..12b7984b9c4 100644 --- a/dlls/webservices/webservices_private.h +++ b/dlls/webservices/webservices_private.h @@ -52,7 +52,6 @@ struct node struct node *alloc_node( WS_XML_NODE_TYPE ) DECLSPEC_HIDDEN; void free_node( struct node * ) DECLSPEC_HIDDEN; void destroy_nodes( struct node * ) DECLSPEC_HIDDEN; -struct node *find_parent( struct node * ) DECLSPEC_HIDDEN; HRESULT copy_node( WS_XML_READER *, struct node ** ) DECLSPEC_HIDDEN; static inline WS_XML_NODE_TYPE node_type( const struct node *node ) @@ -125,6 +124,12 @@ static inline BOOL is_nil_value( const char *value, ULONG size ) return TRUE; } +static inline BOOL is_valid_parent( const struct node *node ) +{ + if (!node) return FALSE; + return (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT || node_type( node ) == WS_XML_NODE_TYPE_BOF); +} + static inline void *heap_alloc( SIZE_T size ) { return HeapAlloc( GetProcessHeap(), 0, size ); diff --git a/dlls/webservices/writer.c b/dlls/webservices/writer.c index 26ab726125e..4622277e027 100644 --- a/dlls/webservices/writer.c +++ b/dlls/webservices/writer.c @@ -130,6 +130,13 @@ static void write_insert_node( struct writer *writer, struct node *parent, struc writer->current = node; } +static struct node *find_parent( struct writer *writer ) +{ + if (is_valid_parent( writer->current )) return writer->current; + if (is_valid_parent( writer->current->parent )) return writer->current->parent; + return NULL; +} + static HRESULT write_init_state( struct writer *writer ) { struct node *node; @@ -890,7 +897,7 @@ static HRESULT write_flush( struct writer *writer ) static HRESULT write_add_cdata_node( struct writer *writer ) { struct node *node, *parent; - if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT; if (!(node = alloc_node( WS_XML_NODE_TYPE_CDATA ))) return E_OUTOFMEMORY; write_insert_node( writer, parent, node ); return S_OK; @@ -977,7 +984,7 @@ static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRIN struct node *node, *parent; WS_XML_ELEMENT_NODE *elem; - if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT; if (!prefix && node_type( parent ) == WS_XML_NODE_TYPE_ELEMENT) { @@ -2563,7 +2570,7 @@ static HRESULT write_add_comment_node( struct writer *writer, const WS_XML_STRIN struct node *node, *parent; WS_XML_COMMENT_NODE *comment; - if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT; if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY; comment = (WS_XML_COMMENT_NODE *)node; @@ -2774,7 +2781,7 @@ HRESULT WINAPI WsCopyNode( WS_XML_WRITER *handle, WS_XML_READER *reader, WS_ERRO if (error) FIXME( "ignoring error parameter\n" ); if (!writer) return E_INVALIDARG; - if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT; + if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT; if ((hr = copy_node( reader, &node )) != S_OK) return hr; write_insert_node( writer, parent, node );