View Issue Details

IDProjectCategoryView StatusLast Update
00008971003.1(2013)/Issue7+TC1System Interfacespublic2019-06-10 08:54
Reportersafinaskar Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status ClosedResolutionAccepted As Marked 
NameAskar Safin
Organization
User Reference
Sectiongetuid
Page Number2013 edition, p. 1091
Line Number36714
Interp Status---
Final Accepted TextSee 0000897:0002456.
Summary0000897: setreuid(getuid(), getuid()) seems not rational
Descriptiongetuid typically is system call. And this is possible that uid is not cached in standard library. And this is very unlikely compiler can optimize two syscalls to one. And examples in POSIX manuals should be ideal. :) So, for performance reasons (to avoid lots of context switches), please do the following:
Desired Actionline 36714

-setreuid(getuid(), getuid());
+uid_t u = getuid();
+setreuid(u, u);
Tagstc2-2008

Activities

geoffclare

2014-12-01 15:36

manager   bugnote:0002456

It seems odd that the example of how to set the effective user ID to the real user ID makes use of the optional (XSI) setreuid() function, instead of the mandatory seteuid() function.

Change from:

The following example sets the effective user ID and the real user ID of the current process to the real user ID of the caller.
#include <unistd.h>
#include <sys/types.h>
...
setreuid(getuid(), getuid());
to:

The following example sets the effective user ID of the calling process to the real user ID.
#include <unistd.h>
...
seteuid(getuid());

philip-guenther

2014-12-02 06:38

reporter   bugnote:0002466

The existing suggestion:
> setreuid(getuid(), getuid());

also sets the saved set-user-ID to the real user ID. The suggested replacement:
> seteuid(getuid());

does not.

The setre{u,g}id() interfaces are probably XSI only because the versions in XSI and in pre-4.4BSD had slightly different semantics when mapped into saved set-*-ID logic...though both versions do the Right Thing when invoked per the example.

geoffclare

2014-12-02 14:19

manager   bugnote:0002468

Yes, my proposed change means different behaviour as regards saved set-user-ID. However, that's another argument in favour of changing to seteuid(), since the setreuid() example code does more than the description above it says it does (and the example's title implies).

Issue History

Date Modified Username Field Change
2014-11-28 23:19 safinaskar New Issue
2014-11-28 23:19 safinaskar Name => Askar Safin
2014-11-28 23:19 safinaskar Section => getuid
2014-11-28 23:19 safinaskar Page Number => 2013 edition, p. 1091
2014-11-28 23:19 safinaskar Line Number => 36714
2014-12-01 15:36 geoffclare Note Added: 0002456
2014-12-02 06:38 philip-guenther Note Added: 0002466
2014-12-02 14:19 geoffclare Note Added: 0002468
2015-03-05 16:16 Don Cragun Interp Status => ---
2015-03-05 16:16 Don Cragun Final Accepted Text => See 0000897:0002456.
2015-03-05 16:16 Don Cragun Status New => Resolved
2015-03-05 16:16 Don Cragun Resolution Open => Accepted As Marked
2015-03-05 16:16 Don Cragun Tag Attached: tc2-2008
2019-06-10 08:54 agadmin Status Resolved => Closed