summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/ranlib/build.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/usr.bin/ranlib/build.c b/usr.bin/ranlib/build.c
index 3577f3fc792..abb0407aff5 100644
--- a/usr.bin/ranlib/build.c
+++ b/usr.bin/ranlib/build.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: build.c,v 1.2 1996/06/26 05:38:03 deraadt Exp $ */
+/* $OpenBSD: build.c,v 1.3 1997/11/05 18:57:27 deraadt Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)build.c 5.3 (Berkeley) 3/12/91";*/
-static char rcsid[] = "$OpenBSD: build.c,v 1.2 1996/06/26 05:38:03 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: build.c,v 1.3 1997/11/05 18:57:27 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -224,6 +224,8 @@ symobj()
struct ranlib rn;
char hb[sizeof(struct ar_hdr) + 1], pad;
long ransize, size, stroff;
+ uid_t uid;
+ gid_t gid;
/* Rewind the archive, leaving the magic number. */
if (fseek(fp, (off_t)SARMAG, SEEK_SET) == (off_t)-1)
@@ -238,9 +240,20 @@ symobj()
} else
pad = '\0';
+ uid = getuid();
+ if (uid > USHRT_MAX) {
+ warnx("warning: uid %d truncated to %d", uid, USHRT_MAX);
+ uid = USHRT_MAX;
+ }
+ gid = getgid();
+ if (gid > USHRT_MAX) {
+ warnx("warning: gid %d truncated to %d", gid, USHRT_MAX);
+ gid = USHRT_MAX;
+ }
+
/* Put out the ranlib archive file header. */
#define DEFMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
- (void)sprintf(hb, HDR2, RANLIBMAG, 0L, getuid(), getgid(),
+ (void)sprintf(hb, HDR2, RANLIBMAG, 0L, uid, gid,
DEFMODE & ~umask(0), (off_t)ransize, ARFMAG);
if (!fwrite(hb, sizeof(struct ar_hdr), 1, fp))
error(tname);