summaryrefslogtreecommitdiff
path: root/usr.sbin/altq/altqstat
diff options
context:
space:
mode:
authorKenjiro Cho <kjc@cvs.openbsd.org>2001-08-16 12:59:44 +0000
committerKenjiro Cho <kjc@cvs.openbsd.org>2001-08-16 12:59:44 +0000
commitb5c8e7c1615165eaa2f24583a32abe1059bea123 (patch)
treecd2bd3c3763dd3e03ab4e2c08f93d6fc11feac9a /usr.sbin/altq/altqstat
parentd64a7d79fc33fe1332cb6af09067b0140772da17 (diff)
sync with KAME.
altq userland cleanup: - string operation audit - remove variable names from function prototypes - clean up error messages
Diffstat (limited to 'usr.sbin/altq/altqstat')
-rw-r--r--usr.sbin/altq/altqstat/altqstat.c20
-rw-r--r--usr.sbin/altq/altqstat/altqstat.h22
-rw-r--r--usr.sbin/altq/altqstat/qdisc_blue.c7
-rw-r--r--usr.sbin/altq/altqstat/qdisc_cbq.c9
-rw-r--r--usr.sbin/altq/altqstat/qdisc_cdnr.c11
-rw-r--r--usr.sbin/altq/altqstat/qdisc_conf.c8
-rw-r--r--usr.sbin/altq/altqstat/qdisc_fifoq.c5
-rw-r--r--usr.sbin/altq/altqstat/qdisc_hfsc.c9
-rw-r--r--usr.sbin/altq/altqstat/qdisc_priq.c9
-rw-r--r--usr.sbin/altq/altqstat/qdisc_red.c7
-rw-r--r--usr.sbin/altq/altqstat/qdisc_rio.c7
-rw-r--r--usr.sbin/altq/altqstat/qdisc_wfq.c5
-rw-r--r--usr.sbin/altq/altqstat/quip_client.c51
-rw-r--r--usr.sbin/altq/altqstat/quip_client.h23
14 files changed, 106 insertions, 87 deletions
diff --git a/usr.sbin/altq/altqstat/altqstat.c b/usr.sbin/altq/altqstat/altqstat.c
index 5c66b740d79..ec4baeaa965 100644
--- a/usr.sbin/altq/altqstat/altqstat.c
+++ b/usr.sbin/altq/altqstat/altqstat.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: altqstat.c,v 1.1 2001/06/27 18:23:19 kjc Exp $ */
-/* $KAME: altqstat.c,v 1.4 2000/12/03 05:44:19 kawa Exp $ */
+/* $OpenBSD: altqstat.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: altqstat.c,v 1.6 2001/08/16 07:43:14 itojun Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -55,7 +55,7 @@ char *qdisc_name = NULL;
stat_loop_t *stat_loop;
-static void sig_handler(int sig);
+static void sig_handler(int);
static void usage(void);
static void
@@ -90,7 +90,7 @@ main (int argc, char **argv)
while ((ch = getopt(argc, argv, "I:c:ei:nrsw:")) != -1) {
switch (ch) {
case 'I':
- sprintf(input, "_%s", optarg);
+ snprintf(input, sizeof(input), "_%s", optarg);
interface = input;
break;
case 'c':
@@ -161,7 +161,7 @@ main (int argc, char **argv)
printf("%s: %s on interface %s\n",
argv[0], qdisc_name, interface);
- sprintf(device, "%s/%s", DEV_PATH, qdisc_name);
+ snprintf(device, sizeof(device), "%s/%s", DEV_PATH, qdisc_name);
if ((qdiscfd = open(device, O_RDONLY)) < 0)
err(1, "can't open %s", device);
@@ -204,12 +204,12 @@ calc_pps(u_int64_t new_pkts, u_int64_t last_pkts, double interval)
}
#define R2S_BUFS 8
-
+#define RATESTR_MAX 16
char *
rate2str(double rate)
{
char *buf;
- static char r2sbuf[R2S_BUFS][16]; /* ring bufer for up to R2S_BUFS */
+ static char r2sbuf[R2S_BUFS][RATESTR_MAX]; /* ring bufer */
static int idx = 0;
buf = r2sbuf[idx++];
@@ -217,10 +217,10 @@ rate2str(double rate)
idx = 0;
if (rate == 0.0)
- sprintf(buf, "0");
+ snprintf(buf, RATESTR_MAX, "0");
else if (rate >= 1000000.0)
- sprintf(buf, "%.2fM", rate / 1000000.0);
+ snprintf(buf, RATESTR_MAX, "%.2fM", rate / 1000000.0);
else
- sprintf(buf, "%.2fK", rate / 1000.0);
+ snprintf(buf, RATESTR_MAX, "%.2fK", rate / 1000.0);
return (buf);
}
diff --git a/usr.sbin/altq/altqstat/altqstat.h b/usr.sbin/altq/altqstat/altqstat.h
index 077d15ddac3..c33ea599560 100644
--- a/usr.sbin/altq/altqstat/altqstat.h
+++ b/usr.sbin/altq/altqstat/altqstat.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: altqstat.h,v 1.1 2001/06/27 18:23:19 kjc Exp $ */
-/* $KAME: altqstat.h,v 1.2 2000/10/18 09:15:16 kjc Exp $ */
+/* $OpenBSD: altqstat.h,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: altqstat.h,v 1.4 2001/08/16 07:43:14 itojun Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -53,15 +53,15 @@ stat_loop_t priq_stat_loop;
struct redstats;
-void chandle2name(const char *ifname, u_long handle, char *name);
-stat_loop_t *qdisc2stat_loop(const char *qdisc_name);
-int ifname2qdisc(const char *ifname, char *qname);
-double calc_interval(struct timeval *cur_time, struct timeval *last_time);
-double calc_rate(u_int64_t new_bytes, u_int64_t last_bytes, double interval);
-double calc_pps(u_int64_t new_pkts, u_int64_t last_pkts, double interval);
-char *rate2str(double rate);
-int print_redstats(struct redstats *rp);
-int print_riostats(struct redstats *rp);
+void chandle2name(const char *, u_long, char *, size_t);
+stat_loop_t *qdisc2stat_loop(const char *);
+int ifname2qdisc(const char *, char *);
+double calc_interval(struct timeval *, struct timeval *);
+double calc_rate(u_int64_t, u_int64_t, double);
+double calc_pps(u_int64_t, u_int64_t, double);
+char *rate2str(double);
+int print_redstats(struct redstats *);
+int print_riostats(struct redstats *);
diff --git a/usr.sbin/altq/altqstat/qdisc_blue.c b/usr.sbin/altq/altqstat/qdisc_blue.c
index f540f8b2ddf..611ae52f8a9 100644
--- a/usr.sbin/altq/altqstat/qdisc_blue.c
+++ b/usr.sbin/altq/altqstat/qdisc_blue.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_blue.c,v 1.1 2001/06/27 18:23:19 kjc Exp $ */
-/* $KAME: qdisc_blue.c,v 1.2 2000/10/18 09:15:16 kjc Exp $ */
+/* $OpenBSD: qdisc_blue.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_blue.c,v 1.3 2001/08/15 12:51:58 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -54,7 +54,8 @@ blue_stat_loop(int fd, const char *ifname, int count, int interval)
double sec;
int cnt = count;
- strcpy(blue_stats.iface.blue_ifname, ifname);
+ strlcpy(blue_stats.iface.blue_ifname, ifname,
+ sizeof(blue_stats.iface.blue_ifname));
gettimeofday(&last_time, NULL);
last_time.tv_sec -= interval;
diff --git a/usr.sbin/altq/altqstat/qdisc_cbq.c b/usr.sbin/altq/altqstat/qdisc_cbq.c
index 7bf6b72d90a..4360cc169fe 100644
--- a/usr.sbin/altq/altqstat/qdisc_cbq.c
+++ b/usr.sbin/altq/altqstat/qdisc_cbq.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_cbq.c,v 1.1 2001/06/27 18:23:20 kjc Exp $ */
-/* $KAME: qdisc_cbq.c,v 1.3 2000/12/29 06:39:27 kjc Exp $ */
+/* $OpenBSD: qdisc_cbq.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_cbq.c,v 1.4 2001/08/15 12:51:58 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -68,7 +68,8 @@ cbq_stat_loop(int fd, const char *ifname, int count, int interval)
double flow_bps, sec;
int cnt = count;
- strcpy(get_stats.iface.cbq_ifacename, ifname);
+ strlcpy(get_stats.iface.cbq_ifacename, ifname,
+ sizeof(get_stats.iface.cbq_ifacename));
new = &stats1[0];
last = &stats2[0];
@@ -90,7 +91,7 @@ cbq_stat_loop(int fd, const char *ifname, int count, int interval)
if (sp->handle != clhandles[i]) {
quip_chandle2name(ifname, sp->handle,
- clnames[i]);
+ clnames[i], sizeof(clnames[0]));
clhandles[i] = sp->handle;
continue;
}
diff --git a/usr.sbin/altq/altqstat/qdisc_cdnr.c b/usr.sbin/altq/altqstat/qdisc_cdnr.c
index 8b5e525ae26..f2ebf23ed5f 100644
--- a/usr.sbin/altq/altqstat/qdisc_cdnr.c
+++ b/usr.sbin/altq/altqstat/qdisc_cdnr.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_cdnr.c,v 1.1 2001/06/27 18:23:20 kjc Exp $ */
-/* $KAME: qdisc_cdnr.c,v 1.3 2000/10/18 09:15:16 kjc Exp $ */
+/* $OpenBSD: qdisc_cdnr.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_cdnr.c,v 1.4 2001/08/15 12:51:58 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -69,9 +69,10 @@ cdnr_stat_loop(int fd, const char *ifname, int count, int interval)
if (ifname[0] == '_')
ifname++;
- sprintf(_ifname, "_%s", ifname);
+ snprintf(_ifname, sizeof(_ifname), "_%s", ifname);
- strcpy(get_stats.iface.cdnr_ifname, ifname);
+ strlcpy(get_stats.iface.cdnr_ifname, ifname,
+ sizeof(get_stats.iface.cdnr_ifname));
new = &stats1[0];
last = &stats2[0];
@@ -104,7 +105,7 @@ cdnr_stat_loop(int fd, const char *ifname, int count, int interval)
if (sp->tce_handle != lp->tce_handle) {
quip_chandle2name(_ifname, sp->tce_handle,
- cdnrnames[i]);
+ cdnrnames[i], sizeof(cdnrnames[0]));
continue;
}
diff --git a/usr.sbin/altq/altqstat/qdisc_conf.c b/usr.sbin/altq/altqstat/qdisc_conf.c
index e574d7a1af1..96331950dd8 100644
--- a/usr.sbin/altq/altqstat/qdisc_conf.c
+++ b/usr.sbin/altq/altqstat/qdisc_conf.c
@@ -1,4 +1,4 @@
-/* $KAME: qdisc_conf.c,v 1.3 2000/10/18 09:15:16 kjc Exp $ */
+/* $KAME: qdisc_conf.c,v 1.4 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -78,11 +78,11 @@ ifname2qdisc(const char *ifname, char *qname)
if (ifname[0] == '_') {
/* input interface */
if (qname != NULL)
- strcpy(qname, "cdnr");
+ strlcpy(qname, "cdnr", 64);
return (ALTQT_CDNR);
}
- strcpy(qtypereq.ifname, ifname);
+ strlcpy(qtypereq.ifname, ifname, sizeof(qtypereq.ifname));
if ((fd = open(ALTQ_DEVICE, O_RDONLY)) < 0) {
warn("can't open %s", ALTQ_DEVICE);
return (0);
@@ -99,7 +99,7 @@ ifname2qdisc(const char *ifname, char *qname)
qtype = qtypereq.arg;
for (stat = qdisc_table; stat->qdisc_name != NULL; stat++)
if (stat->altqtype == qtype)
- strcpy(qname, stat->qdisc_name);
+ strlcpy(qname, stat->qdisc_name, 64);
}
return (qtype);
diff --git a/usr.sbin/altq/altqstat/qdisc_fifoq.c b/usr.sbin/altq/altqstat/qdisc_fifoq.c
index bea260c40b7..69bbd5f452f 100644
--- a/usr.sbin/altq/altqstat/qdisc_fifoq.c
+++ b/usr.sbin/altq/altqstat/qdisc_fifoq.c
@@ -1,4 +1,4 @@
-/* $KAME: qdisc_fifoq.c,v 1.3 2000/10/18 09:15:16 kjc Exp $ */
+/* $KAME: qdisc_fifoq.c,v 1.4 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -53,7 +53,8 @@ fifoq_stat_loop(int fd, const char *ifname, int count, int interval)
double sec;
int cnt = count;
- strcpy(get_stats.iface.fifoq_ifname, ifname);
+ strlcpy(get_stats.iface.fifoq_ifname, ifname,
+ sizeof(get_stats.iface.fifoq_ifname));
gettimeofday(&last_time, NULL);
last_time.tv_sec -= interval;
diff --git a/usr.sbin/altq/altqstat/qdisc_hfsc.c b/usr.sbin/altq/altqstat/qdisc_hfsc.c
index 79c6213b662..7bf19e4e790 100644
--- a/usr.sbin/altq/altqstat/qdisc_hfsc.c
+++ b/usr.sbin/altq/altqstat/qdisc_hfsc.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_hfsc.c,v 1.1 2001/06/27 18:23:21 kjc Exp $ */
-/* $KAME: qdisc_hfsc.c,v 1.3 2000/10/18 09:15:17 kjc Exp $ */
+/* $OpenBSD: qdisc_hfsc.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_hfsc.c,v 1.4 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -60,7 +60,8 @@ hfsc_stat_loop(int fd, const char *ifname, int count, int interval)
double sec;
int cnt = count;
- strcpy(get_stats.iface.hfsc_ifname, ifname);
+ strlcpy(get_stats.iface.hfsc_ifname, ifname,
+ sizeof(get_stats.iface.hfsc_ifname));
new = &stats1[0];
last = &stats2[0];
@@ -89,7 +90,7 @@ hfsc_stat_loop(int fd, const char *ifname, int count, int interval)
if (sp->class_id != lp->class_id) {
quip_chandle2name(ifname, sp->class_handle,
- clnames[i]);
+ clnames[i], sizeof(clnames[0]));
continue;
}
diff --git a/usr.sbin/altq/altqstat/qdisc_priq.c b/usr.sbin/altq/altqstat/qdisc_priq.c
index 868407eb836..db4a2f55279 100644
--- a/usr.sbin/altq/altqstat/qdisc_priq.c
+++ b/usr.sbin/altq/altqstat/qdisc_priq.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_priq.c,v 1.1 2001/06/27 18:23:21 kjc Exp $ */
-/* $KAME: qdisc_priq.c,v 1.1 2000/10/18 09:15:17 kjc Exp $ */
+/* $OpenBSD: qdisc_priq.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_priq.c,v 1.2 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -58,7 +58,8 @@ priq_stat_loop(int fd, const char *ifname, int count, int interval)
double sec;
int cnt = count;
- strcpy(get_stats.iface.ifname, ifname);
+ strlcpy(get_stats.iface.ifname, ifname,
+ sizeof(get_stats.iface.ifname));
new = &stats1[0];
last = &stats2[0];
@@ -86,7 +87,7 @@ priq_stat_loop(int fd, const char *ifname, int count, int interval)
if (sp->class_handle != lp->class_handle) {
quip_chandle2name(ifname, sp->class_handle,
- clnames[i]);
+ clnames[i], sizeof(clnames[0]));
continue;
}
diff --git a/usr.sbin/altq/altqstat/qdisc_red.c b/usr.sbin/altq/altqstat/qdisc_red.c
index 75550bb4e14..87dd9795a91 100644
--- a/usr.sbin/altq/altqstat/qdisc_red.c
+++ b/usr.sbin/altq/altqstat/qdisc_red.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_red.c,v 1.1 2001/06/27 18:23:21 kjc Exp $ */
-/* $KAME: qdisc_red.c,v 1.2 2000/10/18 09:15:17 kjc Exp $ */
+/* $OpenBSD: qdisc_red.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_red.c,v 1.3 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -56,7 +56,8 @@ red_stat_loop(int fd, const char *ifname, int count, int interval)
double sec;
int cnt = count;
- strcpy(red_stats.iface.red_ifname, ifname);
+ strlcpy(red_stats.iface.red_ifname, ifname,
+ sizeof(red_stats.iface.red_ifname));
gettimeofday(&last_time, NULL);
last_time.tv_sec -= interval;
diff --git a/usr.sbin/altq/altqstat/qdisc_rio.c b/usr.sbin/altq/altqstat/qdisc_rio.c
index a7193ff8aec..01d07d57b10 100644
--- a/usr.sbin/altq/altqstat/qdisc_rio.c
+++ b/usr.sbin/altq/altqstat/qdisc_rio.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: qdisc_rio.c,v 1.1 2001/06/27 18:23:21 kjc Exp $ */
-/* $KAME: qdisc_rio.c,v 1.3 2001/05/17 08:01:47 kjc Exp $ */
+/* $OpenBSD: qdisc_rio.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: qdisc_rio.c,v 1.4 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -58,7 +58,8 @@ rio_stat_loop(int fd, const char *ifname, int count, int interval)
int cnt = count;
bzero(&rio_stats, sizeof(rio_stats));
- strcpy(rio_stats.iface.rio_ifname, ifname);
+ strlcpy(rio_stats.iface.rio_ifname, ifname,
+ sizeof(rio_stats.iface.rio_ifname));
gettimeofday(&last_time, NULL);
last_time.tv_sec -= interval;
diff --git a/usr.sbin/altq/altqstat/qdisc_wfq.c b/usr.sbin/altq/altqstat/qdisc_wfq.c
index f829b27e194..c8a16a6942c 100644
--- a/usr.sbin/altq/altqstat/qdisc_wfq.c
+++ b/usr.sbin/altq/altqstat/qdisc_wfq.c
@@ -1,4 +1,4 @@
-/* $KAME: qdisc_wfq.c,v 1.2 2000/10/18 09:15:17 kjc Exp $ */
+/* $KAME: qdisc_wfq.c,v 1.3 2001/08/15 12:51:59 kjc Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -67,7 +67,8 @@ wfq_stat_loop(int fd, const char *ifname, int count, int interval)
struct wfqinfo *qinfo, **top;
int cnt = count;
- strcpy(wfq_stats.iface.wfq_ifacename, ifname);
+ strlcpy(wfq_stats.iface.wfq_ifacename, ifname,
+ sizeof(wfq_stats.iface.wfq_ifacename));
/*
* first, find out how many queues are available
diff --git a/usr.sbin/altq/altqstat/quip_client.c b/usr.sbin/altq/altqstat/quip_client.c
index 10d4cd16271..c7b7d5cbbaa 100644
--- a/usr.sbin/altq/altqstat/quip_client.c
+++ b/usr.sbin/altq/altqstat/quip_client.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: quip_client.c,v 1.1 2001/06/27 18:23:22 kjc Exp $ */
-/* $KAME: quip_client.c,v 1.2 2000/10/18 09:15:17 kjc Exp $ */
+/* $OpenBSD: quip_client.c,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: quip_client.c,v 1.4 2001/08/16 07:43:15 itojun Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -104,7 +104,7 @@ enum nametype { INTERFACE, CLASS, FILTER, CONDITIONER };
static FILE *server = NULL;
int quip_echo = 0;
-static char *extract_ifname(const char *name);
+static char *extract_ifname(const char *);
int
quip_openserver(void)
@@ -117,7 +117,7 @@ quip_openserver(void)
bzero(&addr, sizeof(addr));
addr.sun_family = AF_LOCAL;
- strcpy(addr.sun_path, QUIP_PATH);
+ strlcpy(addr.sun_path, QUIP_PATH,sizeof(addr.sun_path));
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "can't talk to altqd!\n"
@@ -143,18 +143,20 @@ quip_closeserver(void)
void
quip_sendrequest(FILE *fp, const char *request)
{
- char buf[1024], *cp;
+ char buf[QUIPMSG_MAXSIZE], *cp;
int n;
if ((cp = strstr(request, "QUIP")) == NULL) {
cp = strchr(request, '\n');
n = cp - request;
+ if (cp == NULL || n > REQ_MAXSIZE - 10)
+ return;
strncpy(buf, request, n);
- n += sprintf(buf + n, " QUIP/1.0");
- strcpy(buf + n, cp);
+ n += snprintf(buf + n, REQ_MAXSIZE - n, " QUIP/1.0");
+ strlcpy(buf + n, cp, REQ_MAXSIZE - n);
}
else
- strcpy(buf, request);
+ strlcpy(buf, request, REQ_MAXSIZE);
if (fputs(buf, fp) != 0)
err(1, "fputs");
@@ -173,7 +175,7 @@ quip_sendrequest(FILE *fp, const char *request)
int
quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
{
- char buf[1024], version[64];
+ char buf[QUIPMSG_MAXSIZE], version[64];
int code, resid;
int end_of_header = 0;
@@ -181,7 +183,7 @@ quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
*blen = 0;
code = 0;
resid = 0;
- while (fgets(buf, 1024, fp) != 0) {
+ while (fgets(buf, sizeof(buf), fp) != 0) {
if (quip_echo) {
fputs("> ", stdout);
fputs(buf, stdout);
@@ -190,7 +192,7 @@ quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
if (!end_of_header) {
/* process message header */
if (header != NULL)
- header += sprintf(header, "%s", buf);
+ header += snprintf(header, RES_MAXSIZE, "%s", buf);
if (code == 0) {
/* status line expected */
@@ -219,7 +221,10 @@ quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
cp = buf;
field = strsep(&cp, ":");
if (strcmp(field, "Content-Length") == 0) {
- sscanf(cp, "%d", &resid);
+ if (sscanf(cp, "%d", &resid) != 1) {
+ fpurge(fp);
+ return (-1);
+ }
if (blen != NULL)
*blen = resid;
}
@@ -230,7 +235,7 @@ quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
int len;
if (body != NULL) {
- len = sprintf(body, "%s", buf);
+ len = snprintf(body, BODY_MAXSIZE, "%s", buf);
body += len;
}
else
@@ -319,7 +324,7 @@ quip_selectinterface(char *ifname)
char *
quip_selectqdisc(char *ifname, char *qdisc_name)
{
- char buf[8192], req[256];
+ char buf[BODY_MAXSIZE], req[REQ_MAXSIZE];
int result_code, len;
static char qdisc[64];
@@ -331,7 +336,7 @@ quip_selectqdisc(char *ifname, char *qdisc_name)
}
/* get qdisc info from the server */
- sprintf(req, "GET qdisc?%s\n", ifname);
+ snprintf(req, sizeof(req), "GET qdisc?%s\n", ifname);
quip_sendrequest(server, req);
result_code = quip_recvresponse(server, NULL, buf, &len);
@@ -349,9 +354,9 @@ quip_selectqdisc(char *ifname, char *qdisc_name)
}
void
-quip_chandle2name(const char *ifname, u_long handle, char *name)
+quip_chandle2name(const char *ifname, u_long handle, char *name, size_t size)
{
- char buf[8192], req[256], *cp;
+ char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
int result_code, len;
name[0] = '\0';
@@ -359,7 +364,7 @@ quip_chandle2name(const char *ifname, u_long handle, char *name)
return;
/* get class name from the server */
- sprintf(req, "GET handle-to-name?%s:%#lx\n", ifname, handle);
+ snprintf(req, sizeof(req), "GET handle-to-name?%s:%#lx\n", ifname, handle);
quip_sendrequest(server, req);
result_code = quip_recvresponse(server, NULL, buf, &len);
@@ -369,13 +374,13 @@ quip_chandle2name(const char *ifname, u_long handle, char *name)
if ((cp = strchr(buf, '\n')) != NULL)
*cp = '\0';
if ((cp = strrchr(buf, '/')) != NULL)
- strcpy(name, cp+1);
+ strlcpy(name, cp+1, size);
}
void
quip_printqdisc(const char *ifname)
{
- char buf[8192], req[256], *cp;
+ char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
int result_code, len;
if (server == NULL) {
@@ -384,7 +389,7 @@ quip_printqdisc(const char *ifname)
}
/* get qdisc info from the server */
- sprintf(req, "GET qdisc?%s\n", ifname);
+ snprintf(req, sizeof(req), "GET qdisc?%s\n", ifname);
quip_sendrequest(server, req);
result_code = quip_recvresponse(server, NULL, buf, &len);
@@ -402,11 +407,11 @@ quip_printqdisc(const char *ifname)
void
quip_printfilter(const char *ifname, const u_long handle)
{
- char buf[8192], req[256], *cp;
+ char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
int result_code, len;
/* get qdisc info from the server */
- sprintf(req, "GET filter?%s::%#lx\n", ifname, handle);
+ snprintf(req, sizeof(req), "GET filter?%s::%#lx\n", ifname, handle);
quip_sendrequest(server, req);
result_code = quip_recvresponse(server, NULL, buf, &len);
diff --git a/usr.sbin/altq/altqstat/quip_client.h b/usr.sbin/altq/altqstat/quip_client.h
index 7a107b999af..038be02fe5c 100644
--- a/usr.sbin/altq/altqstat/quip_client.h
+++ b/usr.sbin/altq/altqstat/quip_client.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: quip_client.h,v 1.1 2001/06/27 18:23:22 kjc Exp $ */
-/* $KAME: quip_client.h,v 1.2 2000/10/18 09:15:17 kjc Exp $ */
+/* $OpenBSD: quip_client.h,v 1.2 2001/08/16 12:59:43 kjc Exp $ */
+/* $KAME: quip_client.h,v 1.4 2001/08/16 07:43:15 itojun Exp $ */
/*
* Copyright (C) 1999-2000
* Sony Computer Science Laboratories, Inc. All rights reserved.
@@ -32,18 +32,23 @@
/* unix domain socket for quip */
#define QUIP_PATH "/var/run/altq_quip"
+#define REQ_MAXSIZE 256 /* max request size */
+#define RES_MAXSIZE 256 /* max reply header size */
+#define BODY_MAXSIZE 8192 /* max reply body size */
+#define QUIPMSG_MAXSIZE (RES_MAXSIZE+BODY_MAXSIZE) /* max message size */
+
extern int quip_echo;
int quip_openserver(void);
int quip_closeserver(void);
-void quip_sendrequest(FILE *fp, const char *request);
-int quip_recvresponse(FILE *fp, char *header, char *body, int *blen);
+void quip_sendrequest(FILE *, const char *);
+int quip_recvresponse(FILE *, char *, char *, int *);
void quip_rawmode(void);
-char *quip_selectinterface(char *ifname);
-char *quip_selectqdisc(char *ifname, char *qdisc_name);
-void quip_chandle2name(const char *ifname, u_long handle, char *name);
-void quip_printqdisc(const char *ifname);
-void quip_printfilter(const char *ifname, const u_long handle);
+char *quip_selectinterface(char *);
+char *quip_selectqdisc(char *, char *);
+void quip_chandle2name(const char *, u_long, char *, size_t);
+void quip_printqdisc(const char *);
+void quip_printfilter(const char *, const u_long);
void quip_printconfig(void);
#endif /* _QUIP_CLIENT_H_ */