From: Dave Hart Date: Sat, 8 Aug 2009 17:30:14 +0000 (+0000) Subject: First pass at quieting Veracode static analysis warnings, X-Git-Tag: NTP_4_2_5P199~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2819b5f328c536b76fefac0bc2b794e86c98ebb9;p=thirdparty%2Fntp.git First pass at quieting Veracode static analysis warnings, mostly buffer manipulation that is already safe but used unsafe interface functions such as strcpy() and sprintf(). use emalloc(), estrdup() where appropriate. bk: 4a7db626RejXNB66rrJX_BXKwPCGwQ --- diff --git a/libntp/msyslog.c b/libntp/msyslog.c index 39815f658..4e2bb4bc2 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -84,12 +84,12 @@ format_errmsg(char *nfmt, int lennfmt, const char *fmt, int errval) register char c; register char *n; register const char *f; - + size_t len; char *err; n = nfmt; f = fmt; - while ((c = *f++) != '\0' && n < (nfmt+lennfmt - 2)) { + while ((c = *f++) != '\0' && n < (nfmt + lennfmt - 2)) { if (c != '%') { *n++ = c; continue; @@ -99,12 +99,13 @@ format_errmsg(char *nfmt, int lennfmt, const char *fmt, int errval) *n++ = c; continue; } - err = 0; err = strerror(errval); + len = strlen(err); + /* Make sure we have enough space for the error message */ - if ((n + strlen(err)) < (nfmt + lennfmt -2)) { - strcpy(n, err); - n += strlen(err); + if ((n + len) < (nfmt + lennfmt - 2)) { + memcpy(n, err, len); + n += len; } } #if !defined(VMS) diff --git a/libntp/ntp_rfc2553.c b/libntp/ntp_rfc2553.c index 592587c6e..01a3c26d6 100644 --- a/libntp/ntp_rfc2553.c +++ b/libntp/ntp_rfc2553.c @@ -431,12 +431,8 @@ do_nodename( #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR ai->ai_addr->sa_len = sizeof(struct sockaddr); #endif - if (hints != NULL && hints->ai_flags & AI_CANONNAME) { - ai->ai_canonname = malloc(strlen(hp->h_name) + 1); - if (ai->ai_canonname == NULL) - return (EAI_MEMORY); - strcpy(ai->ai_canonname, hp->h_name); - } + if (hints != NULL && hints->ai_flags & AI_CANONNAME) + ai->ai_canonname = estrdup(hp->h_name); return (0); } diff --git a/libntp/statestr.c b/libntp/statestr.c index 9ad7f38e3..fcb2c121e 100644 --- a/libntp/statestr.c +++ b/libntp/statestr.c @@ -198,10 +198,10 @@ getcode( while (codetab->code != -1) { if (codetab->code == code) - return codetab->string; + return codetab->string; codetab++; } - (void) sprintf(buf, "%s_%d", codetab->string, code); + snprintf(buf, sizeof(buf), "%s_%d", codetab->string, code); return buf; } @@ -216,8 +216,9 @@ getevents( static char buf[20]; if (cnt == 0) - return "no events"; - (void) sprintf(buf, "%d event%s", cnt, (cnt==1) ? "" : "s"); + return "no events"; + snprintf(buf, sizeof(buf), "%d event%s", cnt, (cnt==1) ? "" : + "s"); return buf; } diff --git a/libparse/parse.c b/libparse/parse.c index c33ecca9d..83e560aff 100644 --- a/libparse/parse.c +++ b/libparse/parse.c @@ -234,7 +234,7 @@ parse_addchar( * collect into buffer */ parseprintf(DD_PARSE, ("parse: parse_addchar: buffer[%d] = 0x%x\n", parseio->parse_index, ch)); - parseio->parse_data[parseio->parse_index++] = ch; + parseio->parse_data[parseio->parse_index++] = (char)ch; return PARSE_INP_SKIP; } else diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 8be82e5c4..694e32d23 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -2313,13 +2313,14 @@ getconfig( /* * install a non default variable with this daemon version */ - (void) sprintf(line, "daemon_version=\"%s\"", Version); + snprintf(line, sizeof(line), "daemon_version=\"%s\"", Version); set_sys_var(line, strlen(line)+1, RO); /* * Say how we're setting the time of day */ - (void) sprintf(line, "settimeofday=\"%s\"", set_tod_using); + snprintf(line, sizeof(line), "settimeofday=\"%s\"", + set_tod_using); set_sys_var(line, strlen(line)+1, RO); /* @@ -2852,7 +2853,10 @@ abort_resolve(void) #ifndef SYS_VXWORKS /* we don't open the file to begin with */ #if !defined(VMS) - (void) unlink(res_file); + if (unlink(res_file)) + msyslog(LOG_WARNING, + "Unable to remove temporary resolver file %s, %m", + res_file); #else (void) delete(res_file); #endif /* VMS */ diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 5a138e576..fb7397c4e 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -1333,16 +1333,15 @@ ctl_putsys( register struct ctl_var *k; s = buf; - be = buf + sizeof(buf) - - strlen(sys_var[CS_VARLIST].text) - 4; - if (s > be) + be = buf + sizeof(buf); + if (s + strlen(sys_var[CS_VARLIST].text) + 4 > be) break; /* really long var name */ - strcpy(s, sys_var[CS_VARLIST].text); - strcat(s, "=\""); + snprintf(s, sizeof(buf), "%s=\"", + sys_var[CS_VARLIST].text); s += strlen(s); t = s; - for (k = sys_var; !(k->flags &EOV); k++) { + for (k = sys_var; !(k->flags & EOV); k++) { if (k->flags & PADDING) continue; i = strlen(k->text); @@ -1351,11 +1350,11 @@ ctl_putsys( if (s != t) *s++ = ','; - strcpy(s, k->text); + memcpy(s, k->text, i); s += i; } - for (k = ext_sys_var; k && !(k->flags &EOV); + for (k = ext_sys_var; k && !(k->flags & EOV); k++) { if (k->flags & PADDING) continue; @@ -1372,7 +1371,7 @@ ctl_putsys( if (s != t) *s++ = ','; - strncpy(s, k->text, + memcpy(s, k->text, (unsigned)i); s += i; } @@ -1440,8 +1439,8 @@ ctl_putsys( case CS_CERTIF: for (cp = cinfo; cp != NULL; cp = cp->link) { - sprintf(cbuf, "%s %s 0x%x", cp->subject, - cp->issuer, cp->flags); + snprintf(cbuf, sizeof(cbuf), "%s %s 0x%x", + cp->subject, cp->issuer, cp->flags); ctl_putstr(sys_var[CS_CERTIF].text, cbuf, strlen(cbuf)); ctl_putfs(sys_var[CS_REVTIME].text, cp->last); @@ -1693,16 +1692,15 @@ ctl_putpeer( register struct ctl_var *k; s = buf; - be = buf + sizeof(buf) - - strlen(peer_var[CP_VARLIST].text) - 4; - if (s > be) + be = buf + sizeof(buf); + if (s + strlen(peer_var[CP_VARLIST].text) + 4 > be) break; /* really long var name */ - strcpy(s, peer_var[CP_VARLIST].text); - strcat(s, "=\""); + snprintf(s, sizeof(buf), "%s=\"", + peer_var[CP_VARLIST].text); s += strlen(s); t = s; - for (k = peer_var; !(k->flags &EOV); k++) { + for (k = peer_var; !(k->flags & EOV); k++) { if (k->flags & PADDING) continue; @@ -1712,7 +1710,7 @@ ctl_putpeer( if (s != t) *s++ = ','; - strcpy(s, k->text); + memcpy(s, k->text, i); s += i; } if (s+2 >= be) @@ -1869,12 +1867,12 @@ ctl_putclock( be) break; /* really long var name */ - strcpy(s, clock_var[CC_VARLIST].text); - strcat(s, "=\""); + snprintf(s, sizeof(buf), "%s=\"", + clock_var[CC_VARLIST].text); s += strlen(s); t = s; - for (k = clock_var; !(k->flags &EOV); k++) { + for (k = clock_var; !(k->flags & EOV); k++) { if (k->flags & PADDING) continue; @@ -1884,7 +1882,7 @@ ctl_putclock( if (s != t) *s++ = ','; - strcpy(s, k->text); + memcpy(s, k->text, i); s += i; } @@ -1905,7 +1903,7 @@ ctl_putclock( if (s != t) *s++ = ','; - strncpy(s, k->text, (unsigned)i); + memcpy(s, k->text, (unsigned)i); s += i; *s = '\0'; } @@ -2778,6 +2776,7 @@ report_event( { char statstr[NTP_MAXSTRLEN]; int i; + size_t len; /* * Report the error to the protostats file, system log and @@ -2800,8 +2799,9 @@ report_event( "0.0.0.0 %04x %02x %s", ctlsysstatus(), err, eventstr(err)); if (str != NULL) { - strcat(statstr, " "); - strcat(statstr, str); + len = strlen(statstr); + snprintf(statstr + len, sizeof(statstr) - len, + " %s", str); } NLOG(NLOG_SYSEVENT) msyslog(LOG_INFO, statstr); @@ -2832,8 +2832,9 @@ report_event( "%s %04x %02x %s", src, ctlpeerstatus(peer), err, eventstr(err)); if (str != NULL) { - strcat(statstr, " "); - strcat(statstr, str); + len = strlen(statstr); + snprintf(statstr + len, sizeof(statstr) - len, + " %s", str); } NLOG(NLOG_PEEREVENT) msyslog(LOG_INFO, statstr); diff --git a/ntpd/ntp_intres.c b/ntpd/ntp_intres.c index ef398a271..eb88b24ed 100644 --- a/ntpd/ntp_intres.c +++ b/ntpd/ntp_intres.c @@ -247,9 +247,12 @@ ntp_intres(void) (void) fclose(in); #ifdef DEBUG - if (!debug ) + if (!debug) #endif - (void) unlink(req_file); + if (unlink(req_file)) + msyslog(LOG_WARNING, + "unable to remove intres request file %s, %m", + req_file); /* * Set up the timers to do first shot immediately. @@ -437,7 +440,8 @@ addentry( ce->ce_flags = (u_char)flags; ce->ce_ttl = (u_char)ttl; ce->ce_keyid = keyid; - strncpy(ce->ce_keystr, keystr, sizeof(ce->ce_keystr)); + strncpy(ce->ce_keystr, keystr, sizeof(ce->ce_keystr) - 1); + ce->ce_keystr[sizeof(ce->ce_keystr) - 1] = 0; ce->ce_next = NULL; if (confentries == NULL) { diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index bc19f3435..af3389f09 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -1108,6 +1108,7 @@ convert_isc_if( ) { strncpy(itf->name, isc_if->name, sizeof(itf->name)); + itf->name[sizeof(itf->name) - 1] = 0; /* strncpy may not */ itf->family = (u_short)isc_if->af; AF(&itf->sin) = itf->family; AF(&itf->mask) = itf->family; diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index 5799f7a37..be7a4d886 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -106,7 +106,7 @@ create_states( if (curr_char && (keyword[0] == curr_char->ch)) my_state = curr_char; else { - my_state = (struct state *) malloc(sizeof(struct state)); + my_state = emalloc(sizeof(*my_state)); my_state->ch = keyword[0]; /* Store the first character of the keyword */ my_state->next_state = NULL; @@ -528,9 +528,8 @@ yylex( ip_file->prev_token_col_no = ip_file->col_no; /* Read in the lexeme */ - for (i = 0; - (i < MAX_LEXEME) && EOF != (yytext[i] = get_next_char()); - i++) { + i = 0; + while (EOF != (yytext[i] = get_next_char())) { /* Break on whitespace or a special character */ if (isspace(yytext[i]) @@ -546,6 +545,10 @@ yylex( ; /* Null Statement */ break; } + + i++; + if (i >= COUNTOF(yytext)) + goto lex_too_long; } /* Pick up all of the string inside between " marks, to * end of line. If we make it to EOL without a @@ -558,6 +561,8 @@ yylex( while ((yytext[i] = get_next_char()) != EOF && yytext[i] != '"' && yytext[i] != '\n') { i++; + if (i >= COUNTOF(yytext)) + goto lex_too_long; } if (yytext[i] == '"') yytext[i] = ' '; @@ -584,7 +589,7 @@ yylex( * returned) and that we haven't read a string. */ - if ((expect_string == NO_ARG) && (!instring)) { + if (expect_string == NO_ARG && !instring) { token = is_keyword(yytext, &expect_string); if (token) return token; @@ -648,4 +653,24 @@ yylex( expect_string = NO_ARG; return create_string_token(yytext); + +lex_too_long: + yytext[min(sizeof(yytext) - 1, 50)] = 0; + msyslog(LOG_ERR, + "configuration item on line %d longer than limit of %d, began with '%s'", + ip_file->line_no, sizeof(yytext) - 1, yytext); + + /* + * If we hit the length limit reading the startup configuration + * file, abort. + */ + if (input_from_file) + exit(sizeof(yytext) - 1); + + /* + * If it's runtime configuration via ntpq :config treat it as + * if the configuration text ended before the too-long lexeme, + * hostname, or string. + */ + return 0; } diff --git a/ntpd/ntp_signd.c b/ntpd/ntp_signd.c index 3b3c5ef63..3beb03be5 100644 --- a/ntpd/ntp_signd.c +++ b/ntpd/ntp_signd.c @@ -110,10 +110,7 @@ recv_packet(int fd, char **buf, uint32_t *len) { if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; *len = ntohl(*len); - (*buf) = malloc(*len); - if (!*buf) { - return -1; - } + (*buf) = emalloc(*len); if (read_all(fd, *buf, *len) != *len) { free(*buf); return -1; diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index e3b858fd6..65f3d3568 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -295,12 +295,17 @@ write_stats(void) (void)fclose(fp); /* atomic */ #ifdef SYS_WINNT - (void) _unlink(stats_drift_file); /* rename semantics differ under NT */ + if (_unlink(stats_drift_file)) /* rename semantics differ under NT */ + msyslog(LOG_WARNING, + "Unable to remove prior drift file %s, %m", + stats_drift_file); #endif /* SYS_WINNT */ #ifndef NO_RENAME - (void) rename(stats_temp_file, - stats_drift_file); + if (rename(stats_temp_file, stats_drift_file)) + msyslog(LOG_WARNING, + "Unable to rename temp drift file %s to %s, %m", + stats_temp_file, stats_drift_file); #else /* we have no rename NFS of ftp in use */ if ((fp = fopen(stats_drift_file, "w")) == diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index b7be64afb..dd9abf134 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -918,16 +918,20 @@ getgroup: } } - if( chrootdir ) { + if (chrootdir ) { /* make sure cwd is inside the jail: */ - if( chdir(chrootdir) ) { + if (chdir(chrootdir)) { msyslog(LOG_ERR, "Cannot chdir() to `%s': %m", chrootdir); exit (-1); } - if( chroot(chrootdir) ) { + if (chroot(chrootdir)) { msyslog(LOG_ERR, "Cannot chroot() to `%s': %m", chrootdir); exit (-1); } + if (chdir("/")) { + msyslog(LOG_ERR, "Cannot chdir() to`root after chroot(): %m"); + exit (-1); + } } if (user && initgroups(user, sw_gid)) { msyslog(LOG_ERR, "Cannot initgroups() to user `%s': %m", user); diff --git a/ntpd/refclock_acts.c b/ntpd/refclock_acts.c index 058abfd64..71923ce51 100644 --- a/ntpd/refclock_acts.c +++ b/ntpd/refclock_acts.c @@ -250,9 +250,6 @@ acts_start ( * Allocate and initialize unit structure */ up = emalloc(sizeof(struct actsunit)); - if (up == NULL) - return (0); - memset(up, 0, sizeof(struct actsunit)); up->unit = unit; pp = peer->procptr; diff --git a/ntpd/refclock_bancomm.c b/ntpd/refclock_bancomm.c index 5c4966218..0e9ceb002 100644 --- a/ntpd/refclock_bancomm.c +++ b/ntpd/refclock_bancomm.c @@ -422,9 +422,8 @@ get_datumtime(struct vmedate *time_vme) uint8_t dmy; struct stfp_time stfpm; - if ( time_vme == (struct vmedate *)NULL) { - time_vme = (struct vmedate *)malloc(sizeof(struct vmedate )); - } + if (time_vme == NULL) + time_vme = emalloc(sizeof(*time_vme)); switch (tfp_type) { case 1: /* BSD, PCI, 2 32bit time words */ diff --git a/ntpd/refclock_datum.c b/ntpd/refclock_datum.c index e3fcdcd76..247d7da4a 100644 --- a/ntpd/refclock_datum.c +++ b/ntpd/refclock_datum.c @@ -397,7 +397,7 @@ datum_pts_shutdown( if (nunits > 1) { temp_datum_pts_unit = (struct datum_pts_unit **) - malloc((nunits-1)*sizeof(struct datum_pts_unit *)); + emalloc((nunits-1)*sizeof(struct datum_pts_unit *)); if (i!= 0) memcpy(temp_datum_pts_unit, datum_pts_unit, i*sizeof(struct datum_pts_unit *)); diff --git a/ntpd/refclock_oncore.c b/ntpd/refclock_oncore.c index 52507057f..97a62986b 100644 --- a/ntpd/refclock_oncore.c +++ b/ntpd/refclock_oncore.c @@ -600,11 +600,8 @@ oncore_start( /* create instance structure for this unit */ - if (!(instance = (struct instance *) malloc(sizeof *instance))) { - perror("malloc"); - return (0); - } - memset((char *) instance, 0, sizeof *instance); + instance = emalloc(sizeof(*instance)); + memset(instance, 0, sizeof(*instance)); /* initialize miscellaneous variables */ @@ -929,7 +926,7 @@ oncore_init_shmem( struct stat sbuf; size_t shmem_length; - /* + /* * The first thing we do is see if there is an instance->shmem_fname file (still) * out there from a previous run. If so, we copy it in and use it to initialize * shmem (so we won't lose our almanac if we need it). @@ -943,11 +940,8 @@ oncore_init_shmem( fstat(fd, &sbuf); shmem_old_size = sbuf.st_size; if (shmem_old_size != 0) { - shmem_old = (u_char *) malloc((unsigned) sbuf.st_size); - if (shmem_old == NULL) - oncore_log(instance, LOG_WARNING, "ONCORE: Can't malloc buffer for shmem_old"); - else - read(fd, shmem_old, shmem_old_size); + shmem_old = emalloc((unsigned) sbuf.st_size); + read(fd, shmem_old, shmem_old_size); } close(fd); } @@ -988,16 +982,7 @@ oncore_init_shmem( } shmem_length = n + 2; - buf = malloc(shmem_length); - if (buf == NULL) { - oncore_log(instance, LOG_WARNING, "ONCORE: Can't malloc buffer for shmem"); - close(instance->shmemfd); - if (shmem_old) - free(shmem_old); - - return; - } - + buf = emalloc(shmem_length); memset(buf, 0, shmem_length); /* next build the new SHMEM buffer in memory */ @@ -1263,9 +1248,7 @@ oncore_read_config( continue; if (!strncmp(cc, "STATUS", (size_t) 6) || !strncmp(cc, "SHMEM", (size_t) 5)) { - i = strlen(ca); - instance->shmem_fname = (char *) malloc((unsigned) (i+1)); - strcpy(instance->shmem_fname, ca); + instance->shmem_fname = estrdup(ca); continue; } diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 27c3c7361..70b33704c 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -2232,7 +2232,7 @@ getnetinfoservers(void) ni_status status; void *domain; ni_id confdir; - ni_namelist *namelist = (ni_namelist*)malloc(sizeof(ni_namelist)); + ni_namelist *namelist = emalloc(sizeof(ni_namelist)); /* Find a time server in NetInfo */ if ((status = ni_open(NULL, ".", &domain)) != NI_OK) return NULL; diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 78abce39a..d5bab66b9 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -436,12 +436,8 @@ ntpdcmain( /* * Initialize the packet data buffer */ - pktdata = (char *)malloc(INITDATASIZE); - if (pktdata == NULL) { - (void) fprintf(stderr, "%s: malloc() failed!\n", progname); - exit(1); - } pktdatasize = INITDATASIZE; + pktdata = emalloc(INITDATASIZE); if (numcmds == 0) { (void) openhost(chosts[0]); diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index ac8766bbf..d39eb67c6 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -19,7 +19,6 @@ int maxhostlen; * Declarations for command handlers in here */ static int checkassocid (u_int32); -static char * strsave (char *); static struct varlist *findlistvar (struct varlist *, char *); static void doaddvlist (struct varlist *, char *); static void dormvlist (struct varlist *, char *); @@ -225,29 +224,6 @@ checkassocid( } -/* - * strsave - save a string - * XXX - should be in libntp.a - */ -static char * -strsave( - char *str - ) -{ - char *cp; - u_int len; - - len = strlen(str) + 1; - if ((cp = (char *)malloc(len)) == NULL) { - (void) fprintf(stderr, "Malloc failed!!\n"); - exit(1); - } - - memmove(cp, str, len); - return (cp); -} - - /* * findlistvar - look for the named variable in a list and return if found */ @@ -291,14 +267,14 @@ doaddvlist( } if (vl->name == 0) { - vl->name = strsave(name); + vl->name = estrdup(name); } else if (vl->value != 0) { free(vl->value); vl->value = 0; } if (value != 0) - vl->value = strsave(value); + vl->value = estrdup(value); } } diff --git a/ports/winnt/libisc/isc_strerror.c b/ports/winnt/libisc/isc_strerror.c index 299d29165..c5883caa7 100644 --- a/ports/winnt/libisc/isc_strerror.c +++ b/ports/winnt/libisc/isc_strerror.c @@ -22,10 +22,14 @@ */ #pragma warning(disable: 4127) /* conditional expression is constant */ +#ifdef HAVE_CONFIG_H +# include +#endif #include #include #include #include +#include "ntp_stdlib.h" /* @@ -165,12 +169,10 @@ FormatError(int error) { NULL); if (lpMsgBuf) { - lmsg = malloc(sizeof(*lmsg)); - if (lmsg) { - lmsg->code = error; - lmsg->msg = lpMsgBuf; - ISC_LIST_APPEND(errormsg_list, lmsg, link); - } + lmsg = emalloc(sizeof(*lmsg)); + lmsg->code = error; + lmsg->msg = lpMsgBuf; + ISC_LIST_APPEND(errormsg_list, lmsg, link); } UNLOCK(&ErrorMsgLock); return (lpMsgBuf); @@ -235,6 +237,7 @@ isc__NTstrerror(int err) { #endif /* _MSC_VER */ if (!retmsg) { +#undef strerror retmsg = strerror(err); } diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index f900fbf7b..9d5bb469e 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -101,11 +101,12 @@ GetHeapAlloc(char *fromfunc) IoCompletionInfo *lpo; #ifdef USE_HEAP - lpo = (IoCompletionInfo *) HeapAlloc(hHeapHandle, - HEAP_ZERO_MEMORY, - sizeof(IoCompletionInfo)); + lpo = HeapAlloc(hHeapHandle, + HEAP_ZERO_MEMORY, + sizeof(IoCompletionInfo)); #else - lpo = (IoCompletionInfo *) calloc(1, sizeof(*lpo)); + lpo = emalloc(sizeof(*lpo)); + memset(lpo, 0, sizeof(*lpo)); #endif DPRINTF(3, ("Allocation %d memory for %s, ptr %x\n", sizeof(IoCompletionInfo), fromfunc, lpo)); @@ -879,7 +880,9 @@ io_completion_port_sendto( * Something bad happened */ default : - msyslog(LOG_ERR, "WSASendTo - error sending message: %m"); + msyslog(LOG_ERR, + "WSASendTo(%s) error %d: %s", + stoa(dest), errval, strerror(errval)); free_trans_buf(buff); lpo->trans_buf = NULL; FreeHeap(lpo, "io_completion_port_sendto");