Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000897 [1003.1(2013)/Issue7+TC1] System Interfaces Editorial Enhancement Request 2014-11-28 23:19 2015-03-05 16:16
Reporter safinaskar View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Resolved  
Name Askar Safin
Organization
User Reference
Section getuid
Page Number 2013 edition, p. 1091
Line Number 36714
Interp Status ---
Final Accepted Text See Note: 0002456.
Summary 0000897: setreuid(getuid(), getuid()) seems not rational
Description getuid 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 Action line 36714

-setreuid(getuid(), getuid());
+uid_t u = getuid();
+setreuid(u, u);
Tags tc2-2008
Attached Files

- Relationships

-  Notes
(0002456)
geoffclare (manager)
2014-12-01 15:36

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());
(0002466)
philip-guenther (reporter)
2014-12-02 06:38

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.
(0002468)
geoffclare (manager)
2014-12-02 14:19

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 Note: 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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker