summaryrefslogtreecommitdiff
path: root/usr.sbin/altq/altqstat/quip_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/altq/altqstat/quip_client.c')
-rw-r--r--usr.sbin/altq/altqstat/quip_client.c51
1 files changed, 28 insertions, 23 deletions
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);