summaryrefslogtreecommitdiff
path: root/usr.bin/telnet
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-09-09 03:41:09 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-09-09 03:41:09 +0000
commit3738a71b2e358307482a24229b8cd100ab150eab (patch)
treeeb752407af8f18917bbf5971230e47e2ff66b2c5 /usr.bin/telnet
parente53bf16d9b38d7d93c5dd1cefe25ee6f4a5b8086 (diff)
Eliminate a pile of casts that were superfluous or wrong, or that were
the result of bad type choices, particularly (unsigned char *) vs (const char *). Also, use reallocarray().
Diffstat (limited to 'usr.bin/telnet')
-rw-r--r--usr.bin/telnet/commands.c69
-rw-r--r--usr.bin/telnet/externs.h25
-rw-r--r--usr.bin/telnet/sys_bsd.c10
-rw-r--r--usr.bin/telnet/telnet.c44
-rw-r--r--usr.bin/telnet/utilities.c22
5 files changed, 80 insertions, 90 deletions
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index 4a07226dc19..2799f161f47 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commands.c,v 1.69 2014/07/22 07:30:24 jsg Exp $ */
+/* $OpenBSD: commands.c,v 1.70 2014/09/09 03:41:08 guenther Exp $ */
/* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */
/*
@@ -772,7 +772,7 @@ struct termios new_tc = { 0 };
struct setlist {
char *name; /* name */
char *help; /* help information */
- void (*handler)(char *);
+ void (*handler)(const char *);
cc_t *charp; /* where it is located at */
};
@@ -1420,12 +1420,12 @@ struct envlist {
};
static void env_help(void);
-static void env_undefine(unsigned char *);
-static void env_export(unsigned char *);
-static void env_unexport(unsigned char *);
-static void env_send(unsigned char *);
+static void env_undefine(const char *);
+static void env_export(const char *);
+static void env_unexport(const char *);
+static void env_send(const char *);
static void env_list(void);
-static struct env_lst *env_find(unsigned char *var);
+static struct env_lst *env_find(const char *var);
struct envlist EnvList[] = {
{ "define", "Define an environment variable",
@@ -1501,8 +1501,8 @@ env_cmd(int argc, char *argv[])
struct env_lst {
struct env_lst *next; /* pointer to next structure */
struct env_lst *prev; /* pointer to previous structure */
- unsigned char *var; /* pointer to variable name */
- unsigned char *value; /* pointer to variable value */
+ char *var; /* pointer to variable name */
+ char *value; /* pointer to variable value */
int export; /* 1 -> export with default list of variables */
int welldefined; /* A well defined variable */
};
@@ -1510,12 +1510,12 @@ struct env_lst {
struct env_lst envlisthead;
static struct env_lst *
-env_find(unsigned char *var)
+env_find(const char *var)
{
struct env_lst *ep;
for (ep = envlisthead.next; ep; ep = ep->next) {
- if (strcmp((char *)ep->var, (char *)var) == 0)
+ if (strcmp(ep->var, var) == 0)
return(ep);
}
return(NULL);
@@ -1531,8 +1531,7 @@ env_init(void)
for (epp = environ; *epp; epp++) {
if ((cp = strchr(*epp, '='))) {
*cp = '\0';
- ep = env_define((unsigned char *)*epp,
- (unsigned char *)cp+1);
+ ep = env_define(*epp, cp+1);
ep->export = 0;
*cp = '=';
}
@@ -1544,9 +1543,9 @@ env_init(void)
*/
if ((ep = env_find("DISPLAY"))
&& ((*ep->value == ':')
- || (strncmp((char *)ep->value, "unix:", 5) == 0))) {
+ || (strncmp(ep->value, "unix:", 5) == 0))) {
char hbuf[MAXHOSTNAMELEN];
- char *cp2 = strchr((char *)ep->value, ':');
+ char *cp2 = strchr(ep->value, ':');
gethostname(hbuf, sizeof hbuf);
@@ -1562,7 +1561,7 @@ env_init(void)
err(1, "asprintf");
free(ep->value);
- ep->value = (unsigned char *)cp;
+ ep->value = cp;
}
/*
* If USER is not defined, but LOGNAME is, then add
@@ -1570,16 +1569,16 @@ env_init(void)
* don't export the USER variable.
*/
if ((env_find("USER") == NULL) && (ep = env_find("LOGNAME"))) {
- env_define((unsigned char *)"USER", ep->value);
- env_unexport((unsigned char *)"USER");
+ env_define("USER", ep->value);
+ env_unexport("USER");
}
- env_export((unsigned char *)"DISPLAY");
- env_export((unsigned char *)"PRINTER");
- env_export((unsigned char *)"XAUTHORITY");
+ env_export("DISPLAY");
+ env_export("PRINTER");
+ env_export("XAUTHORITY");
}
struct env_lst *
-env_define(unsigned char *var, unsigned char *value)
+env_define(const char *var, const char *value)
{
struct env_lst *ep;
@@ -1597,17 +1596,17 @@ env_define(unsigned char *var, unsigned char *value)
if (ep->next)
ep->next->prev = ep;
}
- ep->welldefined = opt_welldefined((char *)var);
+ ep->welldefined = opt_welldefined(var);
ep->export = 1;
- if ((ep->var = strdup((char *)var)) == NULL)
+ if ((ep->var = strdup(var)) == NULL)
err(1, "strdup");
- if ((ep->value = strdup((char *)value)) == NULL)
+ if ((ep->value = strdup(value)) == NULL)
err(1, "strdup");
return(ep);
}
static void
-env_undefine(unsigned char *var)
+env_undefine(const char *var)
{
struct env_lst *ep;
@@ -1624,7 +1623,7 @@ env_undefine(unsigned char *var)
}
static void
-env_export(unsigned char *var)
+env_export(const char *var)
{
struct env_lst *ep;
@@ -1633,7 +1632,7 @@ env_export(unsigned char *var)
}
static void
-env_unexport(unsigned char *var)
+env_unexport(const char *var)
{
struct env_lst *ep;
@@ -1642,7 +1641,7 @@ env_unexport(unsigned char *var)
}
static void
-env_send(unsigned char *var)
+env_send(const char *var)
{
struct env_lst *ep;
@@ -1675,7 +1674,7 @@ env_list(void)
}
}
-unsigned char *
+char *
env_default(int init, int welldefined)
{
static struct env_lst *nep = NULL;
@@ -1693,8 +1692,8 @@ env_default(int init, int welldefined)
return(NULL);
}
-unsigned char *
-env_getvalue(unsigned char *var, int exported_only)
+char *
+env_getvalue(const char *var, int exported_only)
{
struct env_lst *ep;
@@ -1860,7 +1859,7 @@ tn(int argc, char *argv[])
const int niflags = NI_NUMERICHOST;
/* clear the socket address prior to use */
- memset((char *)&sin, 0, sizeof(sin));
+ memset(&sin, 0, sizeof(sin));
if (connected) {
printf("?Already connected to %s\r\n", hostname);
@@ -2061,8 +2060,8 @@ tn(int argc, char *argv[])
}
}
if (user) {
- env_define((unsigned char *)"USER", (unsigned char *)user);
- env_export((unsigned char *)"USER");
+ env_define("USER", user);
+ env_export("USER");
}
connection_status(1);
if (setjmp(peerdied) == 0)
diff --git a/usr.bin/telnet/externs.h b/usr.bin/telnet/externs.h
index 1078945bff4..e96fb850521 100644
--- a/usr.bin/telnet/externs.h
+++ b/usr.bin/telnet/externs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: externs.h,v 1.28 2014/07/22 07:30:24 jsg Exp $ */
+/* $OpenBSD: externs.h,v 1.29 2014/09/09 03:41:08 guenther Exp $ */
/* $KTH: externs.h,v 1.16 1997/11/29 02:28:35 joda Exp $ */
/*
@@ -152,21 +152,16 @@ extern int rtableid; /* routing table to use */
#define set_his_want_state_wont set_my_want_state_dont
-extern unsigned char
- NetTraceFile[]; /* Name of file where debugging output goes */
-extern void
- SetNetTrace (char *); /* Function to change where debugging goes */
-
extern jmp_buf
peerdied,
toplevel; /* For error conditions. */
/* commands.c */
-struct env_lst *env_define (unsigned char *, unsigned char *);
-void env_init (void);
-unsigned char * env_default(int init, int welldefined);
-unsigned char * env_getvalue(unsigned char *var, int exported_only);
+struct env_lst *env_define (const char *, const char *);
+void env_init (void);
+char *env_default(int init, int welldefined);
+char *env_getvalue(const char *var, int exported_only);
void set_escape_char(char *s);
@@ -207,7 +202,7 @@ void init_telnet(void);
void tel_leave_binary(int rw);
void tel_enter_binary(int rw);
-int opt_welldefined(char *ep);
+int opt_welldefined(const char *ep);
void telnet(char *);
int telrcv(void);
int rlogin_susp(void);
@@ -236,12 +231,9 @@ void slc_mode_import (int);
void slc_check (void);
void env_opt_start_info (void);
-void env_opt_add (unsigned char *);
+void env_opt_add (char *);
void env_opt_end (int);
-unsigned char *env_default (int, int);
-unsigned char *env_getvalue (unsigned char *, int);
-
int get_status (void);
int dosynch (void);
@@ -265,7 +257,8 @@ void setcommandmode(void);
/* utilities.c */
-void SetNetTrace(char *file);
+extern char NetTraceFile[];
+void SetNetTrace(const char *file);
void Dump(char direction, unsigned char *buffer, int length);
void printoption(char *direction, int cmd, int option);
void optionstatus(void);
diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c
index 8bc4813242c..1ccb7d6504f 100644
--- a/usr.bin/telnet/sys_bsd.c
+++ b/usr.bin/telnet/sys_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_bsd.c,v 1.27 2014/07/22 07:30:24 jsg Exp $ */
+/* $OpenBSD: sys_bsd.c,v 1.28 2014/09/09 03:41:08 guenther Exp $ */
/* $NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $ */
/*
@@ -417,8 +417,8 @@ TerminalNewMode(int f)
if (tcsetattr(tin, TCSADRAIN, &tmp_tc) < 0)
tcsetattr(tin, TCSANOW, &tmp_tc);
- ioctl(tin, FIONBIO, (char *)&onoff);
- ioctl(tout, FIONBIO, (char *)&onoff);
+ ioctl(tin, FIONBIO, &onoff);
+ ioctl(tout, FIONBIO, &onoff);
}
/*
@@ -521,7 +521,7 @@ TerminalWindowSize(long *rows, long *cols)
#ifdef TIOCGWINSZ
struct winsize ws;
- if (ioctl(fileno(stdin), TIOCGWINSZ, (char *)&ws) >= 0) {
+ if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) >= 0) {
*rows = ws.ws_row;
*cols = ws.ws_col;
return 1;
@@ -694,7 +694,7 @@ process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
int canread;
canread = ring_empty_consecutive(&netiring);
- c = recv(net, (char *)netiring.supply, canread, 0);
+ c = recv(net, netiring.supply, canread, 0);
if (c < 0 && errno == EWOULDBLOCK) {
c = 0;
} else if (c <= 0) {
diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c
index ca6d88268c0..445d980509f 100644
--- a/usr.bin/telnet/telnet.c
+++ b/usr.bin/telnet/telnet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: telnet.c,v 1.29 2014/07/22 07:30:24 jsg Exp $ */
+/* $OpenBSD: telnet.c,v 1.30 2014/09/09 03:41:08 guenther Exp $ */
/* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */
/*
@@ -68,7 +68,7 @@ static void slc_end_reply(void);
static void slc(unsigned char *, int);
static int slc_update(void);
-static void env_opt(unsigned char *, int);
+static void env_opt(char *, int);
static void env_opt_start(void);
char options[256]; /* The combined options */
@@ -155,7 +155,7 @@ init_telnet(void)
env_init();
SB_CLEAR();
- memset((char *)options, 0, sizeof options);
+ memset(options, 0, sizeof options);
connected = ISend = localflow = donebinarytoggle = 0;
restartany = -1;
@@ -382,7 +382,7 @@ dooption(int option)
break;
case TELOPT_XDISPLOC: /* X Display location */
- if (env_getvalue((unsigned char *)"DISPLAY", 0))
+ if (env_getvalue("DISPLAY", 0))
new_state_ok = 1;
break;
@@ -474,7 +474,7 @@ mklist(char *buf, char *name)
char c, *cp, **argvp, *cp2, **argv, **avt;
if (name) {
- if ((int)strlen(name) > 40) {
+ if (strlen(name) > 40) {
name = NULL;
unknown[0] = name_unknown;
} else {
@@ -493,7 +493,7 @@ mklist(char *buf, char *name)
/*
* Allocate an array to put the name pointers into
*/
- argv = (char **)malloc((n+3)*sizeof(char *));
+ argv = reallocarray(NULL, n+3, sizeof(char *));
if (argv == NULL)
return(unknown);
@@ -605,11 +605,11 @@ gettermname(void)
resettermname = 0;
if (tnamep && tnamep != unknown)
free(tnamep);
- if ((tname = (char *)env_getvalue((unsigned char *)"TERM", 0)) &&
- (setupterm(tname, 1, &errret) == OK)) {
+ if ((tname = env_getvalue("TERM", 0)) &&
+ (setupterm(tname, 1, &errret) == OK)) {
tnamep = mklist(ttytype, tname);
} else {
- if (tname && ((int)strlen(tname) <= 40)) {
+ if (tname && (strlen(tname) <= 40)) {
unknown[0] = tname;
upcase(tname);
} else
@@ -773,7 +773,7 @@ suboption(void)
unsigned char temp[50], *dp;
int len;
- if ((dp = env_getvalue((unsigned char *)"DISPLAY", 0)) == NULL) {
+ if ((dp = env_getvalue("DISPLAY", 0)) == NULL) {
/*
* Something happened, we no longer have a DISPLAY
* variable. So, turn off the option.
@@ -1206,9 +1206,9 @@ slc_update(void)
}
static void
-env_opt(unsigned char *buf, int len)
+env_opt(char *buf, int len)
{
- unsigned char *ep = 0, *epc = 0;
+ char *ep = 0, *epc = 0;
int i;
switch(buf[0]&0xff) {
@@ -1270,7 +1270,7 @@ env_opt_start(void)
{
unsigned char *p;
- p = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
+ p = realloc(opt_reply, OPT_REPLY_SIZE);
if (p == NULL)
free(opt_reply);
opt_reply = p;
@@ -1296,9 +1296,9 @@ env_opt_start_info(void)
}
void
-env_opt_add(unsigned char *ep)
+env_opt_add(char *ep)
{
- unsigned char *vp, c;
+ char *vp, c;
if (opt_reply == NULL) /*XXX*/
return; /*XXX*/
@@ -1316,8 +1316,8 @@ env_opt_add(unsigned char *ep)
return;
}
vp = env_getvalue(ep, 1);
- if (opt_replyp + 2 * (vp ? strlen((char *)vp) : 0) +
- 2 * strlen((char *)ep) + 6 > opt_replyend)
+ if (2 * (vp ? strlen(vp) : 0) + 2 * strlen(ep) + 6 >
+ opt_replyend - opt_replyp)
{
size_t len;
unsigned char *p;
@@ -1326,7 +1326,7 @@ env_opt_add(unsigned char *ep)
len += OPT_REPLY_SIZE + 2 * strlen(ep);
if (vp)
len += 2 * strlen(vp);
- p = (unsigned char *)realloc(opt_reply, len);
+ p = realloc(opt_reply, len);
if (p == NULL) {
free(opt_reply);
/*@*/ printf("env_opt_add: realloc() failed!!!\n");
@@ -1337,8 +1337,8 @@ env_opt_add(unsigned char *ep)
opt_replyend = p + len;
opt_reply = p;
}
- if (opt_welldefined((char *)ep))
- opt_add(NEW_ENV_VAR);
+ if (opt_welldefined(ep))
+ opt_add(NEW_ENV_VAR);
else
opt_add(ENV_USERVAR);
@@ -1366,7 +1366,7 @@ env_opt_add(unsigned char *ep)
}
int
-opt_welldefined(char *ep)
+opt_welldefined(const char *ep)
{
if ((strcmp(ep, "USER") == 0) ||
(strcmp(ep, "DISPLAY") == 0) ||
@@ -1848,7 +1848,7 @@ telnet(char *user)
send_will(TELOPT_LINEMODE, 1);
send_will(TELOPT_NEW_ENVIRON, 1);
send_do(TELOPT_STATUS, 1);
- if (env_getvalue((unsigned char *)"DISPLAY", 0))
+ if (env_getvalue("DISPLAY", 0))
send_will(TELOPT_XDISPLOC, 1);
if (binary)
tel_enter_binary(binary);
diff --git a/usr.bin/telnet/utilities.c b/usr.bin/telnet/utilities.c
index 76eb0f0f2c8..b3acee87613 100644
--- a/usr.bin/telnet/utilities.c
+++ b/usr.bin/telnet/utilities.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utilities.c,v 1.20 2014/07/22 07:30:24 jsg Exp $ */
+/* $OpenBSD: utilities.c,v 1.21 2014/09/09 03:41:08 guenther Exp $ */
/* $NetBSD: utilities.c,v 1.5 1996/02/28 21:04:21 thorpej Exp $ */
/*
@@ -66,23 +66,23 @@ upcase(char *argument)
* The following are routines used to print out debugging information.
*/
-unsigned char NetTraceFile[PATH_MAX] = "(standard output)";
+char NetTraceFile[PATH_MAX] = "(standard output)";
void
-SetNetTrace(char *file)
+SetNetTrace(const char *file)
{
if (NetTrace && NetTrace != stdout)
fclose(NetTrace);
- if (file && (strcmp(file, "-") != 0)) {
- NetTrace = fopen(file, "w");
+ if (file && (strcmp(file, "-") != 0)) {
+ NetTrace = fopen(file, "we");
if (NetTrace) {
- strlcpy((char *)NetTraceFile, file, sizeof(NetTraceFile));
+ strlcpy(NetTraceFile, file, sizeof(NetTraceFile));
return;
}
fprintf(stderr, "Cannot open %s.\n", file);
}
NetTrace = stdout;
- strlcpy((char *)NetTraceFile, "(standard output)", sizeof(NetTraceFile));
+ strlcpy(NetTraceFile, "(standard output)", sizeof(NetTraceFile));
}
void
@@ -356,15 +356,13 @@ printsub(char direction, /* '<' or '>' */
break;
}
fprintf(NetTrace, " %d %d (%d)",
- pointer[1], pointer[2],
- (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
+ pointer[1], pointer[2], (pointer[1]<<8) | pointer[2]);
if (length == 4) {
fprintf(NetTrace, " ?%d?", pointer[3]);
break;
}
fprintf(NetTrace, " %d %d (%d)",
- pointer[3], pointer[4],
- (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
+ pointer[3], pointer[4], (pointer[3]<<8) | pointer[4]);
for (i = 5; i < length; i++)
fprintf(NetTrace, " ?%d?", pointer[i]);
break;
@@ -499,7 +497,7 @@ printsub(char direction, /* '<' or '>' */
case WONT: cp = "WONT"; goto common2;
common2:
i++;
- if (TELOPT_OK((int)pointer[i]))
+ if (TELOPT_OK(pointer[i]))
fprintf(NetTrace, " %s %s", cp, TELOPT(pointer[i]));
else
fprintf(NetTrace, " %s %d", cp, pointer[i]);