Skip to content

Commit

Permalink
Updates: Enable additional warnings, fix a number of things.
Browse files Browse the repository at this point in the history
None of them seem to have been genuine problems, but it's prettier now,
and some were questionable.
  • Loading branch information
Peter Seebach committed Mar 26, 2010
1 parent 9a95df4 commit caeebc0
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 124 deletions.
6 changes: 2 additions & 4 deletions Makefile.in
Expand Up @@ -29,7 +29,7 @@ LIBDIR=$(PREFIX)/lib$(MARK64)
BINDIR=$(PREFIX)/bin
DATADIR=$(PREFIX)/var/pseudo

CFLAGS_BASE=-pipe -std=gnu99 -Wall
CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra
CFLAGS_CODE=-fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE -m$(BITS)
CFLAGS_DEFS=-DPSEUDO_PREFIX='"$(PREFIX)"' -DPSEUDO_SUFFIX='"$(SUFFIX)"' -DPSEUDO_VERSION='"$(VERSION)"'
CFLAGS_DEBUG=-O2 -g
Expand Down Expand Up @@ -92,8 +92,6 @@ pseudo_client.o: pseudo_client.h

pseudo_server.o: pseudo_server.h

pseudo_wrappers.o: $(GUTS)

wrappers: wrapfuncs.in $(USE_64) makewrappers
./makewrappers wrapfuncs.in $(USE_64)

Expand All @@ -102,7 +100,7 @@ wrappers: wrapfuncs.in $(USE_64) makewrappers
pseudo_wrappers.c: wrappers

# no-strict-aliasing is needed for the function pointer trickery.
pseudo_wrappers.o: pseudo_wrappers.c
pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c
$(CC) -fno-strict-aliasing $(CFLAGS) -D_GNU_SOURCE -c -o pseudo_wrappers.o pseudo_wrappers.c

