summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_cmds.c6
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_nv.c27
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_nv.h14
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_tab.c31
4 files changed, 34 insertions, 44 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_cmds.c b/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
index add7845c68..af45b70ca3 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
@@ -27,6 +27,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2013 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
*/
#include <sys/elf.h>
@@ -1563,11 +1564,6 @@ showrev_addversion(void *vers_nv, const mdb_map_t *ignored, const char *object)
if (version == NULL)
version = "Unknown";
- /*
- * The hash table implementation in OVERLOAD mode limits the version
- * name to 31 characters because we cannot specify an external name.
- * The full version name is available via the ::objects dcmd if needed.
- */
(void) mdb_nv_insert(vers_nv, version, NULL, (uintptr_t)objname,
MDB_NV_OVERLOAD);
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_nv.c b/usr/src/cmd/mdb/common/mdb/mdb_nv.c
index 0878f1284a..e030359888 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_nv.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_nv.c
@@ -23,8 +23,9 @@
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-
-#pragma ident "%Z%%M% %I% %E% SMI"
+/*
+ * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ */
#include <mdb/mdb_debug.h>
#include <mdb/mdb_string.h>
@@ -38,7 +39,7 @@
#define NV_SIZE(v) \
(((v)->v_flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) : \
- sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1)
+ sizeof (mdb_var_t) + strlen((v)->v_lname))
#define NV_HASHSZ 211
@@ -66,20 +67,28 @@ static mdb_var_t *
nv_var_alloc(const char *name, const mdb_nv_disc_t *disc,
uintmax_t value, uint_t flags, uint_t um_flags, mdb_var_t *next)
{
- size_t nbytes = (flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) :
- (sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1);
+ size_t nbytes;
+ mdb_var_t *v;
+
+ if (flags & MDB_NV_EXTNAME)
+ nbytes = sizeof (mdb_var_t);
+ else
+ nbytes = sizeof (mdb_var_t) + strlen(name);
- mdb_var_t *v = mdb_alloc(nbytes, um_flags);
+ v = mdb_alloc(nbytes, um_flags);
if (v == NULL)
return (NULL);
if (flags & MDB_NV_EXTNAME) {
v->v_ename = name;
- v->v_lname[0] = 0;
+ v->v_lname[0] = '\0';
} else {
- (void) strncpy(v->v_lname, name, MDB_NV_NAMELEN - 1);
- v->v_lname[MDB_NV_NAMELEN - 1] = '\0';
+ /*
+ * We don't overflow here since the mdb_var_t itself has
+ * room for the trailing \0.
+ */
+ (void) strcpy(v->v_lname, name);
v->v_ename = NULL;
}
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_nv.h b/usr/src/cmd/mdb/common/mdb/mdb_nv.h
index e3cf8164c9..efd3823a6a 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_nv.h
+++ b/usr/src/cmd/mdb/common/mdb/mdb_nv.h
@@ -23,12 +23,13 @@
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ */
#ifndef _MDB_NV_H
#define _MDB_NV_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#ifdef __cplusplus
@@ -37,6 +38,11 @@ extern "C" {
#ifdef _MDB
+/*
+ * There used to be a cap (MDB_NV_NAMELEN bytes including null) on the
+ * length of variable names stored in-line. This cap is no longer there,
+ * however parts of mdb use the constant to sanitize input.
+ */
#define MDB_NV_NAMELEN 31 /* Max variable name length including null */
/*
@@ -74,8 +80,8 @@ typedef struct mdb_nv_disc {
* we make a few simple space optimizations:
*
* A variable's name can be a pointer to external storage (v_ename and
- * MDB_NV_EXTNAME set), or it can be stored locally (MDB_NV_NAMELEN - 1
- * bytes of storage are allocated immediately after v_lname[0]).
+ * MDB_NV_EXTNAME set), or it can be stored locally (bytes of storage are
+ * allocated immediately after v_lname[0]).
*
* A variable may have multiple definitions (v_ndef chain), but this feature
* is mutually exclusive with MDB_NV_EXTNAME in order to save space.
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_tab.c b/usr/src/cmd/mdb/common/mdb/mdb_tab.c
index 8b43ecdb12..541acadbc2 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_tab.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_tab.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
*/
/*
* This file contains all of the interfaces for mdb's tab completion engine.
@@ -394,11 +395,8 @@ mdb_tab_size(mdb_tab_cookie_t *mcp)
void
mdb_tab_insert(mdb_tab_cookie_t *mcp, const char *name)
{
- size_t len, matches, index;
- uint_t flags;
+ size_t matches, index;
mdb_var_t *v;
- char *n;
- const char *nvn;
/*
* If we have a match set, then we want to verify that we actually match
@@ -412,34 +410,15 @@ mdb_tab_insert(mdb_tab_cookie_t *mcp, const char *name)
if (v != NULL)
return;
- /*
- * Names that we get passed in may be longer than MDB_NV_NAMELEN which
- * is currently 31 including the null terminator. If that is the case,
- * then we're going to take care of allocating a string and holding it
- * for our caller. Note that we don't need to free it, because we're
- * allocating this with UM_GC.
- */
- flags = 0;
- len = strlen(name);
- if (len > MDB_NV_NAMELEN - 1) {
- n = mdb_alloc(len + 1, UM_SLEEP | UM_GC);
- (void) strcpy(n, name);
- nvn = n;
- flags |= MDB_NV_EXTNAME;
- } else {
- nvn = name;
- }
- flags |= MDB_NV_RDONLY;
-
- (void) mdb_nv_insert(&mcp->mtc_nv, nvn, NULL, 0, flags);
+ (void) mdb_nv_insert(&mcp->mtc_nv, name, NULL, 0, MDB_NV_RDONLY);
matches = mdb_tab_size(mcp);
if (matches == 1) {
- (void) strlcpy(mcp->mtc_match, nvn, MDB_SYM_NAMLEN);
+ (void) strlcpy(mcp->mtc_match, name, MDB_SYM_NAMLEN);
} else {
index = 0;
while (mcp->mtc_match[index] &&
- mcp->mtc_match[index] == nvn[index])
+ mcp->mtc_match[index] == name[index])
index++;
mcp->mtc_match[index] = '\0';