$OpenBSD: patch-jcc_c,v 1.6 2010/05/24 22:17:03 espie Exp $ --- jcc.c.orig Sat Oct 31 04:58:47 1998 +++ jcc.c Tue May 25 00:15:28 2010 @@ -126,9 +126,10 @@ int add_forwarded = 0; struct client_state clients[1]; struct file_list files[1]; -struct list wafer_list[1]; -struct list xtra_list[1]; -struct list trust_info[1]; +static struct list wafer_storage, xtra_storage, trust_storage; +struct list *wafer_list = &wafer_storage; +struct list *xtra_list = &xtra_storage; +struct list *trust_info = &trust_storage; struct url_spec * trust_list[64]; @@ -226,7 +227,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 +370,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 +414,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 +499,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 +617,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 +680,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 +697,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 +910,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 +1017,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 +1066,7 @@ safe_strerror(int err) #endif /* NOSTRERROR */ if(s == NULL) { - sprintf(buf, "(errno = %d)", err); + snprintf(buf, sizeof(buf),"(errno = %d)", err); s = buf; }