Description: OpenNebula seg faults when there are gaps in the history sequence
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 opennebula (5.4.0-1) unstable; urgency=low
 .
   * Imported from http://packages.qa.debian.org/o/opennebula.html
Author: OpenNebula Team <contact@opennebula.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- opennebula-5.4.0.orig/src/vm/VirtualMachine.cc
+++ opennebula-5.4.0/src/vm/VirtualMachine.cc
@@ -2128,10 +2128,16 @@ int VirtualMachine::from_xml(const strin
     if ( xpath(last_seq,"/VM/HISTORY_RECORDS/HISTORY/SEQ", -1) == 0 && 
             last_seq != -1 )
     {
+        history_records.resize(last_seq + 1);
+
+        for (int i=0; i <= last_seq; ++i)
+        {
+            history_records[i] = 0;
+        }
+
         history = new History(oid, last_seq);
 
-        history_records.resize(history->seq + 1);
-        history_records[history->seq] = history;
+        history_records[last_seq] = history;
     }
 
     // -------------------------------------------------------------------------
