summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2004-04-25 03:21:51 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2004-04-25 03:21:51 +0000
commit93885bdb6d435228a4c7643860a6af619d415821 (patch)
tree699694ab0935ece750b4a60313cfe8cd45408b6b
parent3e5d9ff053f702e35da7618abfdd2e022658e9a9 (diff)
kill unbounded string op. deraadt ok
-rw-r--r--sys/ddb/db_command.c4
-rw-r--r--sys/ddb/db_examine.c34
-rw-r--r--sys/ddb/db_extern.h4
3 files changed, 30 insertions, 12 deletions
diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c
index caf9460f5c5..f62fff34850 100644
--- a/sys/ddb/db_command.c
+++ b/sys/ddb/db_command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_command.c,v 1.34 2004/03/15 12:56:29 aaron Exp $ */
+/* $OpenBSD: db_command.c,v 1.35 2004/04/25 03:21:50 itojun Exp $ */
/* $NetBSD: db_command.c,v 1.20 1996/03/30 22:30:05 christos Exp $ */
/*
@@ -224,7 +224,7 @@ db_command(last_cmdp, cmd_table)
db_flush_lex();
return;
}
- db_strcpy(modif, db_tok_string);
+ db_strlcpy(modif, db_tok_string, sizeof(modif));
}
else {
db_unread_token(t);
diff --git a/sys/ddb/db_examine.c b/sys/ddb/db_examine.c
index 07cfc896500..c8e4fc03c0a 100644
--- a/sys/ddb/db_examine.c
+++ b/sys/ddb/db_examine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_examine.c,v 1.10 2002/05/16 13:01:41 art Exp $ */
+/* $OpenBSD: db_examine.c,v 1.11 2004/04/25 03:21:50 itojun Exp $ */
/* $NetBSD: db_examine.c,v 1.11 1996/03/30 22:30:07 christos Exp $ */
/*
@@ -64,7 +64,7 @@ db_examine_cmd(addr, have_addr, count, modif)
char * modif;
{
if (modif[0] != '\0')
- db_strcpy(db_examine_format, modif);
+ db_strlcpy(db_examine_format, modif, sizeof(db_examine_format));
if (count == -1)
count = 1;
@@ -241,13 +241,31 @@ db_print_loc_and_inst(loc)
(void) db_disasm(loc, FALSE);
}
-void
-db_strcpy(dst, src)
- register char *dst;
- register char *src;
+/* local copy is needed here so that we can trace strlcpy() in libkern */
+size_t
+db_strlcpy(char *dst, const char *src, size_t siz)
{
- while ((*dst++ = *src++) != '\0')
- ;
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
}
/*
diff --git a/sys/ddb/db_extern.h b/sys/ddb/db_extern.h
index 7557661c615..740590673b1 100644
--- a/sys/ddb/db_extern.h
+++ b/sys/ddb/db_extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_extern.h,v 1.11 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: db_extern.h,v 1.12 2004/04/25 03:21:50 itojun Exp $ */
/* $NetBSD: db_extern.h,v 1.1 1996/02/05 01:57:00 christos Exp $ */
/*
@@ -40,7 +40,7 @@ void db_examine_cmd(db_expr_t, int, db_expr_t, char *);
void db_examine(db_addr_t, char *, int);
void db_print_cmd(db_expr_t, int, db_expr_t, char *);
void db_print_loc_and_inst(db_addr_t);
-void db_strcpy(char *, char *);
+size_t db_strlcpy(char *, const char *, size_t);
void db_search_cmd(db_expr_t, boolean_t, db_expr_t, char *);
void db_search(db_addr_t, int, db_expr_t, db_expr_t, db_expr_t);