1 From: Bill Gianopoulos <wag@sccux1.msd.ray.com>
2 Message-Id: <199405191527.LAA03463@sccux1.msd.ray.com>
3 Subject: Patch to rmail to elliminate need for snprintf
4 To: sendmail@CS.Berkeley.EDU
5 Date: Thu, 19 May 1994 11:27:16 -0400 (EDT)
7 I have written the following patch to rmail which removes the requirement
8 for snprintf while maintaining the protection from buffer overruns. It also
9 fixes it to compile with compilers which don't understand ANSI function
10 prototypes. Perhaps this should be included in the next version?
12 *** rmail/rmail.c.orig Mon May 31 18:10:44 1993
13 --- rmail/rmail.c Thu May 19 11:04:50 1994
21 void err __P((int, const char *, ...));
22 void usage __P((void));
28 + #define strdup(s) strcpy(xalloc(strlen(s) + 1), s)
36 + /* some systems can't handle size zero mallocs */
40 + p = malloc((unsigned) sz);
42 + err(EX_UNAVAILABLE, "Out of memory!!");
51 args[i++] = "-oi"; /* Ignore '.' on a line by itself. */
53 if (from_sys != NULL) { /* Set sender's host name. */
54 ! if (strchr(from_sys, '.') == NULL)
55 ! (void)snprintf(buf, sizeof(buf),
56 "-oMs%s.%s", from_sys, domain);
58 ! (void)snprintf(buf, sizeof(buf), "-oMs%s", from_sys);
59 if ((args[i++] = strdup(buf)) == NULL)
60 err(EX_TEMPFAIL, NULL);
62 /* Set protocol used. */
63 ! (void)snprintf(buf, sizeof(buf), "-oMr%s", domain);
64 if ((args[i++] = strdup(buf)) == NULL)
65 err(EX_TEMPFAIL, NULL);
67 /* Set name of ``from'' person. */
68 ! (void)snprintf(buf, sizeof(buf), "-f%s%s",
69 from_path ? from_path : "", from_user);
70 if ((args[i++] = strdup(buf)) == NULL)
71 err(EX_TEMPFAIL, NULL);
73 args[i++] = "-oi"; /* Ignore '.' on a line by itself. */
75 if (from_sys != NULL) { /* Set sender's host name. */
76 ! if (strchr(from_sys, '.') == NULL) {
77 ! if ((strlen(from_sys) + strlen(domain) + 6)
79 ! err(EX_DATAERR, "sender hostname too long");
81 "-oMs%s.%s", from_sys, domain);
84 ! if ((strlen(from_sys) + 5) > sizeof(buf))
85 ! err(EX_DATAERR ,"sender hostname too long");
86 ! (void)sprintf(buf, "-oMs%s", from_sys);
88 if ((args[i++] = strdup(buf)) == NULL)
89 err(EX_TEMPFAIL, NULL);
91 /* Set protocol used. */
92 ! if ((strlen(domain) + 5) > sizeof(buf))
93 ! err(EX_DATAERR, "protocol name too long");
94 ! (void)sprintf(buf, "-oMr%s", domain);
95 if ((args[i++] = strdup(buf)) == NULL)
96 err(EX_TEMPFAIL, NULL);
98 /* Set name of ``from'' person. */
99 ! if (((from_path ? strlen(from_path) : 0) + strlen(from_user) + 3)
101 ! err(EX_DATAERR, "from address too long");
102 ! (void)sprintf(buf, "-f%s%s",
103 from_path ? from_path : "", from_user);
104 if ((args[i++] = strdup(buf)) == NULL)
105 err(EX_TEMPFAIL, NULL);
107 William A. Gianopoulos; Raytheon Missile Systems Division
108 wag@sccux1.msd.ray.com