Skip to content

[bug] EnvVars does not escape quotes in generated bat files #18761

@lhocmf

Description

@lhocmf

Describe the bug

Environment: Windows Server 2019, conan 2.17.1

EnvVars.save_bat does not escape quotes inside environment variables, causing breakage with the generated set commands in the conanbuildenv-(debug|release)-x86_64.bat files.

This seems like an oversight, as the generated save_ps1 and save_sh variants do escape quotes.

How to reproduce it

Conanfile (with Env Var):

from conan import ConanFile

class BugConan(ConanFile):
    name = 'bug'
    version = '0.0.1'
    settings = 'arch', 'build_type', 'compiler', 'os'

    def package_info(self):
        self.buildenv_info.define('bugged', '-Dsome.java.flag.example="hey|echo This could be an injection|invalid_command"')

Conanfile (consumer):

from conan import ConanFile

class ConsumerConan(ConanFile):
    name = 'consumer'
    version = '0.0.1'
    settings = 'arch', 'build_type', 'compiler', 'os'
    requires = 'bug/0.0.1'

    def build(self):
        self.run("echo Test to trigger buildenv usage")

Reproduction steps:

  1. Run conan create on BugConan conanfile
  2. Run conan create (or conan build) on ConsumerConan from cmd (or in another way to trigger bat file generation and usage)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions