Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,862
    • Issues 3,862
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Merge requests
  • !4432

ConvertMSBuildXMLToJSON: Fix python mutable default data structure

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Brendon Go requested to merge brendongo/cmake:python-default-mutable into master Mar 05, 2020
  • Overview 1
  • Commits 1
  • Pipelines 1
  • Changes 1

Hello,

I am a security engineer at r2c.dev. We are working to write code checks for security in open source code. A python project I was looking at happened to checkin the entire cmake codebase which is how I happened onto this.

Problem: In python, the default values of function parameters are instantiated at function definition time. All calls to that function that use the default value all point to the same global object. e.g.:

def func(x=[]):
   x.append(1)
   print(x)

func() # [1]
func() # [1 , 1]

Fix: The recommended solution is to either set default to None and assign a new empty object when the variable is None.

Topic-rename: ConvertMSBuildXMLToJSON-default-mutable

Edited Mar 06, 2020 by Brad King
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: python-default-mutable