ext/libuv/src/unix/openbsd.c in libuv-2.0.8 vs ext/libuv/src/unix/openbsd.c in libuv-2.0.9
- old
+ new
@@ -167,18 +167,28 @@
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
+ size_t len;
+
+ if (buffer == NULL || size == 0)
+ return -EINVAL;
+
if (process_title) {
- strncpy(buffer, process_title, size);
+ len = strlen(process_title) + 1;
+
+ if (size < len)
+ return -ENOBUFS;
+
+ memcpy(buffer, process_title, len);
} else {
- if (size > 0) {
- buffer[0] = '\0';
- }
+ len = 0;
}
+ buffer[len] = '\0';
+
return 0;
}
int uv_resident_set_memory(size_t* rss) {
@@ -245,21 +255,21 @@
*count = numcpus;
which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
- SAVE_ERRNO(uv__free(*cpu_infos));
+ uv__free(*cpu_infos);
return -errno;
}
size = sizeof(info);
which[0] = CTL_KERN;
which[1] = KERN_CPTIME2;
for (i = 0; i < numcpus; i++) {
which[2] = i;
size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0)) {
- SAVE_ERRNO(uv__free(*cpu_infos));
+ uv__free(*cpu_infos);
return -errno;
}
cpu_info = &(*cpu_infos)[i];