From fd8ce841eb5ba7b1d82f3dd0f47c8d8cbd25f3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Fri, 26 Nov 2021 20:01:49 +0100 Subject: [PATCH] Fix a nasty bug : fulfill reply data must be copied, not just referenced --- include/fulfillment_item.h | 7 +++++++ src/fulfillment_item.cpp | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/fulfillment_item.h b/include/fulfillment_item.h index 28074a8..0cfcae0 100644 --- a/include/fulfillment_item.h +++ b/include/fulfillment_item.h @@ -34,6 +34,12 @@ namespace gourou class FulfillmentItem { public: + /** + * @brief Main constructor. Not to be called by user + * + * @param doc Fulfill reply + * @param user User pointer + */ FulfillmentItem(pugi::xml_document& doc, User* user); /** @@ -59,6 +65,7 @@ namespace gourou std::string getResource(); private: + pugi::xml_document fulfillDoc; pugi::xml_node metadatas; pugi::xml_document rights; std::string downloadURL; diff --git a/src/fulfillment_item.cpp b/src/fulfillment_item.cpp index f290d4f..679ac68 100644 --- a/src/fulfillment_item.cpp +++ b/src/fulfillment_item.cpp @@ -24,9 +24,11 @@ namespace gourou { FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user) + : fulfillDoc() { - metadatas = doc.select_node("//metadata").node(); - + fulfillDoc.reset(doc); /* We must keep a copy */ + metadatas = fulfillDoc.select_node("//metadata").node(); + if (!metadatas) EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "No metadata tag in document"); @@ -49,7 +51,7 @@ namespace gourou buildRights(licenseToken, user); } - + void FulfillmentItem::buildRights(const pugi::xml_node& licenseToken, User* user) { pugi::xml_node decl = rights.append_child(pugi::node_declaration);