Added security hook and fixed error reporting bug
authorMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 8 Sep 2006 14:24:07 +0000 (14:24 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 8 Sep 2006 14:24:07 +0000 (14:24 +0000)
mmsoftware/js/classes/js_dir.c

index 5407127..32eb4a5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: js_dir.c,v 1.1 2006/09/08 12:50:43 mmondor Exp $ */
+/* $Id: js_dir.c,v 1.2 2006/09/08 14:24:07 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -56,6 +56,8 @@ static JSBool dir_m_rewind(JSContext *, JSObject *, uintN, jsval *,
                    jsval *);
 static JSBool  dir_m_close(JSContext *, JSObject *, uintN, jsval *, jsval *);
 
+static int     dir_path_allow(const char *);
+
 
 
 /*
@@ -155,11 +157,21 @@ dir_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
        }
 
        path = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
+
+       if (dir_path_allow(path) == -1) {
+               char    str[1024];
+
+               (void) snprintf(str, sizeof(str), "opendir('%s'): %s",
+                   path, "Denied by security hook dir_path_allow()");
+               QUEUE_EXCEPTION(str);
+               goto err;
+       }
+
        if ((dir = opendir(path)) == NULL) {
-               char    str[256];
+               char    str[1024];
 
                (void) snprintf(str, sizeof(str), "opendir('%s'): %s",
-                   str, strerror(errno));
+                   path, strerror(errno));
                QUEUE_EXCEPTION(str);
                goto err;
        }
@@ -337,3 +349,12 @@ dir_m_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 
        return JS_TRUE;
 }
+
+
+/* Security hook could be added here */
+static int
+dir_path_allow(const char *path)
+{
+
+       return 0;
+}