+* A few more Coverity Scan cleanups.
(4.2.7p152) 2011/04/15 Released by Harlan Stenn <stenn@ntp.org>
* Update embedded libevent to current 2.1 git HEAD.
(4.2.7p151) 2011/04/14 Released by Harlan Stenn <stenn@ntp.org>
{
static const char *fmt = "%u.%u.%u.%u";
char tmp[sizeof("255.255.255.255")];
+ int len;
- if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2],
- src[3]) >= size)
+ len = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
+ if (len < 0 || len >= size)
{
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ memcpy(dst, tmp, 1 + len);
return (dst);
}
tp += strlen(tp);
break;
}
- tp += sprintf(tp, "%x", words[i]);
+ tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==
errno = ENOSPC;
return (NULL);
}
- strcpy(dst, tmp);
+ memcpy(dst, tmp, (size_t)(tp - tmp));
return (dst);
}
#endif /* AF_INET6 */
#include <isc/string.h>
#include <isc/time.h>
#include <isc/util.h>
+#include "l_stdlib.h" /* NTP change for strlcpy, strlcat */
#define LCTX_MAGIC ISC_MAGIC('L', 'c', 't', 'x')
#define VALID_CONTEXT(lctx) ISC_MAGIC_VALID(lctx, LCTX_MAGIC)
int syslog_level;
char time_string[64];
char level_string[24];
+ size_t octets;
const char *iformat;
struct stat statbuf;
isc_boolean_t matched = ISC_FALSE;
* It wasn't in the duplicate interval,
* so add it to the message list.
*/
+ octets = strlen(lctx->buffer) + 1;
new = isc_mem_get(lctx->mctx,
sizeof(isc_logmessage_t) +
- strlen(lctx->buffer) + 1);
+ octets);
if (new != NULL) {
/*
* Put the text immediately after
* the struct. The strcpy is safe.
*/
new->text = (char *)(new + 1);
- strcpy(new->text, lctx->buffer);
+ strlcpy(new->text, lctx->buffer, octets);
TIME_NOW(&new->time);
#include <isc/sockaddr.h>
#include <isc/string.h>
#include <isc/util.h>
+#include "l_stdlib.h" /* NTP change for strlcpy, strlcat */
isc_boolean_t
isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b) {
memset(netaddr, 0, sizeof(*netaddr));
netaddr->family = AF_UNIX;
- strcpy(netaddr->type.un, path);
+ strlcpy(netaddr->type.un, path, sizeof(netaddr->type.un));
netaddr->zone = 0;
return (ISC_R_SUCCESS);
#else
manager_free(isc_taskmgr_t *manager) {
isc_mem_t *mctx;
+ LOCK(&manager->lock);
#ifdef ISC_PLATFORM_USETHREADS
(void)isc_condition_destroy(&manager->exclusive_granted);
(void)isc_condition_destroy(&manager->work_available);
isc_mem_free(manager->mctx, manager->threads);
#endif /* ISC_PLATFORM_USETHREADS */
manager->magic = 0;
- DESTROYLOCK(&manager->lock);
mctx = manager->mctx;
+ UNLOCK(&manager->lock);
+ DESTROYLOCK(&manager->lock);
isc_mem_put(mctx, manager, sizeof(*manager));
isc_mem_detach(&mctx);
}
#include <isc/util.h>
#include "errno2result.h"
+#include "l_stdlib.h" /* NTP change for strlcpy, strlcat */
#define ISC_DIR_MAGIC ISC_MAGIC('D', 'I', 'R', '*')
#define VALID_DIR(dir) ISC_MAGIC_VALID(dir, ISC_DIR_MAGIC)
isc_result_t
isc_dir_open(isc_dir_t *dir, const char *dirname) {
char *p;
+ size_t octets;
isc_result_t result = ISC_R_SUCCESS;
REQUIRE(VALID_DIR(dir));
* Copy directory name. Need to have enough space for the name,
* a possible path separator, the wildcard, and the final NUL.
*/
- if (strlen(dirname) + 3 > sizeof(dir->dirname))
+ octets = strlen(dirname) + 1;
+ if (octets + 2 > sizeof(dir->dirname))
/* XXXDCL ? */
return (ISC_R_NOSPACE);
- strcpy(dir->dirname, dirname);
+ strlcpy(dir->dirname, dirname, octets);
/*
* Append path separator, if needed, and "*".
isc_result_t
isc_dir_read(isc_dir_t *dir) {
struct dirent *entry;
+ size_t octets;
REQUIRE(VALID_DIR(dir) && dir->handle != NULL);
/*
* Make sure that the space for the name is long enough.
*/
- if (sizeof(dir->entry.name) <= strlen(entry->d_name))
- return (ISC_R_UNEXPECTED);
+ octets = strlen(entry->d_name) + 1;
+ if (sizeof(dir->entry.name) < octets)
+ return (ISC_R_UNEXPECTED);
- strcpy(dir->entry.name, entry->d_name);
+ strlcpy(dir->entry.name, entry->d_name, octets);
/*
* Some dirents have d_namlen, but it is not portable.
#include <isc/util.h>
#include "errno2result.h"
+#include "l_stdlib.h" /* NTP change for strlcpy, strlcat */
/*
* XXXDCL As the API for accessing file statistics undoubtedly gets expanded,
if ((s - path + 1 + strlen(templet) + 1) > buflen)
return (ISC_R_NOSPACE);
- strncpy(buf, path, s - path + 1);
+ strlcpy(buf, path, buflen);
buf[s - path + 1] = '\0';
- strcat(buf, templet);
+ strlcat(buf, templet, buflen);
} else {
if ((strlen(templet) + 1) > buflen)
return (ISC_R_NOSPACE);
- strcpy(buf, templet);
+ strlcpy(buf, templet, buflen);
}
return (ISC_R_SUCCESS);
if (strlen(dirname) + 1 == length)
result = ISC_R_NOSPACE;
else if (dirname[1] != '\0')
- strcat(dirname, "/");
+ strlcat(dirname, "/", length);
}
return (result);
return (result);
if (strlen(path) + strlen(filename) + 1 > pathlen)
return (ISC_R_NOSPACE);
- strcat(path, filename);
+ strlcat(path, filename, pathlen);
return (ISC_R_SUCCESS);
}
ttyb.c_cc[VTIME] = 5; /* receive timeout */
cfsetispeed(&ttyb, (u_int)speed);
cfsetospeed(&ttyb, (u_int)speed);
- tcsetattr(fd, TCSANOW, &ttyb);
+ rc = tcsetattr(fd, TCSANOW, &ttyb);
if (rc < 0) {
saved_errno = errno;
close(fd);
blocking_pipe_header * threadcopy;
REQUIRE(hdr != NULL);
- REQUIRE(hdr->octets > sizeof(*hdr));
REQUIRE(data != NULL);
DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == hdr->magic_sig);
+ if (sizeof(*hdr) < hdr->octets)
+ return 1; /* failure */
+
ensure_workitems_empty_slot(c);
if (NULL == c->thread_ref) {
ensure_workresp_empty_slot(c);
struct datum_pts_unit *datum_pts;
int fd;
#ifdef HAVE_TERMIOS
+ int rc;
struct termios arg;
#endif
arg.c_cc[VMIN] = 0; /* start timeout timer right away (not used) */
arg.c_cc[VTIME] = 30; /* 3 second timout on reads (not used) */
- tcsetattr(datum_pts->PTS_fd, TCSANOW, &arg);
+ rc = tcsetattr(datum_pts->PTS_fd, TCSANOW, &arg);
+ if (rc < 0) {
+ msyslog(LOG_ERR, "Datum_PTS: tcsetattr(\"%s\") failed: %m", DATUM_DEV);
+ close(datum_pts->PTS_fd);
+ return 0;
+ }
/*
** Initialize the ntpd IO structure