$OpenBSD: patch-jcc_c,v 1.5 2005/11/14 17:23:36 pvalchev Exp $ --- jcc.c.orig Fri Oct 30 22:58:47 1998 +++ jcc.c Sat Jun 9 00:16:47 2001 @@ -226,7 +226,7 @@ chat(struct client_state *csp) } if(http->cmd == NULL) { - strcpy(buf, CHEADER); + strlcpy(buf, CHEADER, sizeof(buf)); write_socket(csp->cfd, buf, strlen(buf)); return; } @@ -369,12 +369,19 @@ chat(struct client_state *csp) } if(errno == EINVAL) { - err = zalloc(strlen(CNXDOM) + strlen(http->host)); - sprintf(err, CNXDOM, http->host); + if ((err = zalloc(strlen(CNXDOM) + strlen(http->host))) == NULL) { + fprintf(stderr, "%s:%d zalloc failed\n", __FILE__, __LINE__); + exit(-1); + } + snprintf(err, (strlen(CNXDOM) + strlen(http->host)), CNXDOM, http->host); + } else { eno = safe_strerror(errno); - err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno)); - sprintf(err, CFAIL, http->hostport, eno); + if ((err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno))) == NULL) { + fprintf(stderr, "%s:%d zalloc failed\n", __FILE__, __LINE__); + exit(-1); + } + snprintf(err, (strlen(CFAIL) + strlen(http->hostport) + strlen(eno)), CFAIL, http->hostport, eno); } write_socket(csp->cfd, err, strlen(err)); @@ -406,8 +413,11 @@ chat(struct client_state *csp) } eno = safe_strerror(errno); - err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno)); - sprintf(err, CFAIL, http->hostport, eno); + if ((err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno))) == NULL) { + fprintf(stderr, "%s:%d zalloc failed\n", __FILE__, __LINE__); + exit(-1); + } + snprintf(err,(strlen(CFAIL) + strlen(http->hostport)), CFAIL, http->hostport, eno); write_socket(csp->cfd, err, strlen(err)); freez(err); @@ -488,7 +498,7 @@ chat(struct client_state *csp) fperror(logfp, ""); eno = safe_strerror(errno); - sprintf(buf, CFAIL, http->hostport, eno); + snprintf(buf, sizeof(buf), CFAIL, http->hostport, eno); freez(eno); write_socket(csp->cfd, buf, strlen(buf)); return; @@ -606,6 +616,14 @@ server_thread(void *data) } #endif +void +sigcatcher(int sigraised) +{ + if (sigraised == SIGCHLD) { + waitpid(-1, NULL, WNOHANG); + } +} + int main(int argc, char *argv[]) { @@ -661,7 +679,7 @@ main(int argc, char *argv[]) line_num++; - strcpy(tmp, buf); + strlcpy(tmp, buf, sizeof(tmp)); if((p = strpbrk(tmp, "#\r\n"))) *p = '\0'; @@ -678,7 +696,7 @@ main(int argc, char *argv[]) while(*p && ((*p == ' ') || (*p == '\t'))) p++; - strcpy(arg, p); + strlcpy(arg, p, sizeof(arg)); p = arg + strlen(arg) - 1; @@ -891,8 +909,12 @@ main(int argc, char *argv[]) #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); +#ifdef __OpenBSD__ + signal(SIGCHLD, sigcatcher); +#else signal(SIGCHLD, SIG_IGN); #endif +#endif #ifdef _WIN32 { @@ -994,7 +1016,7 @@ main(int argc, char *argv[]) fprintf(logfp, "%s: can't fork: ", prog); fperror(logfp, ""); - sprintf(buf , "%s: can't fork: errno = %d", + snprintf(buf , sizeof(buf),"%s: can't fork: errno = %d", prog, errno); write_socket(csp->cfd, buf, strlen(buf)); @@ -1043,7 +1065,7 @@ safe_strerror(int err) #endif /* NOSTRERROR */ if(s == NULL) { - sprintf(buf, "(errno = %d)", err); + snprintf(buf, sizeof(buf),"(errno = %d)", err); s = buf; }