#include <v8-debug.h>
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
using namespace v8;
extern char **environ;
static ev_async eio_done_poll_notifier;
static ev_idle eio_poller;
-// Buffer for getpwnam_r(), getgrpam_r(); keep this scoped at file-level rather
-// than method-level to avoid excess stack usage.
-static char getbuf[1024];
+// Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this
+// scoped at file-level rather than method-level to avoid excess stack usage.
+static char getbuf[PATH_MAX + 1];
// We need to notify V8 when we're idle so that it can run the garbage
// collector. The interface to this is V8::IdleNotification(). It returns
HandleScope scope;
assert(args.Length() == 0);
- char output[PATH_MAX];
- char *r = getcwd(output, PATH_MAX);
+ char *r = getcwd(getbuf, ARRAY_SIZE(getbuf) - 1);
if (r == NULL) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
}
- Local<String> cwd = String::New(output);
+
+ getbuf[ARRAY_SIZE(getbuf) - 1] = '\0';
+ Local<String> cwd = String::New(r);
return scope.Close(cwd);
}
struct group grp, *grpp = NULL;
int err;
- if ((err = getgrnam_r(*grpnam, &grp, getbuf, sizeof(getbuf), &grpp)) ||
+ if ((err = getgrnam_r(*grpnam, &grp, getbuf, ARRAY_SIZE(getbuf), &grpp)) ||
grpp == NULL) {
return ThrowException(ErrnoException(errno, "getgrnam_r"));
}
struct passwd pwd, *pwdp = NULL;
int err;
- if ((err = getpwnam_r(*pwnam, &pwd, getbuf, sizeof(getbuf), &pwdp)) ||
+ if ((err = getpwnam_r(*pwnam, &pwd, getbuf, ARRAY_SIZE(getbuf), &pwdp)) ||
pwdp == NULL) {
return ThrowException(ErrnoException(errno, "getpwnam_r"));
}
void *init_handle = dlsym(handle, "init");
// Error out if not found.
if (init_handle == NULL) {
+ dlclose(handle);
Local<Value> exception =
Exception::Error(String::New("No 'init' symbol found in module."));
return ThrowException(exception);
// Execute the C++ module
init(target);
+ // Tell coverity that 'handle' should not be freed when we return.
+ // coverity[leaked_storage]
return Undefined();
}
Local<Function> cb = Local<Function>::Cast(args[2]);
struct resolve_request *rreq = (struct resolve_request *)
- calloc(1, sizeof(struct resolve_request) + hostname.length());
+ calloc(1, sizeof(struct resolve_request) + hostname.length() + 1);
if (!rreq) {
V8::LowMemoryNotification();
String::New("Could not allocate enough memory")));
}
- strcpy(rreq->hostname, *hostname);
+ strncpy(rreq->hostname, *hostname, hostname.length() + 1);
rreq->cb = Persistent<Function>::New(cb);
rreq->ai_family = fam;