o pcred-removal changes included modifications to optimize the setting of

the saved uid and gid during execve().  Unfortunately, the optimizations
  were incorrect in the case where the credential was updated, skipping
  the setting of the saved uid and gid when new credentials were generated.
  This change corrects that problem by handling the newcred!=NULL case
  correctly.

Reported/tested by:	David Malone <dwmalone@maths.tcd.ie>

Obtained from:	TrustedBSD Project
This commit is contained in:
Robert Watson 2001-05-26 19:59:44 +00:00
parent 0d60c7099d
commit 7cb8e4d277
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77242

View File

@ -334,17 +334,18 @@ execve(p, uap)
* (replaced) euid and egid as the source, which may or may not be
* the right ones to use.
*/
if (oldcred->cr_svuid != oldcred->cr_uid ||
oldcred->cr_svgid != oldcred->cr_gid) {
/*
* Avoid allocating a newcred if we don't have one yet and
* the saved uid/gid update would be a noop.
*/
if (newcred == NULL)
if (newcred == NULL) {
if (oldcred->cr_svuid != oldcred->cr_uid ||
oldcred->cr_svgid != oldcred->cr_gid) {
newcred = crdup(oldcred);
change_svuid(newcred, newcred->cr_uid);
change_svgid(newcred, newcred->cr_gid);
}
} else {
change_svuid(newcred, newcred->cr_uid);
change_svgid(newcred, newcred->cr_gid);
}
if (newcred != NULL) {
PROC_LOCK(p);
p->p_ucred = newcred;