[PATCH 00/17] conf: Fix and prevent uninitialized memory use with new virXMLProp* helpers

Peter Krempa posted 17 patches 2 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/cover.1620314826.git.pkrempa@redhat.com
src/conf/backup_conf.c   |   5 +-
src/conf/domain_conf.c   | 176 ++++++++++++++++++++-------------------
src/conf/domain_conf.h   |   1 +
src/libvirt_private.syms |   1 +
src/util/virxml.c        | 156 +++++++++++++++++++---------------
src/util/virxml.h        |  14 +++-
6 files changed, 198 insertions(+), 155 deletions(-)
[PATCH 00/17] conf: Fix and prevent uninitialized memory use with new virXMLProp* helpers
Posted by Peter Krempa 2 years, 11 months ago
Compilers aren't able to see that the value passed via a pointer from
the new virXMLProp helpers may be uninitialized in certain cases.

Fix 3 such cases, prepare the code and then ensure that the new
virXMLProp* helpers always initialize the memory.

CI pipeline (once it finishes) can be viewed at:

https://gitlab.com/pipo.sk/libvirt/-/pipelines/298562552


Peter Krempa (17):
  util: xml: Extract implementation of xml property -> enum parsing to a
    common helper
  virXMLPropULongLong: Always initialize @result
  virDomainVcpuParse: Assign default vcpus count based on return value
    of virXMLPropUInt
  virDomainDiskDefDriverParseXML: Fix usage of virXMLPropUInt
  virXMLPropUInt: Always initialize @result
  conf: Define autoptr func for virDomainIOThreadIDDef
  virDomainIOThreadIDDefParseXML: Refactor cleanup
  virXMLPropInt: Always initialize '@result'
  virDomainBackupDiskDefParseXML: Fill default backup state after
    parsing it
  virXMLPropTristateBool: Always initialize '@result'
  conf: domain: Don't initialize virTristateBool local variables used
    for virXMLPropTristateBool
  virXMLPropTristateSwitch: Always initialize '@result'
  virDomainAudioCommonParse: Fix parsing of 'format'
  virDomainVideoDefParseXML: Fix parsing of 'backend'
  util: xml: Introduce virXMLPropEnumDefault
  conf: domain: Convert virXMLPropEnum to virXMLPropEnumDefault where we
    set defaults
  virXMLPropEnum: Always initialize '@result'

 src/conf/backup_conf.c   |   5 +-
 src/conf/domain_conf.c   | 176 ++++++++++++++++++++-------------------
 src/conf/domain_conf.h   |   1 +
 src/libvirt_private.syms |   1 +
 src/util/virxml.c        | 156 +++++++++++++++++++---------------
 src/util/virxml.h        |  14 +++-
 6 files changed, 198 insertions(+), 155 deletions(-)

-- 
2.30.2

Re: [PATCH 00/17] conf: Fix and prevent uninitialized memory use with new virXMLProp* helpers
Posted by Michal Prívozník 2 years, 11 months ago
On 5/6/21 5:30 PM, Peter Krempa wrote:
> Compilers aren't able to see that the value passed via a pointer from
> the new virXMLProp helpers may be uninitialized in certain cases.
> 
> Fix 3 such cases, prepare the code and then ensure that the new
> virXMLProp* helpers always initialize the memory.
> 
> CI pipeline (once it finishes) can be viewed at:
> 
> https://gitlab.com/pipo.sk/libvirt/-/pipelines/298562552
> 
> 
> Peter Krempa (17):
>   util: xml: Extract implementation of xml property -> enum parsing to a
>     common helper
>   virXMLPropULongLong: Always initialize @result
>   virDomainVcpuParse: Assign default vcpus count based on return value
>     of virXMLPropUInt
>   virDomainDiskDefDriverParseXML: Fix usage of virXMLPropUInt
>   virXMLPropUInt: Always initialize @result
>   conf: Define autoptr func for virDomainIOThreadIDDef
>   virDomainIOThreadIDDefParseXML: Refactor cleanup
>   virXMLPropInt: Always initialize '@result'
>   virDomainBackupDiskDefParseXML: Fill default backup state after
>     parsing it
>   virXMLPropTristateBool: Always initialize '@result'
>   conf: domain: Don't initialize virTristateBool local variables used
>     for virXMLPropTristateBool
>   virXMLPropTristateSwitch: Always initialize '@result'
>   virDomainAudioCommonParse: Fix parsing of 'format'
>   virDomainVideoDefParseXML: Fix parsing of 'backend'
>   util: xml: Introduce virXMLPropEnumDefault
>   conf: domain: Convert virXMLPropEnum to virXMLPropEnumDefault where we
>     set defaults
>   virXMLPropEnum: Always initialize '@result'
> 
>  src/conf/backup_conf.c   |   5 +-
>  src/conf/domain_conf.c   | 176 ++++++++++++++++++++-------------------
>  src/conf/domain_conf.h   |   1 +
>  src/libvirt_private.syms |   1 +
>  src/util/virxml.c        | 156 +++++++++++++++++++---------------
>  src/util/virxml.h        |  14 +++-
>  6 files changed, 198 insertions(+), 155 deletions(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal