•  


Uncontrolled process operation — CodeQL query help documentation CodeQL docs

Uncontrolled process operation

ID: cpp/uncontrolled-process-operation
Kind: path-problem
Security severity: 8.2
Severity: warning
Precision: medium
Tags:
   - security
   - external/cwe/cwe-114
Query suites:
   - cpp-security-extended.qls
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

The code passes user input directly to system , dlopen , LoadLibrary or some other process or library routine. As a result, the user can cause execution of arbitrary code.

Recommendation

If possible, use hard-coded string literals for the command to run or library to load. Instead of passing the user input directly to the process or library function, examine the user input and then choose among hard-coded string literals.

If the applicable libraries or commands cannot be determined at compile time, then add code to verify that the user-input string is safe before using it.

Example

int
 main
(
int
 argc
,
 char
**
 argv
)
 {

  char
 *
lib
 =
 argv
[
2
];

  
  // BAD: the user can cause arbitrary code to be loaded

  void
*
 handle
 =
 dlopen
(
lib
,
 RTLD_LAZY
);

  
  // GOOD: only hard-coded libraries can be loaded

  void
*
 handle2
;


  if
 (
!
strcmp
(
lib
,
 "inmem"
))
 {

    handle2
 =
 dlopen
(
"/usr/share/dbwrap/inmem"
,
 RTLD_LAZY
);

  }
 else
 if
 (
!
strcmp
(
lib
,
 "mysql"
))
 {

    handle2
 =
 dlopen
(
"/usr/share/dbwrap/mysql"
,
 RTLD_LAZY
);

  }
 else
 {

    die
(
"Invalid library specified
\n
"
);

  }

}

References

  • Common Weakness Enumeration: CWE-114 .

  • © GitHub, Inc.
  • Terms
  • Privacy
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본