Unchecked return value of setuid/seteuid may leave elevated privileges

ID

c.privilege_management.unchecked_ret_setuid_seteuid

Severity

low

Resource

Privilege Management

Language

C / C++

Description

The software does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions. If the program calls a function to drop privileges but does not check the return code to ensure that privileges were successfully dropped, then the program will continue to operate with the higher privileges.

Rationale

The software does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions. If the program calls a function to drop privileges but does not check the return code to ensure that privileges were successfully dropped, then the program will continue to operate with the higher privileges.

The following code illustrates a vulnerable pattern detected by this rule:

void drop_priv_perm()
{
	// VULNERABLE: Unchecked return value of setuid/seteuid may leave elevated privileges
	setuid(getuid());
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.