offsets32:
Expand Down
6 changes: 3 additions & 3 deletions guts/fchown.c
Expand Up @@ -14,7 +14,7 @@
errno = save_errno;
return -1;
}
if (owner == -1 || group == -1) {
if (owner == (uid_t) -1 || group == (gid_t) -1) {
msg = pseudo_client_op(OP_STAT, fd, -1, NULL, &buf);
/* copy in any existing values... */
if (msg) {
Expand All @@ -30,10 +30,10 @@
}
}
/* now override with arguments */
if (owner != -1) {
if (owner != (uid_t) -1) {
buf.st_uid = owner;
}
if (group != -1) {
if (group != (gid_t) -1) {
buf.st_gid = group;
}
pseudo_debug(2, "fchown, fd %d: %d:%d -> %d:%d\n",
Expand Down
24 changes: 13 additions & 11 deletions guts/fchownat.c
Expand Up @@ -30,22 +30,24 @@
}
save_errno = errno;

msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf);
/* copy in any existing values... */
if (msg) {
if (msg->result == RESULT_SUCCEED) {
pseudo_stat_msg(&buf, msg);
} else {
pseudo_debug(2, "chownat to %d:%d on %d/%s, ino %llu, new file.\n",
owner, group, dirfd, path,
(unsigned long long) buf.st_ino);
if (owner == (uid_t) -1 || group == (gid_t) -1) {
msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf);
/* copy in any existing values... */
if (msg) {
if (msg->result == RESULT_SUCCEED) {
pseudo_stat_msg(&buf, msg);
} else {
pseudo_debug(2, "chownat to %d:%d on %d/%s, ino %llu, new file.\n",
owner, group, dirfd, path,
(unsigned long long) buf.st_ino);
}
}
}
/* now override with arguments */
if (owner != -1) {
if (owner != (uid_t) -1) {
buf.st_uid = owner;
}
if (group != -1) {
if (group != (gid_t) -1) {
buf.st_gid = group;
}
msg = pseudo_client_op(OP_CHOWN, -1, dirfd, path, &buf);
Expand Down
2 changes: 1 addition & 1 deletion guts/fts_open.c
Expand Up @@ -4,7 +4,7 @@
* FTS * rc = NULL;
*/
char **rpath_argv;
size_t args = 0;
int args = 0;
int errored = 0;
int i;

Expand Down
45 changes: 2 additions & 43 deletions guts/lchown.c
Expand Up @@ -2,49 +2,8 @@
* static int
* wrap_lchown(const char *path, uid_t owner, gid_t group) {
*/
pseudo_msg_t *msg;
struct stat64 buf;
if (!path) {
errno = EFAULT;
return -1;
}
pseudo_debug(2, "lchown(%s, %d, %d)\n",
path ? path : "<nil>", owner, group);
if (real___lxstat64(_STAT_VER, path, &buf) == -1) {
return -1;
}
if (owner == -1 || group == -1) {
msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf);
/* copy in any existing values... */
if (msg) {
if (msg->result == RESULT_SUCCEED) {
pseudo_stat_msg(&buf, msg);
} else {
pseudo_debug(2, "lchown to %d:%d on %s, ino %llu, new file.\n",
owner, group, path,
(unsigned long long) buf.st_ino);
}
} else {
pseudo_diag("stat within lchown of '%s' [%llu] failed.\n",
path, (unsigned long long) buf.st_ino);
}
}
if (owner != -1) {
buf.st_uid = owner;
}
if (group != -1) {
buf.st_gid = group;
}
msg = pseudo_client_op(OP_CHOWN, -1, -1, path, &buf);
if (!msg) {
errno = ENOSYS;
rc = -1;
} else if (msg->result != RESULT_SUCCEED) {
errno = msg->xerrno;
rc = -1;
} else {
rc = 0;
}

rc = wrap_fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW);

/* return rc;
* }
Expand Down
2 changes: 1 addition & 1 deletion guts/realpath.c
Expand Up @@ -4,7 +4,7 @@
* char * rc = NULL;
*/
char *rname = PSEUDO_ROOT_PATH(AT_FDCWD, name, 0);
size_t len;
ssize_t len;
if (!rname) {
errno = ENAMETOOLONG;
return NULL;
Expand Down
8 changes: 4 additions & 4 deletions guts/setregid.c
Expand Up @@ -4,20 +4,20 @@
* int rc = -1;
*/
rc = 0;
if (pseudo_euid != 0 && rgid != -1 &&
if (pseudo_euid != 0 && rgid != (gid_t) -1 &&
rgid != pseudo_egid && rgid != pseudo_rgid && rgid != pseudo_sgid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && egid != -1 &&
if (pseudo_euid != 0 && egid != (gid_t) -1 &&
egid != pseudo_egid && egid != pseudo_rgid && egid != pseudo_sgid) {
rc = -1;
errno = EPERM;
}
if (rc != -1) {
if (rgid != -1)
if (rgid != (gid_t) -1)
pseudo_rgid = rgid;
if (egid != -1)
if (egid != (gid_t) -1)
pseudo_egid = egid;
pseudo_fgid = pseudo_egid;
pseudo_client_touchuid();
Expand Down
12 changes: 6 additions & 6 deletions guts/setresgid.c
Expand Up @@ -4,27 +4,27 @@
* int rc = -1;
*/
rc = 0;
if (pseudo_euid != 0 && rgid != -1 &&
if (pseudo_euid != 0 && rgid != (gid_t) -1 &&
rgid != pseudo_egid && rgid != pseudo_rgid && rgid != pseudo_sgid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && egid != -1 &&
if (pseudo_euid != 0 && egid != (gid_t) -1 &&
egid != pseudo_egid && egid != pseudo_rgid && egid != pseudo_sgid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && sgid != -1 &&
if (pseudo_euid != 0 && sgid != (gid_t) -1 &&
sgid != pseudo_egid && sgid != pseudo_rgid && sgid != pseudo_sgid) {
rc = -1;
errno = EPERM;
}
if (rc != -1) {
if (rgid != -1)
if (rgid != (gid_t) -1)
pseudo_rgid = rgid;
if (egid != -1)
if (egid != (gid_t) -1)
pseudo_egid = egid;
if (sgid != -1)
if (sgid != (gid_t) -1)
pseudo_sgid = sgid;
pseudo_fgid = pseudo_egid;
pseudo_client_touchuid();
Expand Down
12 changes: 6 additions & 6 deletions guts/setresuid.c
Expand Up @@ -4,27 +4,27 @@
* int rc = -1;
*/
rc = 0;
if (pseudo_euid != 0 && ruid != -1 &&
if (pseudo_euid != 0 && ruid != (uid_t) -1 &&
ruid != pseudo_euid && ruid != pseudo_ruid && ruid != pseudo_suid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && euid != -1 &&
if (pseudo_euid != 0 && euid != (uid_t) -1 &&
euid != pseudo_euid && euid != pseudo_ruid && euid != pseudo_suid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && suid != -1 &&
if (pseudo_euid != 0 && suid != (uid_t) -1 &&
suid != pseudo_euid && suid != pseudo_ruid && suid != pseudo_suid) {
rc = -1;
errno = EPERM;
}
if (rc != -1) {
if (ruid != -1)
if (ruid != (uid_t) -1)
pseudo_ruid = ruid;
if (euid != -1)
if (euid != (uid_t) -1)
pseudo_euid = euid;
if (suid != -1)
if (suid != (uid_t) -1)
pseudo_suid = suid;
pseudo_fuid = pseudo_euid;
pseudo_client_touchuid();
Expand Down
8 changes: 4 additions & 4 deletions guts/setreuid.c
Expand Up @@ -4,20 +4,20 @@
* int rc = -1;
*/
rc = 0;
if (pseudo_euid != 0 && ruid != -1 &&
if (pseudo_euid != 0 && ruid != (uid_t) -1 &&
ruid != pseudo_euid && ruid != pseudo_ruid && ruid != pseudo_suid) {
rc = -1;
errno = EPERM;
}
if (pseudo_euid != 0 && euid != -1 &&
if (pseudo_euid != 0 && euid != (uid_t) -1 &&
euid != pseudo_euid && euid != pseudo_ruid && euid != pseudo_suid) {
rc = -1;
errno = EPERM;
}
if (rc != -1) {
if (ruid != -1)
if (ruid != (uid_t) -1)
pseudo_ruid = ruid;
if (euid != -1)
if (euid != (uid_t) -1)
pseudo_euid = euid;
pseudo_fuid = pseudo_euid;
pseudo_client_touchuid();
Expand Down
6 changes: 5 additions & 1 deletion makewrappers
Expand Up @@ -163,6 +163,7 @@ do
set -- $args
IFS=$save_IFS
args=''
dummy_args=''
optional_arg=false
prepend=''
depth=0
Expand Down Expand Up @@ -207,6 +208,7 @@ do
...*)
optional_arg=true
args="$args${args:+, }..."
dummy_args="$dummy_args${dummy_args:+, }..."
arg=`expr "$arg" : '\.\.\.{\(.*\)}'`
argname=`expr "$arg" : '.*[^a-zA-Z0-9_]\([a-zA-Z0-9_]*\)$'`
argnames="$argnames${argnames:+, }$argname"
Expand All @@ -221,13 +223,15 @@ do
*\(*) # function pointer
argname=`expr "$arg" : '[^(]*(\*\([a-zA-Z0-9_]*\).*'`
args="$args${args:+, }$arg"
dummy_args="$dummy_args${dummy_args:+, }$arg __attribute__((unused))"
wrapargnames="$wrapargnames${wrapargnames:+, }$argname"
argnames="$argnames${argnames:+, }$argname"
prev_argname=$argname
;;
*)
argname=`expr "$arg" : '.*[^a-zA-Z0-9_](*\([a-zA-Z0-9_]*\))*(*)*$'`
args="$args${args:+, }$arg"
dummy_args="$dummy_args${dummy_args:+, }$arg __attribute__((unused))"
# special handling for canonicalization
# set this before changing path -> rpath, for guts files
wrapargnames="$wrapargnames${wrapargnames:+, }$argname"
Expand Down Expand Up @@ -278,7 +282,7 @@ Unknown type '$type'." ; exit 1 ;;
# first the dummy, and the function pointer:
cat >&5 <<EOF
static $type
dummy_$name($args) {
dummy_$name($dummy_args) {
pseudo_enosys("$name");
errno = ENOSYS;
return $default_value;
Expand Down
2 changes: 1 addition & 1 deletion pseudo.c
Expand Up @@ -267,7 +267,7 @@ main(int argc, char *argv[]) {
int
pseudo_op(pseudo_msg_t *msg, const char *tag) {
pseudo_msg_t msg_header;
pseudo_msg_t by_path = { 0 }, by_ino = { 0 };
pseudo_msg_t by_path = { .op = 0 }, by_ino = { .op = 0 };
pseudo_msg_t db_header;
char *path_by_ino = 0;
char *oldpath = 0;
Expand Down
18 changes: 9 additions & 9 deletions pseudo_client.c
Expand Up @@ -51,18 +51,18 @@ char *pseudo_cwd_rel = 0;
static char **fd_paths = 0;
static int nfds = 0;
static int messages = 0;
static struct timeval message_time = { 0 };
static struct timeval message_time = { .tv_sec = 0 };
static int pseudo_inited = 0;

/* note: these are int, not uid_t/gid_t, so I can use 'em with scanf */
int pseudo_ruid;
int pseudo_euid;
int pseudo_suid;
int pseudo_fuid;
int pseudo_rgid;
int pseudo_egid;
int pseudo_sgid;
int pseudo_fgid;
uid_t pseudo_ruid;
uid_t pseudo_euid;
uid_t pseudo_suid;
uid_t pseudo_fuid;
gid_t pseudo_rgid;
gid_t pseudo_egid;
gid_t pseudo_sgid;
gid_t pseudo_fgid;

void
pseudo_client_touchuid(void) {
Expand Down
16 changes: 8 additions & 8 deletions pseudo_client.h
Expand Up @@ -31,14 +31,14 @@ extern void pseudo_stat64_from32(struct stat64 *, struct stat *);
#define MOVE_FD 0
#define COPY_FD 1
#define PSEUDO_MIN_FD 20
extern int pseudo_euid;
extern int pseudo_fuid;
extern int pseudo_suid;
extern int pseudo_ruid;
extern int pseudo_egid;
extern int pseudo_sgid;
extern int pseudo_rgid;
extern int pseudo_fgid;
extern uid_t pseudo_euid;
extern uid_t pseudo_fuid;
extern uid_t pseudo_suid;
extern uid_t pseudo_ruid;
extern gid_t pseudo_egid;
extern gid_t pseudo_sgid;
extern gid_t pseudo_rgid;
extern gid_t pseudo_fgid;
extern int pseudo_dir_fd;

/* support related to chroot/getcwd/etc. */
Expand Down
4 changes: 2 additions & 2 deletions pseudo_db.c
Expand Up @@ -801,7 +801,7 @@ frag(buffer *b, char *fmt, ...) {
va_start(ap, fmt);
rc = vsnprintf(b->tail, b->buflen - curlen, fmt, ap);
va_end(ap);
if (rc >= (b->buflen - curlen)) {
if ((rc > 0) && ((size_t) rc >= (b->buflen - curlen))) {
size_t newlen = b->buflen;
while (newlen <= (rc + curlen))
newlen *= 2;
Expand All @@ -819,7 +819,7 @@ frag(buffer *b, char *fmt, ...) {
va_start(ap, fmt);
rc = vsnprintf(b->tail, b->buflen - curlen, fmt, ap);
va_end(ap);
if (rc >= (b->buflen - curlen)) {
if ((rc > 0) && ((size_t) rc >= (b->buflen - curlen))) {
pseudo_diag("tried to reallocate larger buffer, failed. giving up.\n");
return -1;
}
Expand Down

0 comments on commit caeebc0

Please sign in to comment.