Source
xxxxxxxxxx
duk_def_prop(es->env->ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_CLEAR_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE |
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/* maximum number of consequent runtime errors after which it's treated as fatal error */
typedef struct
{
const void *heapptr; /* js object heap ptr */
void *data;
zbx_es_obj_type_t type;
}
zbx_es_obj_data_t;
/******************************************************************************
* *
* Purpose: fatal error handler *
* *
******************************************************************************/
static void es_handle_error(void *udata, const char *msg)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
zabbix_log(LOG_LEVEL_WARNING, "Cannot process javascript, fatal error: %s", msg);
env->fatal_error = 1;
env->error = zbx_strdup(env->error, msg);
longjmp(env->loc, 1);
}
/*
* Memory allocation routines to track and limit script memory usage.
*/
static void *es_malloc(void *udata, duk_size_t size)
{
zbx_es_env_t *env = (zbx_es_env_t *)udata;
uint64_t *uptr;
if (env->total_alloc + size + 8 > env->max_total_alloc)
env->max_total_alloc = env->total_alloc + size + 8;
if (env->total_alloc + size + 8 > ZBX_ES_MEMORY_LIMIT)
{
if (NULL == env->ctx)
env->error = zbx_strdup(env->error, "cannot allocate memory");
return NULL;
}
env->total_alloc += (size + 8);
uptr = zbx_malloc(NULL, size + 8);
*uptr++ = size;
return uptr;
}
static void *es_realloc(void *udata, void *ptr, duk_size_t size)
{