Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libp2k Make P2K_WIZARDUID require a valid integer instea...



details:   https://anonhg.NetBSD.org/src/rev/c214dc909b15
branches:  trunk
changeset: 760567:c214dc909b15
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Jan 07 16:02:32 2011 +0000

description:
Make P2K_WIZARDUID require a valid integer instead of defaulting to root.

diffstat:

 lib/libp2k/p2k.3 |   6 ++----
 lib/libp2k/p2k.c |  17 ++++++++++++-----
 2 files changed, 14 insertions(+), 9 deletions(-)

diffs (52 lines):

diff -r 9fc7c72a8666 -r c214dc909b15 lib/libp2k/p2k.3
--- a/lib/libp2k/p2k.3  Fri Jan 07 15:50:40 2011 +0000
+++ b/lib/libp2k/p2k.3  Fri Jan 07 16:02:32 2011 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: p2k.3,v 1.9 2011/01/07 15:50:40 pooka Exp $
+.\"     $NetBSD: p2k.3,v 1.10 2011/01/07 16:02:32 pooka Exp $
 .\"
 .\" Copyright (c) 2008 Antti Kantee.  All rights reserved.
 .\"
@@ -118,10 +118,8 @@
 If set, use the value of the variable to determine the UID of the
 caller of each operation instead of the actual caller supplied by
 .Xr puffs 3 .
-This can be used for example to simplify modifying an OS installations
+This can be used for example to simplify modifying an OS installation's
 root image as a non-root user.
-If the variable is set but does not contain an integer value, 0
-(root) is used.
 .El
 .Sh SEE ALSO
 .Xr puffs 3 ,
diff -r 9fc7c72a8666 -r c214dc909b15 lib/libp2k/p2k.c
--- a/lib/libp2k/p2k.c  Fri Jan 07 15:50:40 2011 +0000
+++ b/lib/libp2k/p2k.c  Fri Jan 07 16:02:32 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: p2k.c,v 1.53 2011/01/07 15:47:14 pooka Exp $   */
+/*     $NetBSD: p2k.c,v 1.54 2011/01/07 16:02:32 pooka Exp $   */
 
 /*
  * Copyright (c) 2007, 2008, 2009  Antti Kantee.  All Rights Reserved.
@@ -344,10 +344,17 @@
                puffs_flags |= PUFFS_KFLAG_NOCACHE;
        }
        if ((envbuf = getenv("P2K_WIZARDUID")) != NULL) {
-               /* default to 0 in error cases */
-               wizarduid = atoi(envbuf);
-               haswizard = 1;
-               printf("P2K WIZARD MODE: using uid %d\n", wizarduid);
+               char *ep;
+
+               wizarduid = strtoul(envbuf, &ep, 10);
+               if (envbuf[0] == '\0' || *ep != '\0') {
+                       printf("P2K_WIZARDUID: invalid uid %s\n", envbuf);
+               } else if (wizarduid > UID_MAX) {
+                       printf("P2K_WIZARDUID: uid %s out-of-range\n", envbuf);
+               } else {
+                       haswizard = 1;
+                       printf("P2K WIZARD MODE: using uid %d\n", wizarduid);
+               }
        }
 
        p2m = allocp2m();



Home | Main Index | Thread Index | Old Index