source: trunk/athena/bin/write/writed.c @ 2797

Revision 2797, 1.6 KB checked in by epeisach, 34 years ago (diff)
[changes.70 73 - a) eichin b) jik, audited by dkk & ilham] a) Use fgets instead of gets. (non security) b) loop where builds argument list, doesn't do range checking.
Line 
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.  The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6/*
7 * Copyright (c) 1985 Massachusetts Institute of Technology
8 * Note:  This is mostly fingerd.c with all occurances of
9 * "finger" changed to "write".
10 */
11#ifndef lint
12char copyright[] =
13"@(#) Copyright (c) 1983 Regents of the University of California.\n\
14 All rights reserved.\n";
15static char *rcsid_writed_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/write/writed.c,v 1.3 1990-04-05 18:31:44 epeisach Exp $";
16#endif not lint
17
18#ifndef lint
19static char sccsid[] = "@(#)writed.c    5.1 (Berkeley) 6/6/85";
20#endif not lint
21
22/*
23 * Write server.
24 */
25#include <sys/types.h>
26#include <netinet/in.h>
27
28#include <stdio.h>
29#include <ctype.h>
30
31main(argc, argv)
32        char *argv[];
33{
34        register char *sp;
35        char line[BUFSIZ];
36        struct sockaddr_in sin;
37        int i;
38        char *av[10]; /* space for 9 arguments, plus terminating null */
39
40
41        i = sizeof (sin);
42        if (getpeername(0, &sin, &i) < 0)
43                fatal(argv[0], "getpeername");
44        line[0] = '\0';
45
46        fgets(line, BUFSIZ, stdin);
47        sp = line;
48        av[0] = "write";
49        av[1] = "-f";
50        i = 2;
51        while (1) {
52                while (isspace(*sp))
53                        sp++;
54                if (!*sp)
55                        break;
56                av[i++] = sp;
57                if (i == 9)
58                        /* past end of av space -- throw out the rest */
59                        /* of the args                                */
60                        break;
61                while (*sp && !isspace(*sp)) sp++;
62                if (*sp) *sp++ = '\0';
63        }
64        av[i] = 0;
65        /* Put the socket on stdin, stdout, and stderr */
66        dup2(0, 1);
67        dup2(0, 2);
68        execv("/bin/write", av);
69        _exit(1);
70}
71
72fatal(prog, s)
73        char *prog, *s;
74{
75
76        fprintf(stderr, "%s: ", prog);
77        perror(s);
78        exit(1);
79}
Note: See TracBrowser for help on using the repository browser.