uhttpd/file: fix string out of buffer range on uh_defer_script
[project/uhttpd.git] / ucode.c
diff --git a/ucode.c b/ucode.c
index e76f441ea622778504bc098a353fc76e08343ab2..bbb9b00c93bd264e9738b3494af5203316ff3132 100644 (file)
--- a/ucode.c
+++ b/ucode.c
@@ -115,20 +115,22 @@ uh_ucode_recv(uc_vm_t *vm, size_t nargs)
 static uc_value_t *
 uh_ucode_send(uc_vm_t *vm, size_t nargs)
 {
-       uc_value_t *val = uc_fn_arg(0);
-       ssize_t len;
+       uc_value_t *val;
+       size_t arridx;
+       ssize_t len = 0;
        char *p;
 
-       if (ucv_type(val) == UC_STRING) {
-               len = write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val));
-       }
-       else if (val != NULL) {
-               p = ucv_to_string(vm, val);
-               len = p ? write(STDOUT_FILENO, p, strlen(p)) : 0;
-               free(p);
-       }
-       else {
-               len = 0;
+       for (arridx = 0; arridx < nargs; arridx++) {
+               val = uc_fn_arg(arridx);
+
+               if (ucv_type(val) == UC_STRING) {
+                       len += write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val));
+               }
+               else if (val != NULL) {
+                       p = ucv_to_string(vm, val);
+                       len += p ? write(STDOUT_FILENO, p, strlen(p)) : 0;
+                       free(p);
+               }
        }
 
        return ucv_int64_new(len);
@@ -199,8 +201,8 @@ uh_ucode_exception(uc_vm_t *vm, uc_exception_t *ex)
                return;
 
        printf("Status: 500 Internal Server Error\r\n\r\n"
-       "Exception while executing ucode program %s:\n",
-       current_prefix->handler);
+              "Exception while executing ucode program %s:\n",
+              current_prefix->handler);
 
        switch (ex->type) {
        case EXCEPTION_SYNTAX:    printf("Syntax error");    break;
@@ -229,6 +231,7 @@ uh_ucode_state_init(struct ucode_prefix *ucode)
        uc_value_t *v;
        int exitcode;
 
+       uc_search_path_init(&config.module_search_path);
        uc_vm_init(vm, &config);
        uc_stdlib_load(uc_vm_scope_get(vm));