summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2004-02-18 03:27:23 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2004-02-18 03:27:23 +0000
commit2a6df610fb46624daf1a07c7fc76c336d42de1c2 (patch)
tree8ce8746965f7efef099973c8c816617e7cf1876a
parentcc6e3ac8fcc951790368332053fd875a006d8c9f (diff)
little cleanup. strlcat. usage. don't call atoi on non-numbers.
mostly spotted by deraadt@
-rw-r--r--usr.sbin/procmap/procmap.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/usr.sbin/procmap/procmap.c b/usr.sbin/procmap/procmap.c
index c97b6de9b0b..7dd918b2170 100644
--- a/usr.sbin/procmap/procmap.c
+++ b/usr.sbin/procmap/procmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: procmap.c,v 1.4 2004/02/18 00:46:25 tedu Exp $ */
+/* $OpenBSD: procmap.c,v 1.5 2004/02/18 03:27:22 tedu Exp $ */
/* $NetBSD: pmap.c,v 1.1 2002/09/01 20:32:44 atatat Exp $ */
/*
@@ -192,6 +192,7 @@ char *findname(kvm_t *, struct kbit *, struct kbit *, struct kbit *,
int search_cache(kvm_t *, struct kbit *, char **, char *, size_t);
void load_name_cache(kvm_t *);
void cache_enter(struct namecache *);
+static void __dead usage(void);
int
main(int argc, char *argv[])
@@ -204,7 +205,6 @@ main(int argc, char *argv[])
struct kinfo_proc *kproc;
/* struct proc proc; */
char *kmem, *kernel;
- extern char *__progname;
pid = -1;
verbose = debug = 0;
@@ -235,6 +235,8 @@ main(int argc, char *argv[])
kernel = optarg;
break;
case 'p':
+ if (!isdigit(optarg[0]))
+ usage();
pid = atoi(optarg);
break;
case 'P':
@@ -252,10 +254,7 @@ main(int argc, char *argv[])
/*NOTREACHED*/
case '?':
default:
- fprintf(stderr, "usage: %s [-adlmPsv] [-D number] "
- "[-M core] [-N system] [-p pid] [pid ...]\n",
- __progname);
- exit(1);
+ usage();
}
}
argc -= optind;
@@ -283,6 +282,8 @@ main(int argc, char *argv[])
if (argc == 0)
pid = getppid();
else {
+ if (!isdigit(argv[0][0]))
+ usage();
pid = atoi(argv[0]);
argv++;
argc--;
@@ -689,11 +690,11 @@ dump_vm_map_entry(kvm_t *kd, struct kbit *vmspace,
prot[0] = '\0';
prot[1] = '\0';
if (vme->protection & VM_PROT_READ)
- strcat(prot, "/read");
+ strlcat(prot, "/read", sizeof(prot));
if (vme->protection & VM_PROT_WRITE)
- strcat(prot, "/write");
+ strlcat(prot, "/write", sizeof(prot));
if (vme->protection & VM_PROT_EXECUTE)
- strcat(prot, "/exec");
+ strlcat(prot, "/exec", sizeof(prot));
sz = (size_t)((vme->end - vme->start) / 1024);
printf("%0*lX %6luK %-15s %s\n",
@@ -933,3 +934,13 @@ cache_enter(struct namecache *ncp)
LIST_INSERT_HEAD(&lcache, ce, ce_next);
}
+
+static void __dead
+usage(void)
+{
+ extern char *__progname;
+ fprintf(stderr, "usage: %s [-adlmPsv] [-D number] "
+ "[-M core] [-N system] [-p pid] [pid ...]\n",
+ __progname);
+ exit(1);
+}