Quote unset arguments that can undergo pathname expansion

이 제품은 선택한 Datadog 사이트에서 지원되지 않습니다. ().
이 페이지는 아직 한국어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Metadata

ID: bash-security/avoid-unquoted-unset

Language: Bash

Severity: Warning

Category: Security

CWE: 88

Description

Arguments to unset are expanded like other words: unquoted *, ?, and [ can trigger pathname expansion, so a matching filename can replace the argument and unset the wrong name (CWE-88). That is especially easy to miss with array elements written as unset arr[0] or unset foo[index], where [ starts a glob character class.

Quote or use single-quoted words so the name reaches unset literally, for example unset 'foo[index]' or unset 'arr[0]' instead of the unquoted forms.

Non-Compliant Code Examples

#!/bin/bash
unset *
unset foo[index]
unset arr[0]
unset ?
unset [a]
unset foo*

Compliant Code Examples

#!/bin/bash
unset foo
unset PATH
unset "$x"
unset 'foo[index]'
unset -v foo
unset -f myfunc
unset a$b
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

원활한 통합. Datadog Code Security 사용해 보기