Removed a buffer overflow in args().
While I'm here, fix a bug with 'register' in conjunction with setjmp(), staticize and do some -Wall cleaning.
This commit is contained in:
parent
0fa2443f0e
commit
a8b28da029
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28788
@ -36,7 +36,7 @@
|
|||||||
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id: cmds.c,v 1.4 1997/08/22 22:14:15 imp Exp $";
|
"$Id: cmds.c,v 1.5 1997/08/25 05:02:09 imp Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "tipconf.h"
|
#include "tipconf.h"
|
||||||
@ -46,6 +46,7 @@ static const char rcsid[] =
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <libutil.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -61,30 +62,32 @@ char *sep[] = { "second", "minute", "hour" };
|
|||||||
static char *argv[10]; /* argument vector for take and put */
|
static char *argv[10]; /* argument vector for take and put */
|
||||||
|
|
||||||
void timeout(); /* timeout function called on alarm */
|
void timeout(); /* timeout function called on alarm */
|
||||||
void stopsnd(); /* SIGINT handler during file transfers */
|
static void stopsnd(); /* SIGINT handler during file transfers */
|
||||||
void intcopy(); /* interrupt routine for file transfers */
|
static void intcopy(); /* interrupt routine for file transfers */
|
||||||
int anyof __P((char *, char *));
|
|
||||||
void suspend __P((char));
|
void suspend __P((char));
|
||||||
void genbrk __P((void));
|
void genbrk __P((void));
|
||||||
void tandem __P((char *));
|
|
||||||
void variable __P((void));
|
void variable __P((void));
|
||||||
void prtime __P((char *, time_t));
|
|
||||||
int args __P((char *, char **));
|
|
||||||
void execute __P((char *));
|
|
||||||
void finish __P((void));
|
void finish __P((void));
|
||||||
void tipabort __P((char *));
|
void tipabort __P((char *));
|
||||||
void chdirectory __P((void));
|
void chdirectory __P((void));
|
||||||
void shell __P((void));
|
void shell __P((void));
|
||||||
void send __P((char));
|
|
||||||
void cu_put __P((char));
|
void cu_put __P((char));
|
||||||
void transmit __P((FILE *, char *, char *));
|
|
||||||
void sendfile __P((char));
|
void sendfile __P((char));
|
||||||
void pipefile __P((void));
|
void pipefile __P((void));
|
||||||
void transfer __P((char *, int, char *));
|
|
||||||
void xfer __P((char *, int, char *));
|
|
||||||
void cu_take __P((char));
|
void cu_take __P((char));
|
||||||
void getfl __P((char));
|
void getfl __P((char));
|
||||||
|
|
||||||
|
static int anyof __P((char *, char *));
|
||||||
|
static void tandem __P((char *));
|
||||||
|
static void prtime __P((char *, time_t));
|
||||||
|
static int args __P((char *, char **, int));
|
||||||
|
static void execute __P((char *));
|
||||||
|
static void send __P((char));
|
||||||
|
static void transmit __P((FILE *, char *, char *));
|
||||||
|
static void transfer __P((char *, int, char *));
|
||||||
|
static void xfer __P((char *, int, char *));
|
||||||
|
|
||||||
void
|
void
|
||||||
usedefchars ()
|
usedefchars ()
|
||||||
{
|
{
|
||||||
@ -167,7 +170,7 @@ cu_take(cc)
|
|||||||
|
|
||||||
if (prompt("[take] ", copyname, sizeof(copyname)))
|
if (prompt("[take] ", copyname, sizeof(copyname)))
|
||||||
return;
|
return;
|
||||||
if ((argc = args(copyname, argv)) < 1 || argc > 2) {
|
if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) {
|
||||||
printf("usage: <take> from [to]\r\n");
|
printf("usage: <take> from [to]\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -182,15 +185,15 @@ cu_take(cc)
|
|||||||
xfer(line, fd, "\n___tip_end_of_file_marker___\n");
|
xfer(line, fd, "\n___tip_end_of_file_marker___\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern jmp_buf intbuf;
|
static jmp_buf intbuf;
|
||||||
|
|
||||||
void
|
static void
|
||||||
xfer(buf, fd, eofchars)
|
xfer(buf, fd, eofchars)
|
||||||
char *buf, *eofchars;
|
char *buf, *eofchars;
|
||||||
{
|
{
|
||||||
register int ct;
|
int ct;
|
||||||
char c, *match;
|
char c, *match;
|
||||||
register int cnt, eof, v;
|
int cnt, eof, v;
|
||||||
time_t start;
|
time_t start;
|
||||||
sig_t f;
|
sig_t f;
|
||||||
char r;
|
char r;
|
||||||
@ -266,12 +269,11 @@ xfer(buf, fd, eofchars)
|
|||||||
(void)fclose(ff);
|
(void)fclose(ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jmp_buf intbuf;
|
|
||||||
/*
|
/*
|
||||||
* Bulk transfer routine --
|
* Bulk transfer routine --
|
||||||
* used by getfl(), cu_take(), and pipefile()
|
* used by getfl(), cu_take(), and pipefile()
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
transfer(buf, fd, eofchars)
|
transfer(buf, fd, eofchars)
|
||||||
char *buf, *eofchars;
|
char *buf, *eofchars;
|
||||||
{
|
{
|
||||||
@ -346,7 +348,6 @@ pipefile()
|
|||||||
int cpid, pdes[2];
|
int cpid, pdes[2];
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int status, p;
|
int status, p;
|
||||||
extern int errno;
|
|
||||||
|
|
||||||
if (prompt("Local command? ", buf, sizeof(buf)))
|
if (prompt("Local command? ", buf, sizeof(buf)))
|
||||||
return;
|
return;
|
||||||
@ -433,7 +434,7 @@ sendfile(cc)
|
|||||||
* Bulk transfer routine to remote host --
|
* Bulk transfer routine to remote host --
|
||||||
* used by sendfile() and cu_put()
|
* used by sendfile() and cu_put()
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
transmit(fd, eofchars, command)
|
transmit(fd, eofchars, command)
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
char *eofchars, *command;
|
char *eofchars, *command;
|
||||||
@ -541,7 +542,7 @@ cu_put(cc)
|
|||||||
|
|
||||||
if (prompt("[put] ", copyname, sizeof(copyname)))
|
if (prompt("[put] ", copyname, sizeof(copyname)))
|
||||||
return;
|
return;
|
||||||
if ((argc = args(copyname, argv)) < 1 || argc > 2) {
|
if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) {
|
||||||
printf("usage: <put> from [to]\r\n");
|
printf("usage: <put> from [to]\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -563,7 +564,7 @@ cu_put(cc)
|
|||||||
* FTP - send single character
|
* FTP - send single character
|
||||||
* wait for echo & handle timeout
|
* wait for echo & handle timeout
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
send(c)
|
send(c)
|
||||||
char c;
|
char c;
|
||||||
{
|
{
|
||||||
@ -840,7 +841,7 @@ intcopy()
|
|||||||
longjmp(intbuf, 1);
|
longjmp(intbuf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
execute(s)
|
execute(s)
|
||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
@ -854,15 +855,16 @@ execute(s)
|
|||||||
execl(value(SHELL), cp, "-c", s, 0);
|
execl(value(SHELL), cp, "-c", s, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
args(buf, a)
|
args(buf, a, num)
|
||||||
char *buf, *a[];
|
char *buf, *a[];
|
||||||
|
int num;
|
||||||
{
|
{
|
||||||
register char *p = buf, *start;
|
register char *p = buf, *start;
|
||||||
register char **parg = a;
|
register char **parg = a;
|
||||||
register int n = 0;
|
register int n = 0;
|
||||||
|
|
||||||
do {
|
while (*p && n < num) {
|
||||||
while (*p && (*p == ' ' || *p == '\t'))
|
while (*p && (*p == ' ' || *p == '\t'))
|
||||||
p++;
|
p++;
|
||||||
start = p;
|
start = p;
|
||||||
@ -874,12 +876,11 @@ args(buf, a)
|
|||||||
parg++, n++;
|
parg++, n++;
|
||||||
if (*p)
|
if (*p)
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
} while (*p);
|
}
|
||||||
|
|
||||||
return(n);
|
return(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
prtime(s, a)
|
prtime(s, a)
|
||||||
char *s;
|
char *s;
|
||||||
time_t a;
|
time_t a;
|
||||||
@ -946,7 +947,7 @@ variable()
|
|||||||
/*
|
/*
|
||||||
* Turn tandem mode on or off for remote tty.
|
* Turn tandem mode on or off for remote tty.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
tandem(option)
|
tandem(option)
|
||||||
char *option;
|
char *option;
|
||||||
{
|
{
|
||||||
@ -1079,7 +1080,7 @@ expand(name)
|
|||||||
* Are any of the characters in the two strings the same?
|
* Are any of the characters in the two strings the same?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
static int
|
||||||
anyof(s1, s2)
|
anyof(s1, s2)
|
||||||
register char *s1, *s2;
|
register char *s1, *s2;
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ static const char copyright[] =
|
|||||||
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id: tip.c,v 1.4 1997/08/22 22:14:15 imp Exp $";
|
"$Id: tip.c,v 1.5 1997/08/25 05:02:10 imp Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -58,6 +58,8 @@ void ttysetup (int speed);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <libutil.h>
|
||||||
#include "tipconf.h"
|
#include "tipconf.h"
|
||||||
#include "tip.h"
|
#include "tip.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
@ -157,7 +159,7 @@ main(argc, argv)
|
|||||||
for (p = system; *p; p++)
|
for (p = system; *p; p++)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
PN = PNbuf;
|
PN = PNbuf;
|
||||||
(void)sprintf(sbuf, "tip%d", BR);
|
(void)sprintf(sbuf, "tip%ld", BR);
|
||||||
system = sbuf;
|
system = sbuf;
|
||||||
|
|
||||||
notnumber:
|
notnumber:
|
||||||
@ -713,5 +715,5 @@ setparity(defparity)
|
|||||||
(void) fflush(stderr);
|
(void) fflush(stderr);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 0200; i++)
|
for (i = 0; i < 0200; i++)
|
||||||
partab[i] = evenpartab[i] ^ flip | set & clr;
|
partab[i] = (evenpartab[i] ^ flip) | (set & clr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user