diff options
| author | Bryan Cantrill <bryan@joyent.com> | 2017-05-12 20:53:05 +0000 |
|---|---|---|
| committer | Bryan Cantrill <bryan@joyent.com> | 2017-05-15 23:42:11 +0000 |
| commit | c5bf6dbcaf952d0108897703c878c1c0eb4be27f (patch) | |
| tree | 824a414cbcbfaa82d814f9e40a949f3ceb739a5f /usr/src/cmd/dlstat | |
| parent | d7b3c0f0f9f6c7bd9fbafc475db0d96a54372712 (diff) | |
| download | illumos-joyent-c5bf6dbcaf952d0108897703c878c1c0eb4be27f.tar.gz | |
OS-6057 dladm show-link segfaults if you specify too many fields
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Ryan Zezeski <ryan.zeseski@joyent.com>
Approved by: Ryan Zezeski <ryan.zeseski@joyent.com>
Diffstat (limited to 'usr/src/cmd/dlstat')
| -rw-r--r-- | usr/src/cmd/dlstat/dlstat.c | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/usr/src/cmd/dlstat/dlstat.c b/usr/src/cmd/dlstat/dlstat.c index 2615fdbb12..8c1749475b 100644 --- a/usr/src/cmd/dlstat/dlstat.c +++ b/usr/src/cmd/dlstat/dlstat.c @@ -23,6 +23,10 @@ * Use is subject to license terms. */ +/* + * Copyright 2017 Joyent, Inc. + */ + #include <stdio.h> #include <ctype.h> #include <locale.h> @@ -88,8 +92,6 @@ typedef struct show_history_state_s { */ static ofmt_cb_t print_default_cb; -static void dlstat_ofmt_check(ofmt_status_t, boolean_t, ofmt_handle_t); - typedef void cmdfunc_t(int, char **, const char *); static cmdfunc_t do_show, do_show_history, do_show_phys, do_show_link; @@ -782,7 +784,7 @@ do_show_history(int argc, char *argv[], const char *use) &ofmt); } - dlstat_ofmt_check(oferr, state.hs_parsable, ofmt); + ofmt_check(oferr, state.hs_parsable, ofmt, die, warn); state.hs_ofmt = ofmt; if (d_arg) { @@ -992,7 +994,7 @@ done: } void * -print_rx_generic_ring_stats(const char *linkname, const char *zonename, +print_rx_generic_ring_stats(const char *linkname, const char *zonename, void *statentry, char unit, boolean_t parsable) { ring_stat_entry_t *sentry = statentry; @@ -1288,7 +1290,8 @@ done: void * print_tx_lane_stats(const char *linkname, const char *zonename, void *statentry, - char unit, boolean_t parsable) { + char unit, boolean_t parsable) +{ tx_lane_stat_entry_t *sentry = statentry; tx_lane_stat_t *link_stats = &sentry->tle_stats; tx_lane_fields_buf_t *buf = NULL; @@ -1814,7 +1817,7 @@ do_show(int argc, char *argv[], const char *use) } oferr = ofmt_open(fields_str, oftemplate, ofmtflags, 0, &ofmt); - dlstat_ofmt_check(oferr, state.ls_parsable, ofmt); + ofmt_check(oferr, state.ls_parsable, ofmt, die, warn); state.ls_ofmt = ofmt; show_link_stats(linkid, state, interval); @@ -1993,7 +1996,7 @@ do_show_phys(int argc, char *argv[], const char *use) } oferr = ofmt_open(fields_str, oftemplate, ofmtflags, 0, &ofmt); - dlstat_ofmt_check(oferr, state.ls_parsable, ofmt); + ofmt_check(oferr, state.ls_parsable, ofmt, die, warn); state.ls_ofmt = ofmt; show_link_stats(linkid, state, interval); @@ -2203,7 +2206,7 @@ do_show_link(int argc, char *argv[], const char *use) } oferr = ofmt_open(fields_str, oftemplate, ofmtflags, 0, &ofmt); - dlstat_ofmt_check(oferr, state.ls_parsable, ofmt); + ofmt_check(oferr, state.ls_parsable, ofmt, die, warn); state.ls_ofmt = ofmt; @@ -2340,7 +2343,7 @@ do_show_aggr(int argc, char *argv[], const char *use) } oferr = ofmt_open(fields_str, oftemplate, ofmtflags, 0, &ofmt); - dlstat_ofmt_check(oferr, state.ls_parsable, ofmt); + ofmt_check(oferr, state.ls_parsable, ofmt, die, warn); state.ls_ofmt = ofmt; show_link_stats(linkid, state, interval); @@ -2446,26 +2449,3 @@ print_default_cb(ofmt_arg_t *ofarg, char *buf, uint_t bufsize) (void) strlcpy(buf, value, bufsize); return (B_TRUE); } - -static void -dlstat_ofmt_check(ofmt_status_t oferr, boolean_t parsable, - ofmt_handle_t ofmt) -{ - char buf[OFMT_BUFSIZE]; - - if (oferr == OFMT_SUCCESS) - return; - (void) ofmt_strerror(ofmt, oferr, buf, sizeof (buf)); - /* - * All errors are considered fatal in parsable mode. - * NOMEM errors are always fatal, regardless of mode. - * For other errors, we print diagnostics in human-readable - * mode and processs what we can. - */ - if (parsable || oferr == OFMT_ENOFIELDS) { - ofmt_close(ofmt); - die(buf); - } else { - warn(buf); - } -} |
