idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
5,800
|
hook_hsignal (struct t_weechat_plugin *plugin, const char *signal,
t_hook_callback_hsignal *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hsignal *new_hook_hsignal;
int priority;
const char *ptr_signal;
if (!signal || !signal[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_hsignal = malloc (sizeof (*new_hook_hsignal));
if (!new_hook_hsignal)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (signal, &priority, &ptr_signal);
hook_init_data (new_hook, plugin, HOOK_TYPE_HSIGNAL, priority,
callback_data);
new_hook->hook_data = new_hook_hsignal;
new_hook_hsignal->callback = callback;
new_hook_hsignal->signal = strdup ((ptr_signal) ? ptr_signal : signal);
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_hsignal (struct t_weechat_plugin *plugin, const char *signal,
t_hook_callback_hsignal *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hsignal *new_hook_hsignal;
int priority;
const char *ptr_signal;
if (!signal || !signal[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_hsignal = malloc (sizeof (*new_hook_hsignal));
if (!new_hook_hsignal)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (signal, &priority, &ptr_signal);
hook_init_data (new_hook, plugin, HOOK_TYPE_HSIGNAL, priority,
callback_data);
new_hook->hook_data = new_hook_hsignal;
new_hook_hsignal->callback = callback;
new_hook_hsignal->signal = strdup ((ptr_signal) ? ptr_signal : signal);
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,801
|
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0)))
{
ptr_hook->running = 1;
(void) (HOOK_HSIGNAL(ptr_hook, callback))
(ptr_hook->callback_data, signal, hashtable);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
Exec Code
| 0
|
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0)))
{
ptr_hook->running = 1;
(void) (HOOK_HSIGNAL(ptr_hook, callback))
(ptr_hook->callback_data, signal, hashtable);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,802
|
hook_info (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
t_hook_callback_info *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_info *new_hook_info;
int priority;
const char *ptr_info_name;
if (!info_name || !info_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_info = malloc (sizeof (*new_hook_info));
if (!new_hook_info)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data);
new_hook->hook_data = new_hook_info;
new_hook_info->callback = callback;
new_hook_info->info_name = strdup ((ptr_info_name) ?
ptr_info_name : info_name);
new_hook_info->description = strdup ((description) ? description : "");
new_hook_info->args_description = strdup ((args_description) ?
args_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_info (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
t_hook_callback_info *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_info *new_hook_info;
int priority;
const char *ptr_info_name;
if (!info_name || !info_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_info = malloc (sizeof (*new_hook_info));
if (!new_hook_info)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data);
new_hook->hook_data = new_hook_info;
new_hook_info->callback = callback;
new_hook_info->info_name = strdup ((ptr_info_name) ?
ptr_info_name : info_name);
new_hook_info->description = strdup ((description) ? description : "");
new_hook_info->args_description = strdup ((args_description) ?
args_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,803
|
hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
const char *value;
/* make C compiler happy */
(void) plugin;
if (!info_name || !info_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFO];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFO(ptr_hook, info_name),
info_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFO(ptr_hook, callback))
(ptr_hook->callback_data, info_name, arguments);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* info not found */
return NULL;
}
|
Exec Code
| 0
|
hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
const char *value;
/* make C compiler happy */
(void) plugin;
if (!info_name || !info_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFO];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFO(ptr_hook, info_name),
info_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFO(ptr_hook, callback))
(ptr_hook->callback_data, info_name, arguments);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* info not found */
return NULL;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,804
|
hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hashtable *value;
/* make C compiler happy */
(void) plugin;
if (!info_name || !info_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name),
info_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
(ptr_hook->callback_data, info_name, hashtable);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* info not found */
return NULL;
}
|
Exec Code
| 0
|
hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
struct t_hashtable *hashtable)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hashtable *value;
/* make C compiler happy */
(void) plugin;
if (!info_name || !info_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name),
info_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
(ptr_hook->callback_data, info_name, hashtable);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* info not found */
return NULL;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,805
|
hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
const char *output_description,
t_hook_callback_info_hashtable *callback,
void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_info_hashtable *new_hook_info_hashtable;
int priority;
const char *ptr_info_name;
if (!info_name || !info_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_info_hashtable = malloc (sizeof (*new_hook_info_hashtable));
if (!new_hook_info_hashtable)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority,
callback_data);
new_hook->hook_data = new_hook_info_hashtable;
new_hook_info_hashtable->callback = callback;
new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ?
ptr_info_name : info_name);
new_hook_info_hashtable->description = strdup ((description) ? description : "");
new_hook_info_hashtable->args_description = strdup ((args_description) ?
args_description : "");
new_hook_info_hashtable->output_description = strdup ((output_description) ?
output_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
const char *output_description,
t_hook_callback_info_hashtable *callback,
void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_info_hashtable *new_hook_info_hashtable;
int priority;
const char *ptr_info_name;
if (!info_name || !info_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_info_hashtable = malloc (sizeof (*new_hook_info_hashtable));
if (!new_hook_info_hashtable)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority,
callback_data);
new_hook->hook_data = new_hook_info_hashtable;
new_hook_info_hashtable->callback = callback;
new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ?
ptr_info_name : info_name);
new_hook_info_hashtable->description = strdup ((description) ? description : "");
new_hook_info_hashtable->args_description = strdup ((args_description) ?
args_description : "");
new_hook_info_hashtable->output_description = strdup ((output_description) ?
output_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,806
|
hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name,
const char *description, const char *pointer_description,
const char *args_description,
t_hook_callback_infolist *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_infolist *new_hook_infolist;
int priority;
const char *ptr_infolist_name;
if (!infolist_name || !infolist_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_infolist = malloc (sizeof (*new_hook_infolist));
if (!new_hook_infolist)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (infolist_name, &priority, &ptr_infolist_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFOLIST, priority,
callback_data);
new_hook->hook_data = new_hook_infolist;
new_hook_infolist->callback = callback;
new_hook_infolist->infolist_name = strdup ((ptr_infolist_name) ?
ptr_infolist_name : infolist_name);
new_hook_infolist->description = strdup ((description) ? description : "");
new_hook_infolist->pointer_description = strdup ((pointer_description) ?
pointer_description : "");
new_hook_infolist->args_description = strdup ((args_description) ?
args_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name,
const char *description, const char *pointer_description,
const char *args_description,
t_hook_callback_infolist *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_infolist *new_hook_infolist;
int priority;
const char *ptr_infolist_name;
if (!infolist_name || !infolist_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_infolist = malloc (sizeof (*new_hook_infolist));
if (!new_hook_infolist)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (infolist_name, &priority, &ptr_infolist_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFOLIST, priority,
callback_data);
new_hook->hook_data = new_hook_infolist;
new_hook_infolist->callback = callback;
new_hook_infolist->infolist_name = strdup ((ptr_infolist_name) ?
ptr_infolist_name : infolist_name);
new_hook_infolist->description = strdup ((description) ? description : "");
new_hook_infolist->pointer_description = strdup ((pointer_description) ?
pointer_description : "");
new_hook_infolist->args_description = strdup ((args_description) ?
args_description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,807
|
hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
struct t_infolist *value;
/* make C compiler happy */
(void) plugin;
if (!infolist_name || !infolist_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFOLIST];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFOLIST(ptr_hook, infolist_name),
infolist_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFOLIST(ptr_hook, callback))
(ptr_hook->callback_data, infolist_name, pointer, arguments);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* infolist not found */
return NULL;
}
|
Exec Code
| 0
|
hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
struct t_infolist *value;
/* make C compiler happy */
(void) plugin;
if (!infolist_name || !infolist_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_INFOLIST];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_INFOLIST(ptr_hook, infolist_name),
infolist_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_INFOLIST(ptr_hook, callback))
(ptr_hook->callback_data, infolist_name, pointer, arguments);
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* infolist not found */
return NULL;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,808
|
hook_init ()
{
int type;
for (type = 0; type < HOOK_NUM_TYPES; type++)
{
weechat_hooks[type] = NULL;
last_weechat_hook[type] = NULL;
}
hook_last_system_time = time (NULL);
}
|
Exec Code
| 0
|
hook_init ()
{
int type;
for (type = 0; type < HOOK_NUM_TYPES; type++)
{
weechat_hooks[type] = NULL;
last_weechat_hook[type] = NULL;
}
hook_last_system_time = time (NULL);
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,809
|
hook_modifier (struct t_weechat_plugin *plugin, const char *modifier,
t_hook_callback_modifier *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_modifier *new_hook_modifier;
int priority;
const char *ptr_modifier;
if (!modifier || !modifier[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_modifier = malloc (sizeof (*new_hook_modifier));
if (!new_hook_modifier)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (modifier, &priority, &ptr_modifier);
hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority,
callback_data);
new_hook->hook_data = new_hook_modifier;
new_hook_modifier->callback = callback;
new_hook_modifier->modifier = strdup ((ptr_modifier) ? ptr_modifier : modifier);
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_modifier (struct t_weechat_plugin *plugin, const char *modifier,
t_hook_callback_modifier *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_modifier *new_hook_modifier;
int priority;
const char *ptr_modifier;
if (!modifier || !modifier[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_modifier = malloc (sizeof (*new_hook_modifier));
if (!new_hook_modifier)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (modifier, &priority, &ptr_modifier);
hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority,
callback_data);
new_hook->hook_data = new_hook_modifier;
new_hook_modifier->callback = callback;
new_hook_modifier->modifier = strdup ((ptr_modifier) ? ptr_modifier : modifier);
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,810
|
hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
const char *modifier_data, const char *string)
{
struct t_hook *ptr_hook, *next_hook;
char *new_msg, *message_modified;
/* make C compiler happy */
(void) plugin;
if (!modifier || !modifier[0])
return NULL;
new_msg = NULL;
message_modified = strdup (string);
if (!message_modified)
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier),
modifier) == 0))
{
ptr_hook->running = 1;
new_msg = (HOOK_MODIFIER(ptr_hook, callback))
(ptr_hook->callback_data, modifier, modifier_data,
message_modified);
ptr_hook->running = 0;
/* empty string returned => message dropped */
if (new_msg && !new_msg[0])
{
free (message_modified);
hook_exec_end ();
return new_msg;
}
/* new message => keep it as base for next modifier */
if (new_msg)
{
free (message_modified);
message_modified = new_msg;
}
}
ptr_hook = next_hook;
}
hook_exec_end ();
return message_modified;
}
|
Exec Code
| 0
|
hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
const char *modifier_data, const char *string)
{
struct t_hook *ptr_hook, *next_hook;
char *new_msg, *message_modified;
/* make C compiler happy */
(void) plugin;
if (!modifier || !modifier[0])
return NULL;
new_msg = NULL;
message_modified = strdup (string);
if (!message_modified)
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier),
modifier) == 0))
{
ptr_hook->running = 1;
new_msg = (HOOK_MODIFIER(ptr_hook, callback))
(ptr_hook->callback_data, modifier, modifier_data,
message_modified);
ptr_hook->running = 0;
/* empty string returned => message dropped */
if (new_msg && !new_msg[0])
{
free (message_modified);
hook_exec_end ();
return new_msg;
}
/* new message => keep it as base for next modifier */
if (new_msg)
{
free (message_modified);
message_modified = new_msg;
}
}
ptr_hook = next_hook;
}
hook_exec_end ();
return message_modified;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,811
|
hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
struct t_hook *ptr_hook, *next_hook;
char *prefix_no_color, *message_no_color;
int tags_match, tag_found, i, j;
if (!line->data->message || !line->data->message[0])
return;
prefix_no_color = (line->data->prefix) ?
gui_color_decode (line->data->prefix, NULL) : NULL;
message_no_color = gui_color_decode (line->data->message, NULL);
if (!message_no_color)
{
if (prefix_no_color)
free (prefix_no_color);
return;
}
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_PRINT];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (!HOOK_PRINT(ptr_hook, buffer)
|| (buffer == HOOK_PRINT(ptr_hook, buffer)))
&& (!HOOK_PRINT(ptr_hook, message)
|| !HOOK_PRINT(ptr_hook, message)[0]
|| string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message))
|| string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message))))
{
/* check if tags match */
if (HOOK_PRINT(ptr_hook, tags_array))
{
/* if there are tags in message printed */
if (line->data->tags_array)
{
tags_match = 1;
for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++)
{
/* search for tag in message */
tag_found = 0;
for (j = 0; j < line->data->tags_count; j++)
{
if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i],
line->data->tags_array[j]) == 0)
{
tag_found = 1;
break;
}
}
/* tag was asked by hook but not found in message? */
if (!tag_found)
{
tags_match = 0;
break;
}
}
}
else
tags_match = 0;
}
else
tags_match = 1;
/* run callback */
if (tags_match)
{
ptr_hook->running = 1;
(void) (HOOK_PRINT(ptr_hook, callback))
(ptr_hook->callback_data, buffer, line->data->date,
line->data->tags_count,
(const char **)line->data->tags_array,
(int)line->data->displayed, (int)line->data->highlight,
(HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix,
(HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message);
ptr_hook->running = 0;
}
}
ptr_hook = next_hook;
}
if (prefix_no_color)
free (prefix_no_color);
if (message_no_color)
free (message_no_color);
hook_exec_end ();
}
|
Exec Code
| 0
|
hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
struct t_hook *ptr_hook, *next_hook;
char *prefix_no_color, *message_no_color;
int tags_match, tag_found, i, j;
if (!line->data->message || !line->data->message[0])
return;
prefix_no_color = (line->data->prefix) ?
gui_color_decode (line->data->prefix, NULL) : NULL;
message_no_color = gui_color_decode (line->data->message, NULL);
if (!message_no_color)
{
if (prefix_no_color)
free (prefix_no_color);
return;
}
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_PRINT];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (!HOOK_PRINT(ptr_hook, buffer)
|| (buffer == HOOK_PRINT(ptr_hook, buffer)))
&& (!HOOK_PRINT(ptr_hook, message)
|| !HOOK_PRINT(ptr_hook, message)[0]
|| string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message))
|| string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message))))
{
/* check if tags match */
if (HOOK_PRINT(ptr_hook, tags_array))
{
/* if there are tags in message printed */
if (line->data->tags_array)
{
tags_match = 1;
for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++)
{
/* search for tag in message */
tag_found = 0;
for (j = 0; j < line->data->tags_count; j++)
{
if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i],
line->data->tags_array[j]) == 0)
{
tag_found = 1;
break;
}
}
/* tag was asked by hook but not found in message? */
if (!tag_found)
{
tags_match = 0;
break;
}
}
}
else
tags_match = 0;
}
else
tags_match = 1;
/* run callback */
if (tags_match)
{
ptr_hook->running = 1;
(void) (HOOK_PRINT(ptr_hook, callback))
(ptr_hook->callback_data, buffer, line->data->date,
line->data->tags_count,
(const char **)line->data->tags_array,
(int)line->data->displayed, (int)line->data->highlight,
(HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix,
(HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message);
ptr_hook->running = 0;
}
}
ptr_hook = next_hook;
}
if (prefix_no_color)
free (prefix_no_color);
if (message_no_color)
free (message_no_color);
hook_exec_end ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,812
|
hook_process (struct t_weechat_plugin *plugin,
const char *command, int timeout,
t_hook_callback_process *callback, void *callback_data)
{
return hook_process_hashtable (plugin, command, NULL, timeout,
callback, callback_data);
}
|
Exec Code
| 0
|
hook_process (struct t_weechat_plugin *plugin,
const char *command, int timeout,
t_hook_callback_process *callback, void *callback_data)
{
return hook_process_hashtable (plugin, command, NULL, timeout,
callback, callback_data);
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,813
|
string_convert_hex_chars (const char *string)
{
char *output, hex_str[8], *error;
int pos_output;
long number;
output = malloc (strlen (string) + 1);
if (output)
{
pos_output = 0;
while (string && string[0])
{
if (string[0] == '\\')
{
string++;
switch (string[0])
{
case '\\':
output[pos_output++] = '\\';
string++;
break;
case 'x':
case 'X':
if (isxdigit ((unsigned char)string[1])
&& isxdigit ((unsigned char)string[2]))
{
snprintf (hex_str, sizeof (hex_str),
"0x%c%c", string[1], string[2]);
number = strtol (hex_str, &error, 16);
if (error && !error[0])
{
output[pos_output++] = number;
string += 3;
}
else
{
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
break;
default:
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
break;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
}
output[pos_output] = '\0';
}
return output;
}
|
Exec Code
| 0
|
string_convert_hex_chars (const char *string)
{
char *output, hex_str[8], *error;
int pos_output;
long number;
output = malloc (strlen (string) + 1);
if (output)
{
pos_output = 0;
while (string && string[0])
{
if (string[0] == '\\')
{
string++;
switch (string[0])
{
case '\\':
output[pos_output++] = '\\';
string++;
break;
case 'x':
case 'X':
if (isxdigit ((unsigned char)string[1])
&& isxdigit ((unsigned char)string[2]))
{
snprintf (hex_str, sizeof (hex_str),
"0x%c%c", string[1], string[2]);
number = strtol (hex_str, &error, 16);
if (error && !error[0])
{
output[pos_output++] = number;
string += 3;
}
else
{
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
break;
default:
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
break;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
}
output[pos_output] = '\0';
}
return output;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,814
|
string_expand_home (const char *path)
{
char *ptr_home, *str;
int length;
if (!path)
return NULL;
if (!path[0] || (path[0] != '~')
|| ((path[1] && path[1] != DIR_SEPARATOR_CHAR)))
{
return strdup (path);
}
ptr_home = getenv ("HOME");
length = strlen (ptr_home) + strlen (path + 1) + 1;
str = malloc (length);
if (!str)
return strdup (path);
snprintf (str, length, "%s%s", ptr_home, path + 1);
return str;
}
|
Exec Code
| 0
|
string_expand_home (const char *path)
{
char *ptr_home, *str;
int length;
if (!path)
return NULL;
if (!path[0] || (path[0] != '~')
|| ((path[1] && path[1] != DIR_SEPARATOR_CHAR)))
{
return strdup (path);
}
ptr_home = getenv ("HOME");
length = strlen (ptr_home) + strlen (path + 1) + 1;
str = malloc (length);
if (!str)
return strdup (path);
snprintf (str, length, "%s%s", ptr_home, path + 1);
return str;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,815
|
string_has_highlight_regex (const char *string, const char *regex)
{
regex_t reg;
int rc;
if (!string || !regex || !regex[0])
return 0;
if (string_regcomp (®, regex, REG_EXTENDED | REG_ICASE) != 0)
return 0;
rc = string_has_highlight_regex_compiled (string, ®);
regfree (®);
return rc;
}
|
Exec Code
| 0
|
string_has_highlight_regex (const char *string, const char *regex)
{
regex_t reg;
int rc;
if (!string || !regex || !regex[0])
return 0;
if (string_regcomp (®, regex, REG_EXTENDED | REG_ICASE) != 0)
return 0;
rc = string_has_highlight_regex_compiled (string, ®);
regfree (®);
return rc;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,816
|
string_has_highlight_regex_compiled (const char *string, regex_t *regex)
{
int rc, startswith, endswith;
regmatch_t regex_match;
const char *match_pre;
if (!string || !regex)
return 0;
while (string && string[0])
{
rc = regexec (regex, string, 1, ®ex_match, 0);
if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo < 0))
break;
startswith = (regex_match.rm_so == 0);
if (!startswith)
{
match_pre = utf8_prev_char (string, string + regex_match.rm_so);
startswith = !string_is_word_char (match_pre);
}
endswith = 0;
if (startswith)
{
endswith = ((regex_match.rm_eo == (int)strlen (string))
|| !string_is_word_char (string + regex_match.rm_eo));
}
if (startswith && endswith)
return 1;
string += regex_match.rm_eo;
}
/* no highlight found */
return 0;
}
|
Exec Code
| 0
|
string_has_highlight_regex_compiled (const char *string, regex_t *regex)
{
int rc, startswith, endswith;
regmatch_t regex_match;
const char *match_pre;
if (!string || !regex)
return 0;
while (string && string[0])
{
rc = regexec (regex, string, 1, ®ex_match, 0);
if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo < 0))
break;
startswith = (regex_match.rm_so == 0);
if (!startswith)
{
match_pre = utf8_prev_char (string, string + regex_match.rm_so);
startswith = !string_is_word_char (match_pre);
}
endswith = 0;
if (startswith)
{
endswith = ((regex_match.rm_eo == (int)strlen (string))
|| !string_is_word_char (string + regex_match.rm_eo));
}
if (startswith && endswith)
return 1;
string += regex_match.rm_eo;
}
/* no highlight found */
return 0;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,817
|
string_is_word_char (const char *string)
{
wint_t c = utf8_wide_char (string);
if (c == WEOF)
return 0;
if (iswalnum (c))
return 1;
switch (c)
{
case '-':
case '_':
case '|':
return 1;
}
/* not a 'word char' */
return 0;
}
|
Exec Code
| 0
|
string_is_word_char (const char *string)
{
wint_t c = utf8_wide_char (string);
if (c == WEOF)
return 0;
if (iswalnum (c))
return 1;
switch (c)
{
case '-':
case '_':
case '|':
return 1;
}
/* not a 'word char' */
return 0;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,818
|
string_mask_to_regex (const char *mask)
{
char *result;
const char *ptr_mask;
int index_result;
char *regex_special_char = ".[]{}()?+";
if (!mask)
return NULL;
result = malloc ((strlen (mask) * 2) + 1);
if (!result)
return NULL;
result[0] = '\0';
index_result = 0;
ptr_mask = mask;
while (ptr_mask[0])
{
/* '*' in string ? then replace by '.*' */
if (ptr_mask[0] == '*')
{
result[index_result++] = '.';
result[index_result++] = '*';
}
/* special regex char in string ? escape it with '\' */
else if (strchr (regex_special_char, ptr_mask[0]))
{
result[index_result++] = '\\';
result[index_result++] = ptr_mask[0];
}
/* standard char, just copy it */
else
result[index_result++] = ptr_mask[0];
ptr_mask++;
}
/* add final '\0' */
result[index_result] = '\0';
return result;
}
|
Exec Code
| 0
|
string_mask_to_regex (const char *mask)
{
char *result;
const char *ptr_mask;
int index_result;
char *regex_special_char = ".[]{}()?+";
if (!mask)
return NULL;
result = malloc ((strlen (mask) * 2) + 1);
if (!result)
return NULL;
result[0] = '\0';
index_result = 0;
ptr_mask = mask;
while (ptr_mask[0])
{
/* '*' in string ? then replace by '.*' */
if (ptr_mask[0] == '*')
{
result[index_result++] = '.';
result[index_result++] = '*';
}
/* special regex char in string ? escape it with '\' */
else if (strchr (regex_special_char, ptr_mask[0]))
{
result[index_result++] = '\\';
result[index_result++] = ptr_mask[0];
}
/* standard char, just copy it */
else
result[index_result++] = ptr_mask[0];
ptr_mask++;
}
/* add final '\0' */
result[index_result] = '\0';
return result;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,819
|
string_match (const char *string, const char *mask, int case_sensitive)
{
char last, *mask2;
int len_string, len_mask, rc;
if (!mask || !mask[0])
return 0;
/* if mask is "*", then any string matches */
if (strcmp (mask, "*") == 0)
return 1;
len_string = strlen (string);
len_mask = strlen (mask);
last = mask[len_mask - 1];
/* mask begins with "*" */
if ((mask[0] == '*') && (last != '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* check if end of string matches */
if ((case_sensitive && (strcmp (string + len_string - (len_mask - 1),
mask + 1) == 0))
|| (!case_sensitive && (string_strcasecmp (string + len_string - (len_mask - 1),
mask + 1) == 0)))
return 1;
/* no match */
return 0;
}
/* mask ends with "*" */
if ((mask[0] != '*') && (last == '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* check if beginning of string matches */
if ((case_sensitive && (strncmp (string, mask, len_mask - 1) == 0))
|| (!case_sensitive && (string_strncasecmp (string,
mask,
len_mask - 1) == 0)))
return 1;
/* no match */
return 0;
}
/* mask begins and ends with "*" */
if ((mask[0] == '*') && (last == '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* keep only relevant chars in mask for searching string */
mask2 = string_strndup (mask + 1, len_mask - 2);
if (!mask2)
return 0;
/* search string */
rc = ((case_sensitive && strstr (string, mask2))
|| (!case_sensitive && string_strcasestr (string, mask2))) ?
1 : 0;
/* free and return */
free (mask2);
return rc;
}
/* no "*" at all, compare strings */
if ((case_sensitive && (strcmp (string, mask) == 0))
|| (!case_sensitive && (string_strcasecmp (string, mask) == 0)))
return 1;
/* no match */
return 0;
}
|
Exec Code
| 0
|
string_match (const char *string, const char *mask, int case_sensitive)
{
char last, *mask2;
int len_string, len_mask, rc;
if (!mask || !mask[0])
return 0;
/* if mask is "*", then any string matches */
if (strcmp (mask, "*") == 0)
return 1;
len_string = strlen (string);
len_mask = strlen (mask);
last = mask[len_mask - 1];
/* mask begins with "*" */
if ((mask[0] == '*') && (last != '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* check if end of string matches */
if ((case_sensitive && (strcmp (string + len_string - (len_mask - 1),
mask + 1) == 0))
|| (!case_sensitive && (string_strcasecmp (string + len_string - (len_mask - 1),
mask + 1) == 0)))
return 1;
/* no match */
return 0;
}
/* mask ends with "*" */
if ((mask[0] != '*') && (last == '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* check if beginning of string matches */
if ((case_sensitive && (strncmp (string, mask, len_mask - 1) == 0))
|| (!case_sensitive && (string_strncasecmp (string,
mask,
len_mask - 1) == 0)))
return 1;
/* no match */
return 0;
}
/* mask begins and ends with "*" */
if ((mask[0] == '*') && (last == '*'))
{
/* not enough chars in string to match */
if (len_string < len_mask - 1)
return 0;
/* keep only relevant chars in mask for searching string */
mask2 = string_strndup (mask + 1, len_mask - 2);
if (!mask2)
return 0;
/* search string */
rc = ((case_sensitive && strstr (string, mask2))
|| (!case_sensitive && string_strcasestr (string, mask2))) ?
1 : 0;
/* free and return */
free (mask2);
return rc;
}
/* no "*" at all, compare strings */
if ((case_sensitive && (strcmp (string, mask) == 0))
|| (!case_sensitive && (string_strcasecmp (string, mask) == 0)))
return 1;
/* no match */
return 0;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,820
|
string_regcomp (void *preg, const char *regex, int default_flags)
{
const char *ptr_regex;
int flags;
ptr_regex = string_regex_flags (regex, default_flags, &flags);
return regcomp ((regex_t *)preg, ptr_regex, flags);
}
|
Exec Code
| 0
|
string_regcomp (void *preg, const char *regex, int default_flags)
{
const char *ptr_regex;
int flags;
ptr_regex = string_regex_flags (regex, default_flags, &flags);
return regcomp ((regex_t *)preg, ptr_regex, flags);
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,821
|
string_regex_flags (const char *regex, int default_flags, int *flags)
{
const char *ptr_regex, *ptr_flags;
int set_flag, flag;
char *pos;
ptr_regex = regex;
if (flags)
*flags = default_flags;
while (strncmp (ptr_regex, "(?", 2) == 0)
{
pos = strchr (ptr_regex, ')');
if (!pos)
break;
if (!isalpha ((unsigned char)ptr_regex[2]) && (ptr_regex[2] != '-'))
break;
if (flags)
{
set_flag = 1;
for (ptr_flags = ptr_regex + 2; ptr_flags < pos; ptr_flags++)
{
flag = 0;
switch (ptr_flags[0])
{
case '-':
set_flag = 0;
break;
case 'e':
flag = REG_EXTENDED;
break;
case 'i':
flag = REG_ICASE;
break;
case 'n':
flag = REG_NEWLINE;
break;
case 's':
flag = REG_NOSUB;
break;
}
if (flag > 0)
{
if (set_flag)
*flags |= flag;
else
*flags &= ~flag;
}
}
}
ptr_regex = pos + 1;
}
return ptr_regex;
}
|
Exec Code
| 0
|
string_regex_flags (const char *regex, int default_flags, int *flags)
{
const char *ptr_regex, *ptr_flags;
int set_flag, flag;
char *pos;
ptr_regex = regex;
if (flags)
*flags = default_flags;
while (strncmp (ptr_regex, "(?", 2) == 0)
{
pos = strchr (ptr_regex, ')');
if (!pos)
break;
if (!isalpha ((unsigned char)ptr_regex[2]) && (ptr_regex[2] != '-'))
break;
if (flags)
{
set_flag = 1;
for (ptr_flags = ptr_regex + 2; ptr_flags < pos; ptr_flags++)
{
flag = 0;
switch (ptr_flags[0])
{
case '-':
set_flag = 0;
break;
case 'e':
flag = REG_EXTENDED;
break;
case 'i':
flag = REG_ICASE;
break;
case 'n':
flag = REG_NEWLINE;
break;
case 's':
flag = REG_NOSUB;
break;
}
if (flag > 0)
{
if (set_flag)
*flags |= flag;
else
*flags &= ~flag;
}
}
}
ptr_regex = pos + 1;
}
return ptr_regex;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,822
|
string_remove_quotes (const char *string, const char *quotes)
{
int length;
const char *pos_start, *pos_end;
if (!string || !quotes)
return NULL;
if (!string[0])
return strdup (string);
pos_start = string;
while (pos_start[0] == ' ')
{
pos_start++;
}
length = strlen (string);
pos_end = string + length - 1;
while ((pos_end[0] == ' ') && (pos_end > pos_start))
{
pos_end--;
}
if (!pos_start[0] || !pos_end[0] || (pos_end <= pos_start))
return strdup (string);
if (strchr (quotes, pos_start[0]) && (pos_end[0] == pos_start[0]))
{
if (pos_end == (pos_start + 1))
return strdup ("");
return string_strndup (pos_start + 1, pos_end - pos_start - 1);
}
return strdup (string);
}
|
Exec Code
| 0
|
string_remove_quotes (const char *string, const char *quotes)
{
int length;
const char *pos_start, *pos_end;
if (!string || !quotes)
return NULL;
if (!string[0])
return strdup (string);
pos_start = string;
while (pos_start[0] == ' ')
{
pos_start++;
}
length = strlen (string);
pos_end = string + length - 1;
while ((pos_end[0] == ' ') && (pos_end > pos_start))
{
pos_end--;
}
if (!pos_start[0] || !pos_end[0] || (pos_end <= pos_start))
return strdup (string);
if (strchr (quotes, pos_start[0]) && (pos_end[0] == pos_start[0]))
{
if (pos_end == (pos_start + 1))
return strdup ("");
return string_strndup (pos_start + 1, pos_end - pos_start - 1);
}
return strdup (string);
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,823
|
string_replace (const char *string, const char *search, const char *replace)
{
const char *pos;
char *new_string;
int length1, length2, length_new, count;
if (!string || !search || !replace)
return NULL;
length1 = strlen (search);
length2 = strlen (replace);
/* count number of strings to replace */
count = 0;
pos = string;
while (pos && pos[0] && (pos = strstr (pos, search)))
{
count++;
pos += length1;
}
/* easy: no string to replace! */
if (count == 0)
return strdup (string);
/* compute needed memory for new string */
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
/* allocate new string */
new_string = malloc (length_new);
if (!new_string)
return strdup (string);
/* replace all occurrences */
new_string[0] = '\0';
while (string && string[0])
{
pos = strstr (string, search);
if (pos)
{
strncat (new_string, string, pos - string);
strcat (new_string, replace);
pos += length1;
}
else
strcat (new_string, string);
string = pos;
}
return new_string;
}
|
Exec Code
| 0
|
string_replace (const char *string, const char *search, const char *replace)
{
const char *pos;
char *new_string;
int length1, length2, length_new, count;
if (!string || !search || !replace)
return NULL;
length1 = strlen (search);
length2 = strlen (replace);
/* count number of strings to replace */
count = 0;
pos = string;
while (pos && pos[0] && (pos = strstr (pos, search)))
{
count++;
pos += length1;
}
/* easy: no string to replace! */
if (count == 0)
return strdup (string);
/* compute needed memory for new string */
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
/* allocate new string */
new_string = malloc (length_new);
if (!new_string)
return strdup (string);
/* replace all occurrences */
new_string[0] = '\0';
while (string && string[0])
{
pos = strstr (string, search);
if (pos)
{
strncat (new_string, string, pos - string);
strcat (new_string, replace);
pos += length1;
}
else
strcat (new_string, string);
string = pos;
}
return new_string;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,824
|
string_split (const char *string, const char *separators, int keep_eol,
int num_items_max, int *num_items)
{
int i, j, n_items;
char *string2, **array;
char *ptr, *ptr1, *ptr2;
if (num_items != NULL)
*num_items = 0;
if (!string || !string[0] || !separators || !separators[0])
return NULL;
string2 = string_strip (string, 1, (keep_eol == 2) ? 0 : 1, separators);
if (!string2 || !string2[0])
return NULL;
/* calculate number of items */
ptr = string2;
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
while (ptr[0] && (strchr (separators, ptr[0]) != NULL))
{
ptr++;
}
i++;
}
n_items = i;
if ((num_items_max != 0) && (n_items > num_items_max))
n_items = num_items_max;
array = malloc ((n_items + 1) * sizeof (array[0]));
if (!array)
return NULL;
ptr1 = string2;
for (i = 0; i < n_items; i++)
{
while (ptr1[0] && (strchr (separators, ptr1[0]) != NULL))
{
ptr1++;
}
if (i == (n_items - 1))
{
ptr2 = strpbrk (ptr1, separators);
if (!ptr2)
ptr2 = strchr (ptr1, '\0');
}
else
{
if ((ptr2 = strpbrk (ptr1, separators)) == NULL)
{
if ((ptr2 = strchr (ptr1, '\r')) == NULL)
{
if ((ptr2 = strchr (ptr1, '\n')) == NULL)
{
ptr2 = strchr (ptr1, '\0');
}
}
}
}
if ((ptr1 == NULL) || (ptr2 == NULL))
{
array[i] = NULL;
}
else
{
if (ptr2 - ptr1 > 0)
{
if (keep_eol)
{
array[i] = strdup (ptr1);
if (!array[i])
{
for (j = 0; j < n_items; j++)
{
if (array[j])
free (array[j]);
}
free (array);
free (string2);
return NULL;
}
}
else
{
array[i] = malloc (ptr2 - ptr1 + 1);
if (!array[i])
{
for (j = 0; j < n_items; j++)
{
if (array[j])
free (array[j]);
}
free (array);
free (string2);
return NULL;
}
strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
}
ptr1 = ++ptr2;
}
else
{
array[i] = NULL;
}
}
}
array[i] = NULL;
if (num_items != NULL)
*num_items = i;
free (string2);
return array;
}
|
Exec Code
| 0
|
string_split (const char *string, const char *separators, int keep_eol,
int num_items_max, int *num_items)
{
int i, j, n_items;
char *string2, **array;
char *ptr, *ptr1, *ptr2;
if (num_items != NULL)
*num_items = 0;
if (!string || !string[0] || !separators || !separators[0])
return NULL;
string2 = string_strip (string, 1, (keep_eol == 2) ? 0 : 1, separators);
if (!string2 || !string2[0])
return NULL;
/* calculate number of items */
ptr = string2;
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
while (ptr[0] && (strchr (separators, ptr[0]) != NULL))
{
ptr++;
}
i++;
}
n_items = i;
if ((num_items_max != 0) && (n_items > num_items_max))
n_items = num_items_max;
array = malloc ((n_items + 1) * sizeof (array[0]));
if (!array)
return NULL;
ptr1 = string2;
for (i = 0; i < n_items; i++)
{
while (ptr1[0] && (strchr (separators, ptr1[0]) != NULL))
{
ptr1++;
}
if (i == (n_items - 1))
{
ptr2 = strpbrk (ptr1, separators);
if (!ptr2)
ptr2 = strchr (ptr1, '\0');
}
else
{
if ((ptr2 = strpbrk (ptr1, separators)) == NULL)
{
if ((ptr2 = strchr (ptr1, '\r')) == NULL)
{
if ((ptr2 = strchr (ptr1, '\n')) == NULL)
{
ptr2 = strchr (ptr1, '\0');
}
}
}
}
if ((ptr1 == NULL) || (ptr2 == NULL))
{
array[i] = NULL;
}
else
{
if (ptr2 - ptr1 > 0)
{
if (keep_eol)
{
array[i] = strdup (ptr1);
if (!array[i])
{
for (j = 0; j < n_items; j++)
{
if (array[j])
free (array[j]);
}
free (array);
free (string2);
return NULL;
}
}
else
{
array[i] = malloc (ptr2 - ptr1 + 1);
if (!array[i])
{
for (j = 0; j < n_items; j++)
{
if (array[j])
free (array[j]);
}
free (array);
free (string2);
return NULL;
}
strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
}
ptr1 = ++ptr2;
}
else
{
array[i] = NULL;
}
}
}
array[i] = NULL;
if (num_items != NULL)
*num_items = i;
free (string2);
return array;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,825
|
string_strcasecmp (const char *string1, const char *string2)
{
int diff;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
while (string1[0] && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
}
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
|
Exec Code
| 0
|
string_strcasecmp (const char *string1, const char *string2)
{
int diff;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
while (string1[0] && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
}
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,826
|
string_strcasestr (const char *string, const char *search)
{
int length_search;
length_search = utf8_strlen (search);
if (!string || !search || (length_search == 0))
return NULL;
while (string[0])
{
if (string_strncasecmp (string, search, length_search) == 0)
return (char *)string;
string = utf8_next_char (string);
}
return NULL;
}
|
Exec Code
| 0
|
string_strcasestr (const char *string, const char *search)
{
int length_search;
length_search = utf8_strlen (search);
if (!string || !search || (length_search == 0))
return NULL;
while (string[0])
{
if (string_strncasecmp (string, search, length_search) == 0)
return (char *)string;
string = utf8_next_char (string);
}
return NULL;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,827
|
string_strcmp_ignore_chars (const char *string1, const char *string2,
const char *chars_ignored, int case_sensitive)
{
int diff;
if (!string1 && !string2)
return 0;
if (!string1 && string2)
return -1;
if (string1 && !string2)
return 1;
while (string1 && string1[0] && string2 && string2[0])
{
/* skip ignored chars */
while (string1 && string1[0] && strchr (chars_ignored, string1[0]))
{
string1 = utf8_next_char (string1);
}
while (string2 && string2[0] && strchr (chars_ignored, string2[0]))
{
string2 = utf8_next_char (string2);
}
/* end of one (or both) string(s) ? */
if ((!string1 || !string1[0]) && (!string2 || !string2[0]))
return 0;
if ((!string1 || !string1[0]) && string2 && string2[0])
return -1;
if (string1 && string1[0] && (!string2 || !string2[0]))
return 1;
/* look at diff */
diff = (case_sensitive) ?
(int)string1[0] - (int)string2[0] : utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
/* skip ignored chars */
while (string1 && string1[0] && strchr (chars_ignored, string1[0]))
{
string1 = utf8_next_char (string1);
}
while (string2 && string2[0] && strchr (chars_ignored, string2[0]))
{
string2 = utf8_next_char (string2);
}
}
if ((!string1 || !string1[0]) && string2 && string2[0])
return -1;
if (string1 && string1[0] && (!string2 || !string2[0]))
return 1;
return 0;
}
|
Exec Code
| 0
|
string_strcmp_ignore_chars (const char *string1, const char *string2,
const char *chars_ignored, int case_sensitive)
{
int diff;
if (!string1 && !string2)
return 0;
if (!string1 && string2)
return -1;
if (string1 && !string2)
return 1;
while (string1 && string1[0] && string2 && string2[0])
{
/* skip ignored chars */
while (string1 && string1[0] && strchr (chars_ignored, string1[0]))
{
string1 = utf8_next_char (string1);
}
while (string2 && string2[0] && strchr (chars_ignored, string2[0]))
{
string2 = utf8_next_char (string2);
}
/* end of one (or both) string(s) ? */
if ((!string1 || !string1[0]) && (!string2 || !string2[0]))
return 0;
if ((!string1 || !string1[0]) && string2 && string2[0])
return -1;
if (string1 && string1[0] && (!string2 || !string2[0]))
return 1;
/* look at diff */
diff = (case_sensitive) ?
(int)string1[0] - (int)string2[0] : utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
/* skip ignored chars */
while (string1 && string1[0] && strchr (chars_ignored, string1[0]))
{
string1 = utf8_next_char (string1);
}
while (string2 && string2[0] && strchr (chars_ignored, string2[0]))
{
string2 = utf8_next_char (string2);
}
}
if ((!string1 || !string1[0]) && string2 && string2[0])
return -1;
if (string1 && string1[0] && (!string2 || !string2[0]))
return 1;
return 0;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,828
|
string_strip (const char *string, int left, int right, const char *chars)
{
const char *ptr_start, *ptr_end;
if (!string)
return NULL;
if (!string[0])
return strdup (string);
ptr_start = string;
ptr_end = string + strlen (string) - 1;
if (left)
{
while (ptr_start[0] && strchr (chars, ptr_start[0]))
{
ptr_start++;
}
if (!ptr_start[0])
return strdup (ptr_start);
}
if (right)
{
while ((ptr_end >= ptr_start) && strchr (chars, ptr_end[0]))
{
ptr_end--;
}
if (ptr_end < ptr_start)
return strdup ("");
}
return string_strndup (ptr_start, ptr_end - ptr_start + 1);
}
|
Exec Code
| 0
|
string_strip (const char *string, int left, int right, const char *chars)
{
const char *ptr_start, *ptr_end;
if (!string)
return NULL;
if (!string[0])
return strdup (string);
ptr_start = string;
ptr_end = string + strlen (string) - 1;
if (left)
{
while (ptr_start[0] && strchr (chars, ptr_start[0]))
{
ptr_start++;
}
if (!ptr_start[0])
return strdup (ptr_start);
}
if (right)
{
while ((ptr_end >= ptr_start) && strchr (chars, ptr_end[0]))
{
ptr_end--;
}
if (ptr_end < ptr_start)
return strdup ("");
}
return string_strndup (ptr_start, ptr_end - ptr_start + 1);
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,829
|
string_strncasecmp (const char *string1, const char *string2, int max)
{
int count, diff;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
count = 0;
while ((count < max) && string1[0] && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
count++;
}
if (count >= max)
return 0;
else
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
|
Exec Code
| 0
|
string_strncasecmp (const char *string1, const char *string2, int max)
{
int count, diff;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
count = 0;
while ((count < max) && string1[0] && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
count++;
}
if (count >= max)
return 0;
else
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,830
|
string_strndup (const char *string, int length)
{
char *result;
if ((int)strlen (string) < length)
return strdup (string);
result = malloc (length + 1);
if (!result)
return NULL;
memcpy (result, string, length);
result[length] = '\0';
return result;
}
|
Exec Code
| 0
|
string_strndup (const char *string, int length)
{
char *result;
if ((int)strlen (string) < length)
return strdup (string);
result = malloc (length + 1);
if (!result)
return NULL;
memcpy (result, string, length);
result[length] = '\0';
return result;
}
|
@@ -1138,6 +1138,196 @@ string_split (const char *string, const char *separators, int keep_eol,
}
/*
+ * string_split_shell: split a string like the shell does for a command with
+ * arguments.
+ * Note: result must be freed with string_free_split.
+ * This function is a C conversion of python class "shlex"
+ * (file: Lib/shlex.py in python repository)
+ * Doc: http://docs.python.org/3/library/shlex.html
+ * Copyrights in shlex.py:
+ * Module and documentation by Eric S. Raymond, 21 Dec 1998
+ * Input stacking and error message cleanup added by ESR, March 2000
+ * push_source() and pop_source() made explicit by ESR, January 2001.
+ * Posix compliance, split(), string arguments, and
+ * iterator interface by Gustavo Niemeyer, April 2003.
+ */
+
+char **
+string_split_shell (const char *string)
+{
+ int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
+ char *string2, *temp, **args, **args2, state, escapedstate;
+ char *ptr_string, *ptr_next, saved_char;
+
+ if (!string)
+ return NULL;
+
+ string2 = strdup (string);
+ if (!string2)
+ return NULL;
+
+ /*
+ * prepare "args" with one pointer to NULL, the "args" will be reallocated
+ * later, each time a new argument is added
+ */
+ num_args = 0;
+ args = malloc ((num_args + 1) * sizeof (args[0]));
+ if (!args)
+ {
+ free (string2);
+ return NULL;
+ }
+ args[0] = NULL;
+
+ /* prepare a temp string for working (adding chars one by one) */
+ temp = malloc ((2 * strlen (string)) + 1);
+ if (!temp)
+ {
+ free (string2);
+ free (args);
+ return NULL;
+ }
+ temp[0] = '\0';
+ temp_len = 0;
+
+ state = ' ';
+ escapedstate = ' ';
+ quoted = 0;
+ ptr_string = string2;
+ while (ptr_string[0])
+ {
+ add_char_to_temp = 0;
+ add_temp_to_args = 0;
+ ptr_next = utf8_next_char (ptr_string);
+ saved_char = ptr_next[0];
+ ptr_next[0] = '\0';
+ if (state == ' ')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ state = 'a';
+ }
+ }
+ else if ((state == '\'') || (state == '"'))
+ {
+ quoted = 1;
+ if (ptr_string[0] == state)
+ {
+ state = 'a';
+ }
+ else if ((state == '"') && (ptr_string[0] == '\\'))
+ {
+ escapedstate = state;
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ else if (state == '\\')
+ {
+ if (((escapedstate == '\'') || (escapedstate == '"'))
+ && (ptr_string[0] != state) && (ptr_string[0] != escapedstate))
+ {
+ temp[temp_len] = state;
+ temp_len++;
+ temp[temp_len] = '\0';
+ }
+ add_char_to_temp = 1;
+ state = escapedstate;
+ }
+ else if (state == 'a')
+ {
+ if ((ptr_string[0] == ' ') || (ptr_string[0] == '\t')
+ || (ptr_string[0] == '\r') || (ptr_string[0] == '\n'))
+ {
+ state = ' ';
+ if (temp[0] || quoted)
+ add_temp_to_args = 1;
+ }
+ else if (ptr_string[0] == '\\')
+ {
+ escapedstate = 'a';
+ state = ptr_string[0];
+ }
+ else if ((ptr_string[0] == '\'') || (ptr_string[0] == '"'))
+ {
+ state = ptr_string[0];
+ }
+ else
+ {
+ add_char_to_temp = 1;
+ }
+ }
+ if (add_char_to_temp)
+ {
+ memcpy (temp + temp_len, ptr_string, ptr_next - ptr_string);
+ temp_len += (ptr_next - ptr_string);
+ temp[temp_len] = '\0';
+ }
+ if (add_temp_to_args)
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ escapedstate = ' ';
+ quoted = 0;
+ }
+ ptr_next[0] = saved_char;
+ ptr_string = ptr_next;
+ }
+
+ if (temp[0] || (state != ' '))
+ {
+ num_args++;
+ args2 = realloc (args, (num_args + 1) * sizeof (args[0]));
+ if (!args2)
+ {
+ free (string2);
+ free (temp);
+ return args;
+ }
+ args = args2;
+ args[num_args - 1] = strdup (temp);
+ args[num_args] = NULL;
+ temp[0] = '\0';
+ temp_len = 0;
+ }
+
+ free (string2);
+ free (temp);
+
+ return args;
+}
+
+/*
* string_free_split: free a split string
*/
|
CWE-20
| null | null |
5,831
|
T1_ToBool( PS_Parser parser )
{
return ps_tobool( &parser->cursor, parser->limit );
}
|
Overflow
| 0
|
T1_ToBool( PS_Parser parser )
{
return ps_tobool( &parser->cursor, parser->limit );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,832
|
T1_ToString( PS_Parser parser )
{
return ps_tostring( &parser->cursor, parser->limit, parser->memory );
}
|
Overflow
| 0
|
T1_ToString( PS_Parser parser )
{
return ps_tostring( &parser->cursor, parser->limit, parser->memory );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,833
|
ps_parser_done( PS_Parser parser )
{
FT_UNUSED( parser );
}
|
Overflow
| 0
|
ps_parser_done( PS_Parser parser )
{
FT_UNUSED( parser );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,834
|
ps_parser_init( PS_Parser parser,
FT_Byte* base,
FT_Byte* limit,
FT_Memory memory )
{
parser->error = FT_Err_Ok;
parser->base = base;
parser->limit = limit;
parser->cursor = base;
parser->memory = memory;
parser->funcs = ps_parser_funcs;
}
|
Overflow
| 0
|
ps_parser_init( PS_Parser parser,
FT_Byte* base,
FT_Byte* limit,
FT_Memory memory )
{
parser->error = FT_Err_Ok;
parser->base = base;
parser->limit = limit;
parser->cursor = base;
parser->memory = memory;
parser->funcs = ps_parser_funcs;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,835
|
ps_parser_load_field( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags )
{
T1_TokenRec token;
FT_Byte* cur;
FT_Byte* limit;
FT_UInt count;
FT_UInt idx;
FT_Error error;
T1_FieldType type;
/* this also skips leading whitespace */
ps_parser_to_token( parser, &token );
if ( !token.type )
goto Fail;
count = 1;
idx = 0;
cur = token.start;
limit = token.limit;
type = field->type;
/* we must detect arrays in /FontBBox */
if ( type == T1_FIELD_TYPE_BBOX )
{
T1_TokenRec token2;
FT_Byte* old_cur = parser->cursor;
FT_Byte* old_limit = parser->limit;
/* don't include delimiters */
parser->cursor = token.start + 1;
parser->limit = token.limit - 1;
ps_parser_to_token( parser, &token2 );
parser->cursor = old_cur;
parser->limit = old_limit;
if ( token2.type == T1_TOKEN_TYPE_ARRAY )
{
type = T1_FIELD_TYPE_MM_BBOX;
goto FieldArray;
}
}
else if ( token.type == T1_TOKEN_TYPE_ARRAY )
{
count = max_objects;
FieldArray:
/* if this is an array and we have no blend, an error occurs */
if ( max_objects == 0 )
goto Fail;
idx = 1;
/* don't include delimiters */
cur++;
limit--;
}
for ( ; count > 0; count--, idx++ )
{
FT_Byte* q = (FT_Byte*)objects[idx] + field->offset;
FT_Long val;
FT_String* string = NULL;
skip_spaces( &cur, limit );
switch ( type )
{
case T1_FIELD_TYPE_BOOL:
val = ps_tobool( &cur, limit );
goto Store_Integer;
case T1_FIELD_TYPE_FIXED:
val = PS_Conv_ToFixed( &cur, limit, 0 );
goto Store_Integer;
case T1_FIELD_TYPE_FIXED_1000:
val = PS_Conv_ToFixed( &cur, limit, 3 );
goto Store_Integer;
case T1_FIELD_TYPE_INTEGER:
val = PS_Conv_ToInt( &cur, limit );
/* fall through */
Store_Integer:
switch ( field->size )
{
case (8 / FT_CHAR_BIT):
*(FT_Byte*)q = (FT_Byte)val;
break;
case (16 / FT_CHAR_BIT):
*(FT_UShort*)q = (FT_UShort)val;
break;
case (32 / FT_CHAR_BIT):
*(FT_UInt32*)q = (FT_UInt32)val;
break;
default: /* for 64-bit systems */
*(FT_Long*)q = val;
}
break;
case T1_FIELD_TYPE_STRING:
case T1_FIELD_TYPE_KEY:
{
FT_Memory memory = parser->memory;
FT_UInt len = (FT_UInt)( limit - cur );
if ( cur >= limit )
break;
/* we allow both a string or a name */
/* for cases like /FontName (foo) def */
if ( token.type == T1_TOKEN_TYPE_KEY )
{
/* don't include leading `/' */
len--;
cur++;
}
else if ( token.type == T1_TOKEN_TYPE_STRING )
{
/* don't include delimiting parentheses */
/* XXX we don't handle <<...>> here */
/* XXX should we convert octal escapes? */
/* if so, what encoding should we use? */
cur++;
len -= 2;
}
else
{
FT_ERROR(( "ps_parser_load_field:"
" expected a name or string\n"
" "
" but found token of type %d instead\n",
token.type ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* for this to work (FT_String**)q must have been */
/* initialized to NULL */
if ( *(FT_String**)q )
{
FT_TRACE0(( "ps_parser_load_field: overwriting field %s\n",
field->ident ));
FT_FREE( *(FT_String**)q );
*(FT_String**)q = NULL;
}
if ( FT_ALLOC( string, len + 1 ) )
goto Exit;
FT_MEM_COPY( string, cur, len );
string[len] = 0;
*(FT_String**)q = string;
}
break;
case T1_FIELD_TYPE_BBOX:
{
FT_Fixed temp[4];
FT_BBox* bbox = (FT_BBox*)q;
FT_Int result;
result = ps_tofixedarray( &cur, limit, 4, temp, 0 );
if ( result < 4 )
{
FT_ERROR(( "ps_parser_load_field:"
" expected four integers in bounding box\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
bbox->xMin = FT_RoundFix( temp[0] );
bbox->yMin = FT_RoundFix( temp[1] );
bbox->xMax = FT_RoundFix( temp[2] );
bbox->yMax = FT_RoundFix( temp[3] );
}
break;
case T1_FIELD_TYPE_MM_BBOX:
{
FT_Memory memory = parser->memory;
FT_Fixed* temp = NULL;
FT_Int result;
FT_UInt i;
if ( FT_NEW_ARRAY( temp, max_objects * 4 ) )
goto Exit;
for ( i = 0; i < 4; i++ )
{
result = ps_tofixedarray( &cur, limit, (FT_Int)max_objects,
temp + i * max_objects, 0 );
if ( result < 0 || (FT_UInt)result < max_objects )
{
FT_ERROR(( "ps_parser_load_field:"
" expected %d integer%s in the %s subarray\n"
" "
" of /FontBBox in the /Blend dictionary\n",
max_objects, max_objects > 1 ? "s" : "",
i == 0 ? "first"
: ( i == 1 ? "second"
: ( i == 2 ? "third"
: "fourth" ) ) ));
error = FT_THROW( Invalid_File_Format );
FT_FREE( temp );
goto Exit;
}
skip_spaces( &cur, limit );
}
for ( i = 0; i < max_objects; i++ )
{
FT_BBox* bbox = (FT_BBox*)objects[i];
bbox->xMin = FT_RoundFix( temp[i ] );
bbox->yMin = FT_RoundFix( temp[i + max_objects] );
bbox->xMax = FT_RoundFix( temp[i + 2 * max_objects] );
bbox->yMax = FT_RoundFix( temp[i + 3 * max_objects] );
}
FT_FREE( temp );
}
break;
default:
/* an error occurred */
goto Fail;
}
}
#if 0 /* obsolete -- keep for reference */
if ( pflags )
*pflags |= 1L << field->flag_bit;
#else
FT_UNUSED( pflags );
#endif
error = FT_Err_Ok;
Exit:
return error;
Fail:
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
|
Overflow
| 0
|
ps_parser_load_field( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags )
{
T1_TokenRec token;
FT_Byte* cur;
FT_Byte* limit;
FT_UInt count;
FT_UInt idx;
FT_Error error;
T1_FieldType type;
/* this also skips leading whitespace */
ps_parser_to_token( parser, &token );
if ( !token.type )
goto Fail;
count = 1;
idx = 0;
cur = token.start;
limit = token.limit;
type = field->type;
/* we must detect arrays in /FontBBox */
if ( type == T1_FIELD_TYPE_BBOX )
{
T1_TokenRec token2;
FT_Byte* old_cur = parser->cursor;
FT_Byte* old_limit = parser->limit;
/* don't include delimiters */
parser->cursor = token.start + 1;
parser->limit = token.limit - 1;
ps_parser_to_token( parser, &token2 );
parser->cursor = old_cur;
parser->limit = old_limit;
if ( token2.type == T1_TOKEN_TYPE_ARRAY )
{
type = T1_FIELD_TYPE_MM_BBOX;
goto FieldArray;
}
}
else if ( token.type == T1_TOKEN_TYPE_ARRAY )
{
count = max_objects;
FieldArray:
/* if this is an array and we have no blend, an error occurs */
if ( max_objects == 0 )
goto Fail;
idx = 1;
/* don't include delimiters */
cur++;
limit--;
}
for ( ; count > 0; count--, idx++ )
{
FT_Byte* q = (FT_Byte*)objects[idx] + field->offset;
FT_Long val;
FT_String* string = NULL;
skip_spaces( &cur, limit );
switch ( type )
{
case T1_FIELD_TYPE_BOOL:
val = ps_tobool( &cur, limit );
goto Store_Integer;
case T1_FIELD_TYPE_FIXED:
val = PS_Conv_ToFixed( &cur, limit, 0 );
goto Store_Integer;
case T1_FIELD_TYPE_FIXED_1000:
val = PS_Conv_ToFixed( &cur, limit, 3 );
goto Store_Integer;
case T1_FIELD_TYPE_INTEGER:
val = PS_Conv_ToInt( &cur, limit );
/* fall through */
Store_Integer:
switch ( field->size )
{
case (8 / FT_CHAR_BIT):
*(FT_Byte*)q = (FT_Byte)val;
break;
case (16 / FT_CHAR_BIT):
*(FT_UShort*)q = (FT_UShort)val;
break;
case (32 / FT_CHAR_BIT):
*(FT_UInt32*)q = (FT_UInt32)val;
break;
default: /* for 64-bit systems */
*(FT_Long*)q = val;
}
break;
case T1_FIELD_TYPE_STRING:
case T1_FIELD_TYPE_KEY:
{
FT_Memory memory = parser->memory;
FT_UInt len = (FT_UInt)( limit - cur );
if ( cur >= limit )
break;
/* we allow both a string or a name */
/* for cases like /FontName (foo) def */
if ( token.type == T1_TOKEN_TYPE_KEY )
{
/* don't include leading `/' */
len--;
cur++;
}
else if ( token.type == T1_TOKEN_TYPE_STRING )
{
/* don't include delimiting parentheses */
/* XXX we don't handle <<...>> here */
/* XXX should we convert octal escapes? */
/* if so, what encoding should we use? */
cur++;
len -= 2;
}
else
{
FT_ERROR(( "ps_parser_load_field:"
" expected a name or string\n"
" "
" but found token of type %d instead\n",
token.type ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* for this to work (FT_String**)q must have been */
/* initialized to NULL */
if ( *(FT_String**)q )
{
FT_TRACE0(( "ps_parser_load_field: overwriting field %s\n",
field->ident ));
FT_FREE( *(FT_String**)q );
*(FT_String**)q = NULL;
}
if ( FT_ALLOC( string, len + 1 ) )
goto Exit;
FT_MEM_COPY( string, cur, len );
string[len] = 0;
*(FT_String**)q = string;
}
break;
case T1_FIELD_TYPE_BBOX:
{
FT_Fixed temp[4];
FT_BBox* bbox = (FT_BBox*)q;
FT_Int result;
result = ps_tofixedarray( &cur, limit, 4, temp, 0 );
if ( result < 4 )
{
FT_ERROR(( "ps_parser_load_field:"
" expected four integers in bounding box\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
bbox->xMin = FT_RoundFix( temp[0] );
bbox->yMin = FT_RoundFix( temp[1] );
bbox->xMax = FT_RoundFix( temp[2] );
bbox->yMax = FT_RoundFix( temp[3] );
}
break;
case T1_FIELD_TYPE_MM_BBOX:
{
FT_Memory memory = parser->memory;
FT_Fixed* temp = NULL;
FT_Int result;
FT_UInt i;
if ( FT_NEW_ARRAY( temp, max_objects * 4 ) )
goto Exit;
for ( i = 0; i < 4; i++ )
{
result = ps_tofixedarray( &cur, limit, (FT_Int)max_objects,
temp + i * max_objects, 0 );
if ( result < 0 || (FT_UInt)result < max_objects )
{
FT_ERROR(( "ps_parser_load_field:"
" expected %d integer%s in the %s subarray\n"
" "
" of /FontBBox in the /Blend dictionary\n",
max_objects, max_objects > 1 ? "s" : "",
i == 0 ? "first"
: ( i == 1 ? "second"
: ( i == 2 ? "third"
: "fourth" ) ) ));
error = FT_THROW( Invalid_File_Format );
FT_FREE( temp );
goto Exit;
}
skip_spaces( &cur, limit );
}
for ( i = 0; i < max_objects; i++ )
{
FT_BBox* bbox = (FT_BBox*)objects[i];
bbox->xMin = FT_RoundFix( temp[i ] );
bbox->yMin = FT_RoundFix( temp[i + max_objects] );
bbox->xMax = FT_RoundFix( temp[i + 2 * max_objects] );
bbox->yMax = FT_RoundFix( temp[i + 3 * max_objects] );
}
FT_FREE( temp );
}
break;
default:
/* an error occurred */
goto Fail;
}
}
#if 0 /* obsolete -- keep for reference */
if ( pflags )
*pflags |= 1L << field->flag_bit;
#else
FT_UNUSED( pflags );
#endif
error = FT_Err_Ok;
Exit:
return error;
Fail:
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,836
|
ps_parser_load_field_table( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags )
{
T1_TokenRec elements[T1_MAX_TABLE_ELEMENTS];
T1_Token token;
FT_Int num_elements;
FT_Error error = FT_Err_Ok;
FT_Byte* old_cursor;
FT_Byte* old_limit;
T1_FieldRec fieldrec = *(T1_Field)field;
fieldrec.type = T1_FIELD_TYPE_INTEGER;
if ( field->type == T1_FIELD_TYPE_FIXED_ARRAY ||
field->type == T1_FIELD_TYPE_BBOX )
fieldrec.type = T1_FIELD_TYPE_FIXED;
ps_parser_to_token_array( parser, elements,
T1_MAX_TABLE_ELEMENTS, &num_elements );
if ( num_elements < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( (FT_UInt)num_elements > field->array_max )
num_elements = (FT_Int)field->array_max;
old_cursor = parser->cursor;
old_limit = parser->limit;
/* we store the elements count if necessary; */
/* we further assume that `count_offset' can't be zero */
if ( field->type != T1_FIELD_TYPE_BBOX && field->count_offset != 0 )
*(FT_Byte*)( (FT_Byte*)objects[0] + field->count_offset ) =
(FT_Byte)num_elements;
/* we now load each element, adjusting the field.offset on each one */
token = elements;
for ( ; num_elements > 0; num_elements--, token++ )
{
parser->cursor = token->start;
parser->limit = token->limit;
error = ps_parser_load_field( parser,
&fieldrec,
objects,
max_objects,
0 );
if ( error )
break;
fieldrec.offset += fieldrec.size;
}
#if 0 /* obsolete -- keep for reference */
if ( pflags )
*pflags |= 1L << field->flag_bit;
#else
FT_UNUSED( pflags );
#endif
parser->cursor = old_cursor;
parser->limit = old_limit;
Exit:
return error;
}
|
Overflow
| 0
|
ps_parser_load_field_table( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags )
{
T1_TokenRec elements[T1_MAX_TABLE_ELEMENTS];
T1_Token token;
FT_Int num_elements;
FT_Error error = FT_Err_Ok;
FT_Byte* old_cursor;
FT_Byte* old_limit;
T1_FieldRec fieldrec = *(T1_Field)field;
fieldrec.type = T1_FIELD_TYPE_INTEGER;
if ( field->type == T1_FIELD_TYPE_FIXED_ARRAY ||
field->type == T1_FIELD_TYPE_BBOX )
fieldrec.type = T1_FIELD_TYPE_FIXED;
ps_parser_to_token_array( parser, elements,
T1_MAX_TABLE_ELEMENTS, &num_elements );
if ( num_elements < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( (FT_UInt)num_elements > field->array_max )
num_elements = (FT_Int)field->array_max;
old_cursor = parser->cursor;
old_limit = parser->limit;
/* we store the elements count if necessary; */
/* we further assume that `count_offset' can't be zero */
if ( field->type != T1_FIELD_TYPE_BBOX && field->count_offset != 0 )
*(FT_Byte*)( (FT_Byte*)objects[0] + field->count_offset ) =
(FT_Byte)num_elements;
/* we now load each element, adjusting the field.offset on each one */
token = elements;
for ( ; num_elements > 0; num_elements--, token++ )
{
parser->cursor = token->start;
parser->limit = token->limit;
error = ps_parser_load_field( parser,
&fieldrec,
objects,
max_objects,
0 );
if ( error )
break;
fieldrec.offset += fieldrec.size;
}
#if 0 /* obsolete -- keep for reference */
if ( pflags )
*pflags |= 1L << field->flag_bit;
#else
FT_UNUSED( pflags );
#endif
parser->cursor = old_cursor;
parser->limit = old_limit;
Exit:
return error;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,837
|
ps_parser_skip_spaces( PS_Parser parser )
{
skip_spaces( &parser->cursor, parser->limit );
}
|
Overflow
| 0
|
ps_parser_skip_spaces( PS_Parser parser )
{
skip_spaces( &parser->cursor, parser->limit );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,838
|
ps_parser_to_bytes( PS_Parser parser,
FT_Byte* bytes,
FT_Offset max_bytes,
FT_ULong* pnum_bytes,
FT_Bool delimiters )
{
FT_Error error = FT_Err_Ok;
FT_Byte* cur;
ps_parser_skip_spaces( parser );
cur = parser->cursor;
if ( cur >= parser->limit )
goto Exit;
if ( delimiters )
{
if ( *cur != '<' )
{
FT_ERROR(( "ps_parser_to_bytes: Missing starting delimiter `<'\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
cur++;
}
*pnum_bytes = PS_Conv_ASCIIHexDecode( &cur,
parser->limit,
bytes,
max_bytes );
if ( delimiters )
{
if ( cur < parser->limit && *cur != '>' )
{
FT_ERROR(( "ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
cur++;
}
parser->cursor = cur;
Exit:
return error;
}
|
Overflow
| 0
|
ps_parser_to_bytes( PS_Parser parser,
FT_Byte* bytes,
FT_Offset max_bytes,
FT_ULong* pnum_bytes,
FT_Bool delimiters )
{
FT_Error error = FT_Err_Ok;
FT_Byte* cur;
ps_parser_skip_spaces( parser );
cur = parser->cursor;
if ( cur >= parser->limit )
goto Exit;
if ( delimiters )
{
if ( *cur != '<' )
{
FT_ERROR(( "ps_parser_to_bytes: Missing starting delimiter `<'\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
cur++;
}
*pnum_bytes = PS_Conv_ASCIIHexDecode( &cur,
parser->limit,
bytes,
max_bytes );
if ( delimiters )
{
if ( cur < parser->limit && *cur != '>' )
{
FT_ERROR(( "ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
cur++;
}
parser->cursor = cur;
Exit:
return error;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,839
|
ps_parser_to_fixed( PS_Parser parser,
FT_Int power_ten )
{
ps_parser_skip_spaces( parser );
return PS_Conv_ToFixed( &parser->cursor, parser->limit, power_ten );
}
|
Overflow
| 0
|
ps_parser_to_fixed( PS_Parser parser,
FT_Int power_ten )
{
ps_parser_skip_spaces( parser );
return PS_Conv_ToFixed( &parser->cursor, parser->limit, power_ten );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,840
|
ps_parser_to_fixed_array( PS_Parser parser,
FT_Int max_values,
FT_Fixed* values,
FT_Int power_ten )
{
ps_parser_skip_spaces( parser );
return ps_tofixedarray( &parser->cursor, parser->limit,
max_values, values, power_ten );
}
|
Overflow
| 0
|
ps_parser_to_fixed_array( PS_Parser parser,
FT_Int max_values,
FT_Fixed* values,
FT_Int power_ten )
{
ps_parser_skip_spaces( parser );
return ps_tofixedarray( &parser->cursor, parser->limit,
max_values, values, power_ten );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,841
|
ps_parser_to_int( PS_Parser parser )
{
ps_parser_skip_spaces( parser );
return PS_Conv_ToInt( &parser->cursor, parser->limit );
}
|
Overflow
| 0
|
ps_parser_to_int( PS_Parser parser )
{
ps_parser_skip_spaces( parser );
return PS_Conv_ToInt( &parser->cursor, parser->limit );
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,842
|
ps_table_add( PS_Table table,
FT_Int idx,
void* object,
FT_UInt length )
{
if ( idx < 0 || idx >= table->max_elems )
{
FT_ERROR(( "ps_table_add: invalid index\n" ));
return FT_THROW( Invalid_Argument );
}
/* grow the base block if needed */
if ( table->cursor + length > table->capacity )
{
FT_Error error;
FT_Offset new_size = table->capacity;
FT_PtrDist in_offset;
in_offset = (FT_Byte*)object - table->block;
if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
in_offset = -1;
while ( new_size < table->cursor + length )
{
/* increase size by 25% and round up to the nearest multiple
of 1024 */
new_size += ( new_size >> 2 ) + 1;
new_size = FT_PAD_CEIL( new_size, 1024 );
}
error = reallocate_t1_table( table, new_size );
if ( error )
return error;
if ( in_offset >= 0 )
object = table->block + in_offset;
}
/* add the object to the base block and adjust offset */
table->elements[idx] = table->block + table->cursor;
table->lengths [idx] = length;
FT_MEM_COPY( table->block + table->cursor, object, length );
table->cursor += length;
return FT_Err_Ok;
}
|
Overflow
| 0
|
ps_table_add( PS_Table table,
FT_Int idx,
void* object,
FT_UInt length )
{
if ( idx < 0 || idx >= table->max_elems )
{
FT_ERROR(( "ps_table_add: invalid index\n" ));
return FT_THROW( Invalid_Argument );
}
/* grow the base block if needed */
if ( table->cursor + length > table->capacity )
{
FT_Error error;
FT_Offset new_size = table->capacity;
FT_PtrDist in_offset;
in_offset = (FT_Byte*)object - table->block;
if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
in_offset = -1;
while ( new_size < table->cursor + length )
{
/* increase size by 25% and round up to the nearest multiple
of 1024 */
new_size += ( new_size >> 2 ) + 1;
new_size = FT_PAD_CEIL( new_size, 1024 );
}
error = reallocate_t1_table( table, new_size );
if ( error )
return error;
if ( in_offset >= 0 )
object = table->block + in_offset;
}
/* add the object to the base block and adjust offset */
table->elements[idx] = table->block + table->cursor;
table->lengths [idx] = length;
FT_MEM_COPY( table->block + table->cursor, object, length );
table->cursor += length;
return FT_Err_Ok;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,843
|
ps_table_new( PS_Table table,
FT_Int count,
FT_Memory memory )
{
FT_Error error;
table->memory = memory;
if ( FT_NEW_ARRAY( table->elements, count ) ||
FT_NEW_ARRAY( table->lengths, count ) )
goto Exit;
table->max_elems = count;
table->init = 0xDEADBEEFUL;
table->num_elems = 0;
table->block = NULL;
table->capacity = 0;
table->cursor = 0;
*(PS_Table_FuncsRec*)&table->funcs = ps_table_funcs;
Exit:
if ( error )
FT_FREE( table->elements );
return error;
}
|
Overflow
| 0
|
ps_table_new( PS_Table table,
FT_Int count,
FT_Memory memory )
{
FT_Error error;
table->memory = memory;
if ( FT_NEW_ARRAY( table->elements, count ) ||
FT_NEW_ARRAY( table->lengths, count ) )
goto Exit;
table->max_elems = count;
table->init = 0xDEADBEEFUL;
table->num_elems = 0;
table->block = NULL;
table->capacity = 0;
table->cursor = 0;
*(PS_Table_FuncsRec*)&table->funcs = ps_table_funcs;
Exit:
if ( error )
FT_FREE( table->elements );
return error;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,844
|
ps_table_release( PS_Table table )
{
FT_Memory memory = table->memory;
if ( (FT_ULong)table->init == 0xDEADBEEFUL )
{
FT_FREE( table->block );
FT_FREE( table->elements );
FT_FREE( table->lengths );
table->init = 0;
}
}
|
Overflow
| 0
|
ps_table_release( PS_Table table )
{
FT_Memory memory = table->memory;
if ( (FT_ULong)table->init == 0xDEADBEEFUL )
{
FT_FREE( table->block );
FT_FREE( table->elements );
FT_FREE( table->lengths );
table->init = 0;
}
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,845
|
ps_tofixedarray( FT_Byte* *acur,
FT_Byte* limit,
FT_Int max_values,
FT_Fixed* values,
FT_Int power_ten )
{
FT_Byte* cur = *acur;
FT_Int count = 0;
FT_Byte c, ender;
if ( cur >= limit )
goto Exit;
/* Check for the beginning of an array. Otherwise, only one number */
/* will be read. */
c = *cur;
ender = 0;
if ( c == '[' )
ender = ']';
else if ( c == '{' )
ender = '}';
if ( ender )
cur++;
/* now, read the values */
while ( cur < limit )
{
FT_Fixed dummy;
FT_Byte* old_cur;
/* skip whitespace in front of data */
skip_spaces( &cur, limit );
if ( cur >= limit )
goto Exit;
if ( *cur == ender )
{
cur++;
break;
}
old_cur = cur;
if ( values && count >= max_values )
break;
/* call PS_Conv_ToFixed() even if coords == NULL */
/* to properly parse number at `cur' */
*( values ? &values[count] : &dummy ) =
PS_Conv_ToFixed( &cur, limit, power_ten );
if ( old_cur == cur )
{
count = -1;
goto Exit;
}
else
count++;
if ( !ender )
break;
}
Exit:
*acur = cur;
return count;
}
|
Overflow
| 0
|
ps_tofixedarray( FT_Byte* *acur,
FT_Byte* limit,
FT_Int max_values,
FT_Fixed* values,
FT_Int power_ten )
{
FT_Byte* cur = *acur;
FT_Int count = 0;
FT_Byte c, ender;
if ( cur >= limit )
goto Exit;
/* Check for the beginning of an array. Otherwise, only one number */
/* will be read. */
c = *cur;
ender = 0;
if ( c == '[' )
ender = ']';
else if ( c == '{' )
ender = '}';
if ( ender )
cur++;
/* now, read the values */
while ( cur < limit )
{
FT_Fixed dummy;
FT_Byte* old_cur;
/* skip whitespace in front of data */
skip_spaces( &cur, limit );
if ( cur >= limit )
goto Exit;
if ( *cur == ender )
{
cur++;
break;
}
old_cur = cur;
if ( values && count >= max_values )
break;
/* call PS_Conv_ToFixed() even if coords == NULL */
/* to properly parse number at `cur' */
*( values ? &values[count] : &dummy ) =
PS_Conv_ToFixed( &cur, limit, power_ten );
if ( old_cur == cur )
{
count = -1;
goto Exit;
}
else
count++;
if ( !ender )
break;
}
Exit:
*acur = cur;
return count;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,846
|
ps_tostring( FT_Byte** cursor,
FT_Byte* limit,
FT_Memory memory )
{
FT_Byte* cur = *cursor;
FT_UInt len = 0;
FT_Int count;
FT_String* result;
FT_Error error;
/* XXX: some stupid fonts have a `Notice' or `Copyright' string */
/* that simply doesn't begin with an opening parenthesis, even */
/* though they have a closing one! E.g. "amuncial.pfb" */
/* */
/* We must deal with these ill-fated cases there. Note that */
/* these fonts didn't work with the old Type 1 driver as the */
/* notice/copyright was not recognized as a valid string token */
/* and made the old token parser commit errors. */
while ( cur < limit && ( *cur == ' ' || *cur == '\t' ) )
cur++;
if ( cur + 1 >= limit )
return 0;
if ( *cur == '(' )
cur++; /* skip the opening parenthesis, if there is one */
*cursor = cur;
count = 0;
/* then, count its length */
for ( ; cur < limit; cur++ )
{
if ( *cur == '(' )
count++;
else if ( *cur == ')' )
{
count--;
if ( count < 0 )
break;
}
}
len = (FT_UInt)( cur - *cursor );
if ( cur >= limit || FT_ALLOC( result, len + 1 ) )
return 0;
/* now copy the string */
FT_MEM_COPY( result, *cursor, len );
result[len] = '\0';
*cursor = cur;
return result;
}
|
Overflow
| 0
|
ps_tostring( FT_Byte** cursor,
FT_Byte* limit,
FT_Memory memory )
{
FT_Byte* cur = *cursor;
FT_UInt len = 0;
FT_Int count;
FT_String* result;
FT_Error error;
/* XXX: some stupid fonts have a `Notice' or `Copyright' string */
/* that simply doesn't begin with an opening parenthesis, even */
/* though they have a closing one! E.g. "amuncial.pfb" */
/* */
/* We must deal with these ill-fated cases there. Note that */
/* these fonts didn't work with the old Type 1 driver as the */
/* notice/copyright was not recognized as a valid string token */
/* and made the old token parser commit errors. */
while ( cur < limit && ( *cur == ' ' || *cur == '\t' ) )
cur++;
if ( cur + 1 >= limit )
return 0;
if ( *cur == '(' )
cur++; /* skip the opening parenthesis, if there is one */
*cursor = cur;
count = 0;
/* then, count its length */
for ( ; cur < limit; cur++ )
{
if ( *cur == '(' )
count++;
else if ( *cur == ')' )
{
count--;
if ( count < 0 )
break;
}
}
len = (FT_UInt)( cur - *cursor );
if ( cur >= limit || FT_ALLOC( result, len + 1 ) )
return 0;
/* now copy the string */
FT_MEM_COPY( result, *cursor, len );
result[len] = '\0';
*cursor = cur;
return result;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,847
|
reallocate_t1_table( PS_Table table,
FT_Offset new_size )
{
FT_Memory memory = table->memory;
FT_Byte* old_base = table->block;
FT_Error error;
/* allocate new base block */
if ( FT_ALLOC( table->block, new_size ) )
{
table->block = old_base;
return error;
}
/* copy elements and shift offsets */
if ( old_base )
{
FT_MEM_COPY( table->block, old_base, table->capacity );
shift_elements( table, old_base );
FT_FREE( old_base );
}
table->capacity = new_size;
return FT_Err_Ok;
}
|
Overflow
| 0
|
reallocate_t1_table( PS_Table table,
FT_Offset new_size )
{
FT_Memory memory = table->memory;
FT_Byte* old_base = table->block;
FT_Error error;
/* allocate new base block */
if ( FT_ALLOC( table->block, new_size ) )
{
table->block = old_base;
return error;
}
/* copy elements and shift offsets */
if ( old_base )
{
FT_MEM_COPY( table->block, old_base, table->capacity );
shift_elements( table, old_base );
FT_FREE( old_base );
}
table->capacity = new_size;
return FT_Err_Ok;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,848
|
skip_comment( FT_Byte* *acur,
FT_Byte* limit )
{
FT_Byte* cur = *acur;
while ( cur < limit )
{
if ( IS_PS_NEWLINE( *cur ) )
break;
cur++;
}
*acur = cur;
}
|
Overflow
| 0
|
skip_comment( FT_Byte* *acur,
FT_Byte* limit )
{
FT_Byte* cur = *acur;
while ( cur < limit )
{
if ( IS_PS_NEWLINE( *cur ) )
break;
cur++;
}
*acur = cur;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,849
|
skip_literal_string( FT_Byte* *acur,
FT_Byte* limit )
{
FT_Byte* cur = *acur;
FT_Int embed = 0;
FT_Error error = FT_ERR( Invalid_File_Format );
unsigned int i;
while ( cur < limit )
{
FT_Byte c = *cur;
cur++;
if ( c == '\\' )
{
/* Red Book 3rd ed., section `Literal Text Strings', p. 29: */
/* A backslash can introduce three different types */
/* of escape sequences: */
/* - a special escaped char like \r, \n, etc. */
/* - a one-, two-, or three-digit octal number */
/* - none of the above in which case the backslash is ignored */
if ( cur == limit )
/* error (or to be ignored?) */
break;
switch ( *cur )
{
/* skip `special' escape */
case 'n':
case 'r':
case 't':
case 'b':
case 'f':
case '\\':
case '(':
case ')':
cur++;
break;
default:
/* skip octal escape or ignore backslash */
for ( i = 0; i < 3 && cur < limit; i++ )
{
if ( !IS_OCTAL_DIGIT( *cur ) )
break;
cur++;
}
}
}
else if ( c == '(' )
embed++;
else if ( c == ')' )
{
embed--;
if ( embed == 0 )
{
error = FT_Err_Ok;
break;
}
}
}
*acur = cur;
return error;
}
|
Overflow
| 0
|
skip_literal_string( FT_Byte* *acur,
FT_Byte* limit )
{
FT_Byte* cur = *acur;
FT_Int embed = 0;
FT_Error error = FT_ERR( Invalid_File_Format );
unsigned int i;
while ( cur < limit )
{
FT_Byte c = *cur;
cur++;
if ( c == '\\' )
{
/* Red Book 3rd ed., section `Literal Text Strings', p. 29: */
/* A backslash can introduce three different types */
/* of escape sequences: */
/* - a special escaped char like \r, \n, etc. */
/* - a one-, two-, or three-digit octal number */
/* - none of the above in which case the backslash is ignored */
if ( cur == limit )
/* error (or to be ignored?) */
break;
switch ( *cur )
{
/* skip `special' escape */
case 'n':
case 'r':
case 't':
case 'b':
case 'f':
case '\\':
case '(':
case ')':
cur++;
break;
default:
/* skip octal escape or ignore backslash */
for ( i = 0; i < 3 && cur < limit; i++ )
{
if ( !IS_OCTAL_DIGIT( *cur ) )
break;
cur++;
}
}
}
else if ( c == '(' )
embed++;
else if ( c == ')' )
{
embed--;
if ( embed == 0 )
{
error = FT_Err_Ok;
break;
}
}
}
*acur = cur;
return error;
}
|
@@ -1718,6 +1718,14 @@
first = outline->n_contours <= 1
? 0 : outline->contours[outline->n_contours - 2] + 1;
+ /* in malformed fonts it can happen that a contour was started */
+ /* but no points were added */
+ if ( outline->n_contours && first == outline->n_points )
+ {
+ outline->n_contours--;
+ return;
+ }
+
/* We must not include the last point in the path if it */
/* is located on the first point. */
if ( outline->n_points > 1 )
|
CWE-119
| null | null |
5,850
|
CtcpHandler::CtcpHandler(CoreNetwork *parent)
: CoreBasicHandler(parent),
XDELIM("\001"),
_ignoreListManager(parent->ignoreListManager())
{
QByteArray MQUOTE = QByteArray("\020");
ctcpMDequoteHash[MQUOTE + '0'] = QByteArray(1, '\000');
ctcpMDequoteHash[MQUOTE + 'n'] = QByteArray(1, '\n');
ctcpMDequoteHash[MQUOTE + 'r'] = QByteArray(1, '\r');
ctcpMDequoteHash[MQUOTE + MQUOTE] = MQUOTE;
QByteArray XQUOTE = QByteArray("\134");
ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE;
ctcpXDelimDequoteHash[XQUOTE + QByteArray("a")] = XDELIM;
}
|
DoS
| 0
|
CtcpHandler::CtcpHandler(CoreNetwork *parent)
: CoreBasicHandler(parent),
XDELIM("\001"),
_ignoreListManager(parent->ignoreListManager())
{
QByteArray MQUOTE = QByteArray("\020");
ctcpMDequoteHash[MQUOTE + '0'] = QByteArray(1, '\000');
ctcpMDequoteHash[MQUOTE + 'n'] = QByteArray(1, '\n');
ctcpMDequoteHash[MQUOTE + 'r'] = QByteArray(1, '\r');
ctcpMDequoteHash[MQUOTE + MQUOTE] = MQUOTE;
QByteArray XQUOTE = QByteArray("\134");
ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE;
ctcpXDelimDequoteHash[XQUOTE + QByteArray("a")] = XDELIM;
}
|
@@ -129,6 +129,7 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
int xdelimPos = -1;
int xdelimEndPos = -1;
int spacePos = -1;
+ QList<QByteArray> replies;
while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) {
if(xdelimPos > 0)
displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags);
@@ -154,7 +155,16 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
ctcpparam = QString();
}
- handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) {
+ QString reply_;
+ handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_));
+ if(ctcptype == CtcpQuery && !reply_.isNull()) {
+ replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_)));
+ }
+ }
+ }
+ if(ctcptype == CtcpQuery && !replies.isEmpty()) {
+ packedReply(nickFromMask(prefix), replies);
}
if(!dequotedMessage.isEmpty())
@@ -180,20 +190,39 @@ void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QS
emit putCmd("NOTICE", params);
}
+void CtcpHandler::packedReply(const QString &bufname, const QList<QByteArray> &replies) {
+ QList<QByteArray> params;
+
+ int answerSize = 0;
+ for(int i = 0; i < replies.count(); i++) {
+ answerSize += replies.at(i).size();
+ }
+
+ QByteArray quotedReply(answerSize, 0);
+ int nextPos = 0;
+ QByteArray &reply = quotedReply;
+ for(int i = 0; i < replies.count(); i++) {
+ reply = replies.at(i);
+ quotedReply.replace(nextPos, reply.size(), reply);
+ nextPos += reply.size();
+ }
+
+ params << serverEncode(bufname) << quotedReply;
+ emit putCmd("NOTICE", params);
+}
+
//******************************/
// CTCP HANDLER
//******************************/
-void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) {
Q_UNUSED(ctcptype)
emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix);
}
-void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING"))
- return;
- reply(nickFromMask(prefix), "PING", param);
+ reply = param;
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
} else {
// display ping answer
@@ -204,14 +233,10 @@ void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QSt
}
}
-void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION"))
- return;
- reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
+ reply = QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org").arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate);
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
} else {
// display Version answer
@@ -220,28 +245,24 @@ void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const
}
}
-void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "TIME"))
- return;
- reply(nickFromMask(prefix), "TIME", QDateTime::currentDateTime().toString());
+ reply = QDateTime::currentDateTime().toString();
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix));
- }
- else {
+ } else {
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2")
.arg(nickFromMask(prefix)).arg(param));
}
}
-void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(ctcptype);
Q_UNUSED(target);
- if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
- QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
- if(!param.isEmpty())
- str.append(tr(" with arguments: %1").arg(param));
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
- }
+ Q_UNUSED(reply);
+ QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
+ if(!param.isEmpty())
+ str.append(tr(" with arguments: %1").arg(param));
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
}
|
CWE-399
| null | null |
5,851
|
QByteArray CtcpHandler::lowLevelDequote(const QByteArray &message) {
QByteArray dequotedMessage;
QByteArray messagepart;
QHash<QByteArray, QByteArray>::iterator ctcpquote;
for(int i = 0; i < message.size(); i++) {
messagepart = message.mid(i,1);
if(i+1 < message.size()) {
for(ctcpquote = ctcpMDequoteHash.begin(); ctcpquote != ctcpMDequoteHash.end(); ++ctcpquote) {
if(message.mid(i,2) == ctcpquote.key()) {
messagepart = ctcpquote.value();
i++;
break;
}
}
}
dequotedMessage += messagepart;
}
return dequotedMessage;
}
|
DoS
| 0
|
QByteArray CtcpHandler::lowLevelDequote(const QByteArray &message) {
QByteArray dequotedMessage;
QByteArray messagepart;
QHash<QByteArray, QByteArray>::iterator ctcpquote;
for(int i = 0; i < message.size(); i++) {
messagepart = message.mid(i,1);
if(i+1 < message.size()) {
for(ctcpquote = ctcpMDequoteHash.begin(); ctcpquote != ctcpMDequoteHash.end(); ++ctcpquote) {
if(message.mid(i,2) == ctcpquote.key()) {
messagepart = ctcpquote.value();
i++;
break;
}
}
}
dequotedMessage += messagepart;
}
return dequotedMessage;
}
|
@@ -129,6 +129,7 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
int xdelimPos = -1;
int xdelimEndPos = -1;
int spacePos = -1;
+ QList<QByteArray> replies;
while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) {
if(xdelimPos > 0)
displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags);
@@ -154,7 +155,16 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
ctcpparam = QString();
}
- handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) {
+ QString reply_;
+ handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_));
+ if(ctcptype == CtcpQuery && !reply_.isNull()) {
+ replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_)));
+ }
+ }
+ }
+ if(ctcptype == CtcpQuery && !replies.isEmpty()) {
+ packedReply(nickFromMask(prefix), replies);
}
if(!dequotedMessage.isEmpty())
@@ -180,20 +190,39 @@ void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QS
emit putCmd("NOTICE", params);
}
+void CtcpHandler::packedReply(const QString &bufname, const QList<QByteArray> &replies) {
+ QList<QByteArray> params;
+
+ int answerSize = 0;
+ for(int i = 0; i < replies.count(); i++) {
+ answerSize += replies.at(i).size();
+ }
+
+ QByteArray quotedReply(answerSize, 0);
+ int nextPos = 0;
+ QByteArray &reply = quotedReply;
+ for(int i = 0; i < replies.count(); i++) {
+ reply = replies.at(i);
+ quotedReply.replace(nextPos, reply.size(), reply);
+ nextPos += reply.size();
+ }
+
+ params << serverEncode(bufname) << quotedReply;
+ emit putCmd("NOTICE", params);
+}
+
//******************************/
// CTCP HANDLER
//******************************/
-void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) {
Q_UNUSED(ctcptype)
emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix);
}
-void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING"))
- return;
- reply(nickFromMask(prefix), "PING", param);
+ reply = param;
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
} else {
// display ping answer
@@ -204,14 +233,10 @@ void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QSt
}
}
-void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION"))
- return;
- reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
+ reply = QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org").arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate);
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
} else {
// display Version answer
@@ -220,28 +245,24 @@ void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const
}
}
-void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "TIME"))
- return;
- reply(nickFromMask(prefix), "TIME", QDateTime::currentDateTime().toString());
+ reply = QDateTime::currentDateTime().toString();
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix));
- }
- else {
+ } else {
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2")
.arg(nickFromMask(prefix)).arg(param));
}
}
-void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(ctcptype);
Q_UNUSED(target);
- if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
- QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
- if(!param.isEmpty())
- str.append(tr(" with arguments: %1").arg(param));
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
- }
+ Q_UNUSED(reply);
+ QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
+ if(!param.isEmpty())
+ str.append(tr(" with arguments: %1").arg(param));
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
}
|
CWE-399
| null | null |
5,852
|
QByteArray CtcpHandler::lowLevelQuote(const QByteArray &message) {
QByteArray quotedMessage = message;
QHash<QByteArray, QByteArray> quoteHash = ctcpMDequoteHash;
QByteArray MQUOTE = QByteArray("\020");
quoteHash.remove(MQUOTE + MQUOTE);
quotedMessage.replace(MQUOTE, MQUOTE + MQUOTE);
QHash<QByteArray, QByteArray>::const_iterator quoteIter = quoteHash.constBegin();
while(quoteIter != quoteHash.constEnd()) {
quotedMessage.replace(quoteIter.value(), quoteIter.key());
quoteIter++;
}
return quotedMessage;
}
|
DoS
| 0
|
QByteArray CtcpHandler::lowLevelQuote(const QByteArray &message) {
QByteArray quotedMessage = message;
QHash<QByteArray, QByteArray> quoteHash = ctcpMDequoteHash;
QByteArray MQUOTE = QByteArray("\020");
quoteHash.remove(MQUOTE + MQUOTE);
quotedMessage.replace(MQUOTE, MQUOTE + MQUOTE);
QHash<QByteArray, QByteArray>::const_iterator quoteIter = quoteHash.constBegin();
while(quoteIter != quoteHash.constEnd()) {
quotedMessage.replace(quoteIter.value(), quoteIter.key());
quoteIter++;
}
return quotedMessage;
}
|
@@ -129,6 +129,7 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
int xdelimPos = -1;
int xdelimEndPos = -1;
int spacePos = -1;
+ QList<QByteArray> replies;
while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) {
if(xdelimPos > 0)
displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags);
@@ -154,7 +155,16 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
ctcpparam = QString();
}
- handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) {
+ QString reply_;
+ handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_));
+ if(ctcptype == CtcpQuery && !reply_.isNull()) {
+ replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_)));
+ }
+ }
+ }
+ if(ctcptype == CtcpQuery && !replies.isEmpty()) {
+ packedReply(nickFromMask(prefix), replies);
}
if(!dequotedMessage.isEmpty())
@@ -180,20 +190,39 @@ void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QS
emit putCmd("NOTICE", params);
}
+void CtcpHandler::packedReply(const QString &bufname, const QList<QByteArray> &replies) {
+ QList<QByteArray> params;
+
+ int answerSize = 0;
+ for(int i = 0; i < replies.count(); i++) {
+ answerSize += replies.at(i).size();
+ }
+
+ QByteArray quotedReply(answerSize, 0);
+ int nextPos = 0;
+ QByteArray &reply = quotedReply;
+ for(int i = 0; i < replies.count(); i++) {
+ reply = replies.at(i);
+ quotedReply.replace(nextPos, reply.size(), reply);
+ nextPos += reply.size();
+ }
+
+ params << serverEncode(bufname) << quotedReply;
+ emit putCmd("NOTICE", params);
+}
+
//******************************/
// CTCP HANDLER
//******************************/
-void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) {
Q_UNUSED(ctcptype)
emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix);
}
-void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING"))
- return;
- reply(nickFromMask(prefix), "PING", param);
+ reply = param;
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
} else {
// display ping answer
@@ -204,14 +233,10 @@ void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QSt
}
}
-void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION"))
- return;
- reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
+ reply = QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org").arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate);
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
} else {
// display Version answer
@@ -220,28 +245,24 @@ void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const
}
}
-void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "TIME"))
- return;
- reply(nickFromMask(prefix), "TIME", QDateTime::currentDateTime().toString());
+ reply = QDateTime::currentDateTime().toString();
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix));
- }
- else {
+ } else {
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2")
.arg(nickFromMask(prefix)).arg(param));
}
}
-void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(ctcptype);
Q_UNUSED(target);
- if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
- QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
- if(!param.isEmpty())
- str.append(tr(" with arguments: %1").arg(param));
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
- }
+ Q_UNUSED(reply);
+ QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
+ if(!param.isEmpty())
+ str.append(tr(" with arguments: %1").arg(param));
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
}
|
CWE-399
| null | null |
5,853
|
QByteArray CtcpHandler::xdelimDequote(const QByteArray &message) {
QByteArray dequotedMessage;
QByteArray messagepart;
QHash<QByteArray, QByteArray>::iterator xdelimquote;
for(int i = 0; i < message.size(); i++) {
messagepart = message.mid(i,1);
if(i+1 < message.size()) {
for(xdelimquote = ctcpXDelimDequoteHash.begin(); xdelimquote != ctcpXDelimDequoteHash.end(); ++xdelimquote) {
if(message.mid(i,2) == xdelimquote.key()) {
messagepart = xdelimquote.value();
i++;
break;
}
}
}
dequotedMessage += messagepart;
}
return dequotedMessage;
}
|
DoS
| 0
|
QByteArray CtcpHandler::xdelimDequote(const QByteArray &message) {
QByteArray dequotedMessage;
QByteArray messagepart;
QHash<QByteArray, QByteArray>::iterator xdelimquote;
for(int i = 0; i < message.size(); i++) {
messagepart = message.mid(i,1);
if(i+1 < message.size()) {
for(xdelimquote = ctcpXDelimDequoteHash.begin(); xdelimquote != ctcpXDelimDequoteHash.end(); ++xdelimquote) {
if(message.mid(i,2) == xdelimquote.key()) {
messagepart = xdelimquote.value();
i++;
break;
}
}
}
dequotedMessage += messagepart;
}
return dequotedMessage;
}
|
@@ -129,6 +129,7 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
int xdelimPos = -1;
int xdelimEndPos = -1;
int spacePos = -1;
+ QList<QByteArray> replies;
while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) {
if(xdelimPos > 0)
displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags);
@@ -154,7 +155,16 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const
ctcpparam = QString();
}
- handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) {
+ QString reply_;
+ handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_));
+ if(ctcptype == CtcpQuery && !reply_.isNull()) {
+ replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_)));
+ }
+ }
+ }
+ if(ctcptype == CtcpQuery && !replies.isEmpty()) {
+ packedReply(nickFromMask(prefix), replies);
}
if(!dequotedMessage.isEmpty())
@@ -180,20 +190,39 @@ void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QS
emit putCmd("NOTICE", params);
}
+void CtcpHandler::packedReply(const QString &bufname, const QList<QByteArray> &replies) {
+ QList<QByteArray> params;
+
+ int answerSize = 0;
+ for(int i = 0; i < replies.count(); i++) {
+ answerSize += replies.at(i).size();
+ }
+
+ QByteArray quotedReply(answerSize, 0);
+ int nextPos = 0;
+ QByteArray &reply = quotedReply;
+ for(int i = 0; i < replies.count(); i++) {
+ reply = replies.at(i);
+ quotedReply.replace(nextPos, reply.size(), reply);
+ nextPos += reply.size();
+ }
+
+ params << serverEncode(bufname) << quotedReply;
+ emit putCmd("NOTICE", params);
+}
+
//******************************/
// CTCP HANDLER
//******************************/
-void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) {
Q_UNUSED(ctcptype)
emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix);
}
-void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING"))
- return;
- reply(nickFromMask(prefix), "PING", param);
+ reply = param;
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
} else {
// display ping answer
@@ -204,14 +233,10 @@ void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QSt
}
}
-void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION"))
- return;
- reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
+ reply = QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org").arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate);
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
} else {
// display Version answer
@@ -220,28 +245,24 @@ void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const
}
}
-void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "TIME"))
- return;
- reply(nickFromMask(prefix), "TIME", QDateTime::currentDateTime().toString());
+ reply = QDateTime::currentDateTime().toString();
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix));
- }
- else {
+ } else {
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2")
.arg(nickFromMask(prefix)).arg(param));
}
}
-void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
Q_UNUSED(ctcptype);
Q_UNUSED(target);
- if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
- QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
- if(!param.isEmpty())
- str.append(tr(" with arguments: %1").arg(param));
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
- }
+ Q_UNUSED(reply);
+ QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix);
+ if(!param.isEmpty())
+ str.append(tr(" with arguments: %1").arg(param));
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str);
}
|
CWE-399
| null | null |
5,854
|
add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
{
struct mlist *ml;
if ((ml = CAST(struct mlist *, emalloc(sizeof(*ml)))) == NULL)
return -1;
ml->map = idx == 0 ? map : NULL;
ml->magic = map->magic[idx];
ml->nmagic = map->nmagic[idx];
mlp->prev->next = ml;
ml->prev = mlp->prev;
ml->next = mlp;
mlp->prev = ml;
return 0;
}
|
DoS Mem. Corr.
| 0
|
add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
{
struct mlist *ml;
if ((ml = CAST(struct mlist *, emalloc(sizeof(*ml)))) == NULL)
return -1;
ml->map = idx == 0 ? map : NULL;
ml->magic = map->magic[idx];
ml->nmagic = map->nmagic[idx];
mlp->prev->next = ml;
ml->prev = mlp->prev;
ml->next = mlp;
mlp->prev = ml;
return 0;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,855
|
apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
{
static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
static const size_t m = sizeof(**map->magic);
int fd = -1;
size_t len;
char *dbname;
int rv = -1;
uint32_t i;
php_stream *stream;
TSRMLS_FETCH();
dbname = mkdbname(ms, fn, 0);
if (dbname == NULL)
goto out;
/* wb+ == O_WRONLY|O_CREAT|O_TRUNC|O_BINARY */
stream = php_stream_open_wrapper((char *)fn, "wb+", REPORT_ERRORS, NULL);
if (!stream) {
file_error(ms, errno, "cannot open `%s'", dbname);
goto out;
}
if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
if (php_stream_write(stream, (const char *)map->nmagic, nm) != (ssize_t)nm) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
assert(nm + sizeof(ar) < m);
if (php_stream_seek(stream,(off_t)sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) {
file_error(ms, errno, "error seeking `%s'", dbname);
goto out;
}
for (i = 0; i < MAGIC_SETS; i++) {
len = m * map->nmagic[i];
if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
}
if (stream) {
php_stream_close(stream);
}
rv = 0;
out:
efree(dbname);
return rv;
}
|
DoS Mem. Corr.
| 0
|
apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
{
static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
static const size_t m = sizeof(**map->magic);
int fd = -1;
size_t len;
char *dbname;
int rv = -1;
uint32_t i;
php_stream *stream;
TSRMLS_FETCH();
dbname = mkdbname(ms, fn, 0);
if (dbname == NULL)
goto out;
/* wb+ == O_WRONLY|O_CREAT|O_TRUNC|O_BINARY */
stream = php_stream_open_wrapper((char *)fn, "wb+", REPORT_ERRORS, NULL);
if (!stream) {
file_error(ms, errno, "cannot open `%s'", dbname);
goto out;
}
if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
if (php_stream_write(stream, (const char *)map->nmagic, nm) != (ssize_t)nm) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
assert(nm + sizeof(ar) < m);
if (php_stream_seek(stream,(off_t)sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) {
file_error(ms, errno, "error seeking `%s'", dbname);
goto out;
}
for (i = 0; i < MAGIC_SETS; i++) {
len = m * map->nmagic[i];
if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
}
if (stream) {
php_stream_close(stream);
}
rv = 0;
out:
efree(dbname);
return rv;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,856
|
apprentice_map(struct magic_set *ms, const char *fn)
{
uint32_t *ptr;
uint32_t version, entries, nentries;
int needsbyteswap;
char *dbname = NULL;
struct magic_map *map;
size_t i;
php_stream *stream = NULL;
php_stream_statbuf st;
TSRMLS_FETCH();
if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
file_oomem(ms, sizeof(*map));
efree(map);
goto error;
}
if (fn == NULL) {
map->p = (void *)&php_magic_database;
goto internal_loaded;
}
#ifdef PHP_WIN32
/* Don't bother on windows with php_stream_open_wrapper,
return to give apprentice_load() a chance. */
if (php_stream_stat_path_ex((char *)fn, 0, &st, NULL) == SUCCESS) {
if (st.sb.st_mode & S_IFDIR) {
goto error;
}
}
#endif
dbname = mkdbname(ms, fn, 0);
if (dbname == NULL)
goto error;
stream = php_stream_open_wrapper((char *)fn, "rb", REPORT_ERRORS, NULL);
if (!stream) {
goto error;
}
if (php_stream_stat(stream, &st) < 0) {
file_error(ms, errno, "cannot stat `%s'", dbname);
goto error;
}
if (st.sb.st_size < 8) {
file_error(ms, 0, "file `%s' is too small", dbname);
goto error;
}
map->len = (size_t)st.sb.st_size;
if ((map->p = CAST(void *, emalloc(map->len))) == NULL) {
file_oomem(ms, map->len);
goto error;
}
if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) {
file_badread(ms);
goto error;
}
map->len = 0;
#define RET 1
php_stream_close(stream);
stream = NULL;
internal_loaded:
ptr = (uint32_t *)(void *)map->p;
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
file_error(ms, 0, "bad magic in `%s'", dbname);
goto error;
}
needsbyteswap = 1;
} else
needsbyteswap = 0;
if (needsbyteswap)
version = swap4(ptr[1]);
else
version = ptr[1];
if (version != VERSIONNO) {
file_error(ms, 0, "File %d.%d supports only version %d magic "
"files. `%s' is version %d", FILE_VERSION_MAJOR, patchlevel,
VERSIONNO, dbname, version);
goto error;
}
/* php_magic_database is a const, performing writes will segfault. This is for big-endian
machines only, PPC and Sparc specifically. Consider static variable or MINIT in
future. */
if (needsbyteswap && fn == NULL) {
map->p = emalloc(sizeof(php_magic_database));
map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database));
}
if (NULL != fn) {
nentries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
entries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
if ((off_t)(entries * sizeof(struct magic)) != st.sb.st_size) {
file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
dbname, (unsigned long long)st.sb.st_size,
sizeof(struct magic));
goto error;
}
}
map->magic[0] = CAST(struct magic *, map->p) + 1;
nentries = 0;
for (i = 0; i < MAGIC_SETS; i++) {
if (needsbyteswap)
map->nmagic[i] = swap4(ptr[i + 2]);
else
map->nmagic[i] = ptr[i + 2];
if (i != MAGIC_SETS - 1)
map->magic[i + 1] = map->magic[i] + map->nmagic[i];
nentries += map->nmagic[i];
}
if (NULL != fn && entries != nentries + 1) {
file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
dbname, entries, nentries + 1);
goto error;
}
if (needsbyteswap)
for (i = 0; i < MAGIC_SETS; i++)
byteswap(map->magic[i], map->nmagic[i]);
if (dbname) {
efree(dbname);
}
return map;
error:
if (stream) {
php_stream_close(stream);
}
apprentice_unmap(map);
if (dbname) {
efree(dbname);
}
return NULL;
}
|
DoS Mem. Corr.
| 0
|
apprentice_map(struct magic_set *ms, const char *fn)
{
uint32_t *ptr;
uint32_t version, entries, nentries;
int needsbyteswap;
char *dbname = NULL;
struct magic_map *map;
size_t i;
php_stream *stream = NULL;
php_stream_statbuf st;
TSRMLS_FETCH();
if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
file_oomem(ms, sizeof(*map));
efree(map);
goto error;
}
if (fn == NULL) {
map->p = (void *)&php_magic_database;
goto internal_loaded;
}
#ifdef PHP_WIN32
/* Don't bother on windows with php_stream_open_wrapper,
return to give apprentice_load() a chance. */
if (php_stream_stat_path_ex((char *)fn, 0, &st, NULL) == SUCCESS) {
if (st.sb.st_mode & S_IFDIR) {
goto error;
}
}
#endif
dbname = mkdbname(ms, fn, 0);
if (dbname == NULL)
goto error;
stream = php_stream_open_wrapper((char *)fn, "rb", REPORT_ERRORS, NULL);
if (!stream) {
goto error;
}
if (php_stream_stat(stream, &st) < 0) {
file_error(ms, errno, "cannot stat `%s'", dbname);
goto error;
}
if (st.sb.st_size < 8) {
file_error(ms, 0, "file `%s' is too small", dbname);
goto error;
}
map->len = (size_t)st.sb.st_size;
if ((map->p = CAST(void *, emalloc(map->len))) == NULL) {
file_oomem(ms, map->len);
goto error;
}
if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) {
file_badread(ms);
goto error;
}
map->len = 0;
#define RET 1
php_stream_close(stream);
stream = NULL;
internal_loaded:
ptr = (uint32_t *)(void *)map->p;
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
file_error(ms, 0, "bad magic in `%s'", dbname);
goto error;
}
needsbyteswap = 1;
} else
needsbyteswap = 0;
if (needsbyteswap)
version = swap4(ptr[1]);
else
version = ptr[1];
if (version != VERSIONNO) {
file_error(ms, 0, "File %d.%d supports only version %d magic "
"files. `%s' is version %d", FILE_VERSION_MAJOR, patchlevel,
VERSIONNO, dbname, version);
goto error;
}
/* php_magic_database is a const, performing writes will segfault. This is for big-endian
machines only, PPC and Sparc specifically. Consider static variable or MINIT in
future. */
if (needsbyteswap && fn == NULL) {
map->p = emalloc(sizeof(php_magic_database));
map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database));
}
if (NULL != fn) {
nentries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
entries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
if ((off_t)(entries * sizeof(struct magic)) != st.sb.st_size) {
file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
dbname, (unsigned long long)st.sb.st_size,
sizeof(struct magic));
goto error;
}
}
map->magic[0] = CAST(struct magic *, map->p) + 1;
nentries = 0;
for (i = 0; i < MAGIC_SETS; i++) {
if (needsbyteswap)
map->nmagic[i] = swap4(ptr[i + 2]);
else
map->nmagic[i] = ptr[i + 2];
if (i != MAGIC_SETS - 1)
map->magic[i + 1] = map->magic[i] + map->nmagic[i];
nentries += map->nmagic[i];
}
if (NULL != fn && entries != nentries + 1) {
file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
dbname, entries, nentries + 1);
goto error;
}
if (needsbyteswap)
for (i = 0; i < MAGIC_SETS; i++)
byteswap(map->magic[i], map->nmagic[i]);
if (dbname) {
efree(dbname);
}
return map;
error:
if (stream) {
php_stream_close(stream);
}
apprentice_unmap(map);
if (dbname) {
efree(dbname);
}
return NULL;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,857
|
apprentice_sort(const void *a, const void *b)
{
const struct magic_entry *ma = CAST(const struct magic_entry *, a);
const struct magic_entry *mb = CAST(const struct magic_entry *, b);
size_t sa = apprentice_magic_strength(ma->mp);
size_t sb = apprentice_magic_strength(mb->mp);
if (sa == sb)
return 0;
else if (sa > sb)
return -1;
else
return 1;
}
|
DoS Mem. Corr.
| 0
|
apprentice_sort(const void *a, const void *b)
{
const struct magic_entry *ma = CAST(const struct magic_entry *, a);
const struct magic_entry *mb = CAST(const struct magic_entry *, b);
size_t sa = apprentice_magic_strength(ma->mp);
size_t sb = apprentice_magic_strength(mb->mp);
if (sa == sb)
return 0;
else if (sa > sb)
return -1;
else
return 1;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,858
|
apprentice_unmap(struct magic_map *map)
{
if (map == NULL)
return;
if (map->p != php_magic_database) {
if (map->p == NULL) {
int j;
for (j = 0; j < MAGIC_SETS; j++) {
if (map->magic[j]) {
efree(map->magic[j]);
}
}
} else {
efree(map->p);
}
}
efree(map);
}
|
DoS Mem. Corr.
| 0
|
apprentice_unmap(struct magic_map *map)
{
if (map == NULL)
return;
if (map->p != php_magic_database) {
if (map->p == NULL) {
int j;
for (j = 0; j < MAGIC_SETS; j++) {
if (map->magic[j]) {
efree(map->magic[j]);
}
}
} else {
efree(map->p);
}
}
efree(map);
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,859
|
bs1(struct magic *m)
{
m->cont_level = swap2(m->cont_level);
m->offset = swap4((uint32_t)m->offset);
m->in_offset = swap4((uint32_t)m->in_offset);
m->lineno = swap4((uint32_t)m->lineno);
if (IS_LIBMAGIC_STRING(m->type)) {
m->str_range = swap4(m->str_range);
m->str_flags = swap4(m->str_flags);
}
else {
m->value.q = swap8(m->value.q);
m->num_mask = swap8(m->num_mask);
}
}
|
DoS Mem. Corr.
| 0
|
bs1(struct magic *m)
{
m->cont_level = swap2(m->cont_level);
m->offset = swap4((uint32_t)m->offset);
m->in_offset = swap4((uint32_t)m->in_offset);
m->lineno = swap4((uint32_t)m->lineno);
if (IS_LIBMAGIC_STRING(m->type)) {
m->str_range = swap4(m->str_range);
m->str_flags = swap4(m->str_flags);
}
else {
m->value.q = swap8(m->value.q);
m->num_mask = swap8(m->num_mask);
}
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,860
|
byteswap(struct magic *magic, uint32_t nmagic)
{
uint32_t i;
for (i = 0; i < nmagic; i++)
bs1(&magic[i]);
}
|
DoS Mem. Corr.
| 0
|
byteswap(struct magic *magic, uint32_t nmagic)
{
uint32_t i;
for (i = 0; i < nmagic; i++)
bs1(&magic[i]);
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,861
|
check_format(struct magic_set *ms, struct magic *m)
{
char *ptr;
for (ptr = m->desc; *ptr; ptr++)
if (*ptr == '%')
break;
if (*ptr == '\0') {
/* No format string; ok */
return 1;
}
assert(file_nformats == file_nnames);
if (m->type >= file_nformats) {
file_magwarn(ms, "Internal error inconsistency between "
"m->type and format strings");
return -1;
}
if (file_formats[m->type] == FILE_FMT_NONE) {
file_magwarn(ms, "No format string for `%s' with description "
"`%s'", m->desc, file_names[m->type]);
return -1;
}
ptr++;
if (check_format_type(ptr, file_formats[m->type]) == -1) {
/*
* TODO: this error message is unhelpful if the format
* string is not one character long
*/
file_magwarn(ms, "Printf format `%c' is not valid for type "
"`%s' in description `%s'", *ptr ? *ptr : '?',
file_names[m->type], m->desc);
return -1;
}
for (; *ptr; ptr++) {
if (*ptr == '%') {
file_magwarn(ms,
"Too many format strings (should have at most one) "
"for `%s' with description `%s'",
file_names[m->type], m->desc);
return -1;
}
}
return 0;
}
|
DoS Mem. Corr.
| 0
|
check_format(struct magic_set *ms, struct magic *m)
{
char *ptr;
for (ptr = m->desc; *ptr; ptr++)
if (*ptr == '%')
break;
if (*ptr == '\0') {
/* No format string; ok */
return 1;
}
assert(file_nformats == file_nnames);
if (m->type >= file_nformats) {
file_magwarn(ms, "Internal error inconsistency between "
"m->type and format strings");
return -1;
}
if (file_formats[m->type] == FILE_FMT_NONE) {
file_magwarn(ms, "No format string for `%s' with description "
"`%s'", m->desc, file_names[m->type]);
return -1;
}
ptr++;
if (check_format_type(ptr, file_formats[m->type]) == -1) {
/*
* TODO: this error message is unhelpful if the format
* string is not one character long
*/
file_magwarn(ms, "Printf format `%c' is not valid for type "
"`%s' in description `%s'", *ptr ? *ptr : '?',
file_names[m->type], m->desc);
return -1;
}
for (; *ptr; ptr++) {
if (*ptr == '%') {
file_magwarn(ms,
"Too many format strings (should have at most one) "
"for `%s' with description `%s'",
file_names[m->type], m->desc);
return -1;
}
}
return 0;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,862
|
check_format_type(const char *ptr, int type)
{
int quad = 0;
if (*ptr == '\0') {
/* Missing format string; bad */
return -1;
}
switch (type) {
case FILE_FMT_QUAD:
quad = 1;
/*FALLTHROUGH*/
case FILE_FMT_NUM:
if (*ptr == '-')
ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (quad) {
if (*ptr++ != 'l')
return -1;
if (*ptr++ != 'l')
return -1;
}
switch (*ptr++) {
case 'l':
switch (*ptr++) {
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case 'h':
switch (*ptr++) {
case 'h':
switch (*ptr++) {
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case 'd':
return 0;
default:
return -1;
}
case 'i':
case 'c':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case FILE_FMT_FLOAT:
case FILE_FMT_DOUBLE:
if (*ptr == '-')
ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
switch (*ptr++) {
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
return 0;
default:
return -1;
}
case FILE_FMT_STR:
if (*ptr == '-')
ptr++;
while (isdigit((unsigned char )*ptr))
ptr++;
if (*ptr == '.') {
ptr++;
while (isdigit((unsigned char )*ptr))
ptr++;
}
switch (*ptr++) {
case 's':
return 0;
default:
return -1;
}
default:
/* internal error */
abort();
}
/*NOTREACHED*/
return -1;
}
|
DoS Mem. Corr.
| 0
|
check_format_type(const char *ptr, int type)
{
int quad = 0;
if (*ptr == '\0') {
/* Missing format string; bad */
return -1;
}
switch (type) {
case FILE_FMT_QUAD:
quad = 1;
/*FALLTHROUGH*/
case FILE_FMT_NUM:
if (*ptr == '-')
ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (quad) {
if (*ptr++ != 'l')
return -1;
if (*ptr++ != 'l')
return -1;
}
switch (*ptr++) {
case 'l':
switch (*ptr++) {
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case 'h':
switch (*ptr++) {
case 'h':
switch (*ptr++) {
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case 'd':
return 0;
default:
return -1;
}
case 'i':
case 'c':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
default:
return -1;
}
case FILE_FMT_FLOAT:
case FILE_FMT_DOUBLE:
if (*ptr == '-')
ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
if (*ptr == '.')
ptr++;
while (isdigit((unsigned char)*ptr)) ptr++;
switch (*ptr++) {
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
return 0;
default:
return -1;
}
case FILE_FMT_STR:
if (*ptr == '-')
ptr++;
while (isdigit((unsigned char )*ptr))
ptr++;
if (*ptr == '.') {
ptr++;
while (isdigit((unsigned char )*ptr))
ptr++;
}
switch (*ptr++) {
case 's':
return 0;
default:
return -1;
}
default:
/* internal error */
abort();
}
/*NOTREACHED*/
return -1;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,863
|
cmpstrp(const void *p1, const void *p2)
{
return strcmp(*(char *const *)p1, *(char *const *)p2);
}
|
DoS Mem. Corr.
| 0
|
cmpstrp(const void *p1, const void *p2)
{
return strcmp(*(char *const *)p1, *(char *const *)p2);
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,864
|
coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
struct magic **ma, uint32_t *nma)
{
uint32_t i, mentrycount = 0;
size_t slen;
for (i = 0; i < nme; i++)
mentrycount += me[i].cont_count;
slen = sizeof(**ma) * mentrycount;
if ((*ma = CAST(struct magic *, emalloc(slen))) == NULL) {
file_oomem(ms, slen);
return -1;
}
mentrycount = 0;
for (i = 0; i < nme; i++) {
(void)memcpy(*ma + mentrycount, me[i].mp,
me[i].cont_count * sizeof(**ma));
mentrycount += me[i].cont_count;
}
*nma = mentrycount;
return 0;
}
|
DoS Mem. Corr.
| 0
|
coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
struct magic **ma, uint32_t *nma)
{
uint32_t i, mentrycount = 0;
size_t slen;
for (i = 0; i < nme; i++)
mentrycount += me[i].cont_count;
slen = sizeof(**ma) * mentrycount;
if ((*ma = CAST(struct magic *, emalloc(slen))) == NULL) {
file_oomem(ms, slen);
return -1;
}
mentrycount = 0;
for (i = 0; i < nme; i++) {
(void)memcpy(*ma + mentrycount, me[i].mp,
me[i].cont_count * sizeof(**ma));
mentrycount += me[i].cont_count;
}
*nma = mentrycount;
return 0;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,865
|
eatsize(const char **p)
{
const char *l = *p;
if (LOWCASE(*l) == 'u')
l++;
switch (LOWCASE(*l)) {
case 'l': /* long */
case 's': /* short */
case 'h': /* short */
case 'b': /* char/byte */
case 'c': /* char/byte */
l++;
/*FALLTHROUGH*/
default:
break;
}
*p = l;
}
|
DoS Mem. Corr.
| 0
|
eatsize(const char **p)
{
const char *l = *p;
if (LOWCASE(*l) == 'u')
l++;
switch (LOWCASE(*l)) {
case 'l': /* long */
case 's': /* short */
case 'h': /* short */
case 'b': /* char/byte */
case 'c': /* char/byte */
l++;
/*FALLTHROUGH*/
default:
break;
}
*p = l;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,866
|
file_apprentice(struct magic_set *ms, const char *fn, int action)
{
char *p, *mfn;
int file_err, errs = -1;
size_t i;
file_reset(ms);
/* XXX disabling default magic loading so the compiled in data is used */
#if 0
if ((fn = magic_getpath(fn, action)) == NULL)
return -1;
#endif
init_file_tables();
if (fn == NULL)
fn = getenv("MAGIC");
if (fn == NULL) {
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
file_oomem(ms, sizeof(*ms->mlist[i]));
return -1;
}
}
return apprentice_1(ms, fn, action);
}
if ((mfn = estrdup(fn)) == NULL) {
file_oomem(ms, strlen(fn));
return -1;
}
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
file_oomem(ms, sizeof(*ms->mlist[i]));
if (i != 0) {
--i;
do
mlist_free(ms->mlist[i]);
while (i != 0);
}
efree(mfn);
return -1;
}
}
fn = mfn;
while (fn) {
p = strchr(fn, PATHSEP);
if (p)
*p++ = '\0';
if (*fn == '\0')
break;
file_err = apprentice_1(ms, fn, action);
errs = MAX(errs, file_err);
fn = p;
}
efree(mfn);
if (errs == -1) {
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
ms->mlist[i] = NULL;
}
file_error(ms, 0, "could not find any valid magic files!");
return -1;
}
#if 0
/*
* Always leave the database loaded
*/
if (action == FILE_LOAD)
return 0;
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
ms->mlist[i] = NULL;
}
#endif
switch (action) {
case FILE_LOAD:
case FILE_COMPILE:
case FILE_CHECK:
case FILE_LIST:
return 0;
default:
file_error(ms, 0, "Invalid action %d", action);
return -1;
}
}
|
DoS Mem. Corr.
| 0
|
file_apprentice(struct magic_set *ms, const char *fn, int action)
{
char *p, *mfn;
int file_err, errs = -1;
size_t i;
file_reset(ms);
/* XXX disabling default magic loading so the compiled in data is used */
#if 0
if ((fn = magic_getpath(fn, action)) == NULL)
return -1;
#endif
init_file_tables();
if (fn == NULL)
fn = getenv("MAGIC");
if (fn == NULL) {
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
file_oomem(ms, sizeof(*ms->mlist[i]));
return -1;
}
}
return apprentice_1(ms, fn, action);
}
if ((mfn = estrdup(fn)) == NULL) {
file_oomem(ms, strlen(fn));
return -1;
}
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
file_oomem(ms, sizeof(*ms->mlist[i]));
if (i != 0) {
--i;
do
mlist_free(ms->mlist[i]);
while (i != 0);
}
efree(mfn);
return -1;
}
}
fn = mfn;
while (fn) {
p = strchr(fn, PATHSEP);
if (p)
*p++ = '\0';
if (*fn == '\0')
break;
file_err = apprentice_1(ms, fn, action);
errs = MAX(errs, file_err);
fn = p;
}
efree(mfn);
if (errs == -1) {
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
ms->mlist[i] = NULL;
}
file_error(ms, 0, "could not find any valid magic files!");
return -1;
}
#if 0
/*
* Always leave the database loaded
*/
if (action == FILE_LOAD)
return 0;
for (i = 0; i < MAGIC_SETS; i++) {
mlist_free(ms->mlist[i]);
ms->mlist[i] = NULL;
}
#endif
switch (action) {
case FILE_LOAD:
case FILE_COMPILE:
case FILE_CHECK:
case FILE_LIST:
return 0;
default:
file_error(ms, 0, "Invalid action %d", action);
return -1;
}
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,867
|
file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
{
uint32_t i, j;
struct mlist *mlist, *ml;
mlist = ms->mlist[1];
for (ml = mlist->next; ml != mlist; ml = ml->next) {
struct magic *ma = ml->magic;
uint32_t nma = ml->nmagic;
for (i = 0; i < nma; i++) {
if (ma[i].type != FILE_NAME)
continue;
if (strcmp(ma[i].value.s, name) == 0) {
v->magic = &ma[i];
for (j = i + 1; j < nma; j++)
if (ma[j].cont_level == 0)
break;
v->nmagic = j - i;
return 0;
}
}
}
return -1;
}
|
DoS Mem. Corr.
| 0
|
file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
{
uint32_t i, j;
struct mlist *mlist, *ml;
mlist = ms->mlist[1];
for (ml = mlist->next; ml != mlist; ml = ml->next) {
struct magic *ma = ml->magic;
uint32_t nma = ml->nmagic;
for (i = 0; i < nma; i++) {
if (ma[i].type != FILE_NAME)
continue;
if (strcmp(ma[i].value.s, name) == 0) {
v->magic = &ma[i];
for (j = i + 1; j < nma; j++)
if (ma[j].cont_level == 0)
break;
v->nmagic = j - i;
return 0;
}
}
}
return -1;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,868
|
file_ms_alloc(int flags)
{
struct magic_set *ms;
size_t i, len;
if ((ms = CAST(struct magic_set *, ecalloc((size_t)1,
sizeof(struct magic_set)))) == NULL)
return NULL;
if (magic_setflags(ms, flags) == -1) {
errno = EINVAL;
goto free;
}
ms->o.buf = ms->o.pbuf = NULL;
len = (ms->c.len = 10) * sizeof(*ms->c.li);
if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL)
goto free;
ms->event_flags = 0;
ms->error = -1;
for (i = 0; i < MAGIC_SETS; i++)
ms->mlist[i] = NULL;
ms->file = "unknown";
ms->line = 0;
return ms;
free:
efree(ms);
return NULL;
}
|
DoS Mem. Corr.
| 0
|
file_ms_alloc(int flags)
{
struct magic_set *ms;
size_t i, len;
if ((ms = CAST(struct magic_set *, ecalloc((size_t)1,
sizeof(struct magic_set)))) == NULL)
return NULL;
if (magic_setflags(ms, flags) == -1) {
errno = EINVAL;
goto free;
}
ms->o.buf = ms->o.pbuf = NULL;
len = (ms->c.len = 10) * sizeof(*ms->c.li);
if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL)
goto free;
ms->event_flags = 0;
ms->error = -1;
for (i = 0; i < MAGIC_SETS; i++)
ms->mlist[i] = NULL;
ms->file = "unknown";
ms->line = 0;
return ms;
free:
efree(ms);
return NULL;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,869
|
file_ms_free(struct magic_set *ms)
{
size_t i;
if (ms == NULL)
return;
for (i = 0; i < MAGIC_SETS; i++)
mlist_free(ms->mlist[i]);
if (ms->o.pbuf) {
efree(ms->o.pbuf);
}
if (ms->o.buf) {
efree(ms->o.buf);
}
if (ms->c.li) {
efree(ms->c.li);
}
efree(ms);
}
|
DoS Mem. Corr.
| 0
|
file_ms_free(struct magic_set *ms)
{
size_t i;
if (ms == NULL)
return;
for (i = 0; i < MAGIC_SETS; i++)
mlist_free(ms->mlist[i]);
if (ms->o.pbuf) {
efree(ms->o.pbuf);
}
if (ms->o.buf) {
efree(ms->o.buf);
}
if (ms->c.li) {
efree(ms->c.li);
}
efree(ms);
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,870
|
file_pstring_get_length(const struct magic *m, const char *s)
{
size_t len = 0;
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
len = *s;
break;
case PSTRING_2_LE:
len = (s[1] << 8) | s[0];
break;
case PSTRING_2_BE:
len = (s[0] << 8) | s[1];
break;
case PSTRING_4_LE:
len = (s[3] << 24) | (s[2] << 16) | (s[1] << 8) | s[0];
break;
case PSTRING_4_BE:
len = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
break;
default:
abort(); /* Impossible */
}
if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
len -= file_pstring_length_size(m);
return len;
}
|
DoS Mem. Corr.
| 0
|
file_pstring_get_length(const struct magic *m, const char *s)
{
size_t len = 0;
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
len = *s;
break;
case PSTRING_2_LE:
len = (s[1] << 8) | s[0];
break;
case PSTRING_2_BE:
len = (s[0] << 8) | s[1];
break;
case PSTRING_4_LE:
len = (s[3] << 24) | (s[2] << 16) | (s[1] << 8) | s[0];
break;
case PSTRING_4_BE:
len = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
break;
default:
abort(); /* Impossible */
}
if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
len -= file_pstring_length_size(m);
return len;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,871
|
file_pstring_length_size(const struct magic *m)
{
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
return 1;
case PSTRING_2_LE:
case PSTRING_2_BE:
return 2;
case PSTRING_4_LE:
case PSTRING_4_BE:
return 4;
default:
abort(); /* Impossible */
return 1;
}
}
|
DoS Mem. Corr.
| 0
|
file_pstring_length_size(const struct magic *m)
{
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
return 1;
case PSTRING_2_LE:
case PSTRING_2_BE:
return 2;
case PSTRING_4_LE:
case PSTRING_4_BE:
return 4;
default:
abort(); /* Impossible */
return 1;
}
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,872
|
file_showstr(FILE *fp, const char *s, size_t len)
{
char c;
for (;;) {
if (len == ~0U) {
c = *s++;
if (c == '\0')
break;
}
else {
if (len-- == 0)
break;
c = *s++;
}
if (c >= 040 && c <= 0176) /* TODO isprint && !iscntrl */
(void) fputc(c, fp);
else {
(void) fputc('\\', fp);
switch (c) {
case '\a':
(void) fputc('a', fp);
break;
case '\b':
(void) fputc('b', fp);
break;
case '\f':
(void) fputc('f', fp);
break;
case '\n':
(void) fputc('n', fp);
break;
case '\r':
(void) fputc('r', fp);
break;
case '\t':
(void) fputc('t', fp);
break;
case '\v':
(void) fputc('v', fp);
break;
default:
(void) fprintf(fp, "%.3o", c & 0377);
break;
}
}
}
}
|
DoS Mem. Corr.
| 0
|
file_showstr(FILE *fp, const char *s, size_t len)
{
char c;
for (;;) {
if (len == ~0U) {
c = *s++;
if (c == '\0')
break;
}
else {
if (len-- == 0)
break;
c = *s++;
}
if (c >= 040 && c <= 0176) /* TODO isprint && !iscntrl */
(void) fputc(c, fp);
else {
(void) fputc('\\', fp);
switch (c) {
case '\a':
(void) fputc('a', fp);
break;
case '\b':
(void) fputc('b', fp);
break;
case '\f':
(void) fputc('f', fp);
break;
case '\n':
(void) fputc('n', fp);
break;
case '\r':
(void) fputc('r', fp);
break;
case '\t':
(void) fputc('t', fp);
break;
case '\v':
(void) fputc('v', fp);
break;
default:
(void) fprintf(fp, "%.3o", c & 0377);
break;
}
}
}
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,873
|
file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
{
if (!(m->flag & UNSIGNED)) {
switch(m->type) {
/*
* Do not remove the casts below. They are
* vital. When later compared with the data,
* the sign extension must have happened.
*/
case FILE_BYTE:
v = (signed char) v;
break;
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
v = (short) v;
break;
case FILE_DATE:
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
case FILE_LDATE:
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
case FILE_LONG:
case FILE_BELONG:
case FILE_LELONG:
case FILE_MELONG:
case FILE_FLOAT:
case FILE_BEFLOAT:
case FILE_LEFLOAT:
v = (int32_t) v;
break;
case FILE_QUAD:
case FILE_BEQUAD:
case FILE_LEQUAD:
case FILE_QDATE:
case FILE_QLDATE:
case FILE_QWDATE:
case FILE_BEQDATE:
case FILE_BEQLDATE:
case FILE_BEQWDATE:
case FILE_LEQDATE:
case FILE_LEQLDATE:
case FILE_LEQWDATE:
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
v = (int64_t) v;
break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_BESTRING16:
case FILE_LESTRING16:
case FILE_REGEX:
case FILE_SEARCH:
case FILE_DEFAULT:
case FILE_INDIRECT:
case FILE_NAME:
case FILE_USE:
case FILE_CLEAR:
break;
default:
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "cannot happen: m->type=%d\n",
m->type);
return ~0U;
}
}
return v;
}
|
DoS Mem. Corr.
| 0
|
file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
{
if (!(m->flag & UNSIGNED)) {
switch(m->type) {
/*
* Do not remove the casts below. They are
* vital. When later compared with the data,
* the sign extension must have happened.
*/
case FILE_BYTE:
v = (signed char) v;
break;
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
v = (short) v;
break;
case FILE_DATE:
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
case FILE_LDATE:
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
case FILE_LONG:
case FILE_BELONG:
case FILE_LELONG:
case FILE_MELONG:
case FILE_FLOAT:
case FILE_BEFLOAT:
case FILE_LEFLOAT:
v = (int32_t) v;
break;
case FILE_QUAD:
case FILE_BEQUAD:
case FILE_LEQUAD:
case FILE_QDATE:
case FILE_QLDATE:
case FILE_QWDATE:
case FILE_BEQDATE:
case FILE_BEQLDATE:
case FILE_BEQWDATE:
case FILE_LEQDATE:
case FILE_LEQLDATE:
case FILE_LEQWDATE:
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
v = (int64_t) v;
break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_BESTRING16:
case FILE_LESTRING16:
case FILE_REGEX:
case FILE_SEARCH:
case FILE_DEFAULT:
case FILE_INDIRECT:
case FILE_NAME:
case FILE_USE:
case FILE_CLEAR:
break;
default:
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "cannot happen: m->type=%d\n",
m->type);
return ~0U;
}
}
return v;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,874
|
get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
{
const struct type_tbl_s *p;
for (p = tbl; p->len; p++) {
if (strncmp(l, p->name, p->len) == 0) {
if (t)
*t = l + p->len;
break;
}
}
return p->type;
}
|
DoS Mem. Corr.
| 0
|
get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
{
const struct type_tbl_s *p;
for (p = tbl; p->len; p++) {
if (strncmp(l, p->name, p->len) == 0) {
if (t)
*t = l + p->len;
break;
}
}
return p->type;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,875
|
getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
{
const char *origs = s;
char *p = m->value.s;
size_t plen = sizeof(m->value.s);
char *origp = p;
char *pmax = p + plen - 1;
int c;
int val;
while ((c = *s++) != '\0') {
if (isspace((unsigned char) c))
break;
if (p >= pmax) {
file_error(ms, 0, "string too long: `%s'", origs);
return NULL;
}
if (c == '\\') {
switch(c = *s++) {
case '\0':
if (warn)
file_magwarn(ms, "incomplete escape");
goto out;
case '\t':
if (warn) {
file_magwarn(ms,
"escaped tab found, use \\t instead");
warn = 0; /* already did */
}
/*FALLTHROUGH*/
default:
if (warn) {
if (isprint((unsigned char)c)) {
/* Allow escaping of
* ``relations'' */
if (strchr("<>&^=!", c) == NULL
&& (m->type != FILE_REGEX ||
strchr("[]().*?^$|{}", c)
== NULL)) {
file_magwarn(ms, "no "
"need to escape "
"`%c'", c);
}
} else {
file_magwarn(ms,
"unknown escape sequence: "
"\\%03o", c);
}
}
/*FALLTHROUGH*/
/* space, perhaps force people to use \040? */
case ' ':
#if 0
/*
* Other things people escape, but shouldn't need to,
* so we disallow them
*/
case '\'':
case '"':
case '?':
#endif
/* Relations */
case '>':
case '<':
case '&':
case '^':
case '=':
case '!':
/* and baskslash itself */
case '\\':
*p++ = (char) c;
break;
case 'a':
*p++ = '\a';
break;
case 'b':
*p++ = '\b';
break;
case 'f':
*p++ = '\f';
break;
case 'n':
*p++ = '\n';
break;
case 'r':
*p++ = '\r';
break;
case 't':
*p++ = '\t';
break;
case 'v':
*p++ = '\v';
break;
/* \ and up to 3 octal digits */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
val = c - '0';
c = *s++; /* try for 2 */
if (c >= '0' && c <= '7') {
val = (val << 3) | (c - '0');
c = *s++; /* try for 3 */
if (c >= '0' && c <= '7')
val = (val << 3) | (c-'0');
else
--s;
}
else
--s;
*p++ = (char)val;
break;
/* \x and up to 2 hex digits */
case 'x':
val = 'x'; /* Default if no digits */
c = hextoint(*s++); /* Get next char */
if (c >= 0) {
val = c;
c = hextoint(*s++);
if (c >= 0)
val = (val << 4) + c;
else
--s;
} else
--s;
*p++ = (char)val;
break;
}
} else
*p++ = (char)c;
}
out:
*p = '\0';
m->vallen = CAST(unsigned char, (p - origp));
if (m->type == FILE_PSTRING)
m->vallen += (unsigned char)file_pstring_length_size(m);
return s;
}
|
DoS Mem. Corr.
| 0
|
getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
{
const char *origs = s;
char *p = m->value.s;
size_t plen = sizeof(m->value.s);
char *origp = p;
char *pmax = p + plen - 1;
int c;
int val;
while ((c = *s++) != '\0') {
if (isspace((unsigned char) c))
break;
if (p >= pmax) {
file_error(ms, 0, "string too long: `%s'", origs);
return NULL;
}
if (c == '\\') {
switch(c = *s++) {
case '\0':
if (warn)
file_magwarn(ms, "incomplete escape");
goto out;
case '\t':
if (warn) {
file_magwarn(ms,
"escaped tab found, use \\t instead");
warn = 0; /* already did */
}
/*FALLTHROUGH*/
default:
if (warn) {
if (isprint((unsigned char)c)) {
/* Allow escaping of
* ``relations'' */
if (strchr("<>&^=!", c) == NULL
&& (m->type != FILE_REGEX ||
strchr("[]().*?^$|{}", c)
== NULL)) {
file_magwarn(ms, "no "
"need to escape "
"`%c'", c);
}
} else {
file_magwarn(ms,
"unknown escape sequence: "
"\\%03o", c);
}
}
/*FALLTHROUGH*/
/* space, perhaps force people to use \040? */
case ' ':
#if 0
/*
* Other things people escape, but shouldn't need to,
* so we disallow them
*/
case '\'':
case '"':
case '?':
#endif
/* Relations */
case '>':
case '<':
case '&':
case '^':
case '=':
case '!':
/* and baskslash itself */
case '\\':
*p++ = (char) c;
break;
case 'a':
*p++ = '\a';
break;
case 'b':
*p++ = '\b';
break;
case 'f':
*p++ = '\f';
break;
case 'n':
*p++ = '\n';
break;
case 'r':
*p++ = '\r';
break;
case 't':
*p++ = '\t';
break;
case 'v':
*p++ = '\v';
break;
/* \ and up to 3 octal digits */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
val = c - '0';
c = *s++; /* try for 2 */
if (c >= '0' && c <= '7') {
val = (val << 3) | (c - '0');
c = *s++; /* try for 3 */
if (c >= '0' && c <= '7')
val = (val << 3) | (c-'0');
else
--s;
}
else
--s;
*p++ = (char)val;
break;
/* \x and up to 2 hex digits */
case 'x':
val = 'x'; /* Default if no digits */
c = hextoint(*s++); /* Get next char */
if (c >= 0) {
val = c;
c = hextoint(*s++);
if (c >= 0)
val = (val << 4) + c;
else
--s;
} else
--s;
*p++ = (char)val;
break;
}
} else
*p++ = (char)c;
}
out:
*p = '\0';
m->vallen = CAST(unsigned char, (p - origp));
if (m->type == FILE_PSTRING)
m->vallen += (unsigned char)file_pstring_length_size(m);
return s;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,876
|
hextoint(int c)
{
if (!isascii((unsigned char) c))
return -1;
if (isdigit((unsigned char) c))
return c - '0';
if ((c >= 'a') && (c <= 'f'))
return c + 10 - 'a';
if (( c>= 'A') && (c <= 'F'))
return c + 10 - 'A';
return -1;
}
|
DoS Mem. Corr.
| 0
|
hextoint(int c)
{
if (!isascii((unsigned char) c))
return -1;
if (isdigit((unsigned char) c))
return c - '0';
if ((c >= 'a') && (c <= 'f'))
return c + 10 - 'a';
if (( c>= 'A') && (c <= 'F'))
return c + 10 - 'A';
return -1;
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,877
|
magic_entry_free(struct magic_entry *me, uint32_t nme)
{
uint32_t i;
if (me == NULL)
return;
for (i = 0; i < nme; i++)
efree(me[i].mp);
efree(me);
}
|
DoS Mem. Corr.
| 0
|
magic_entry_free(struct magic_entry *me, uint32_t nme)
{
uint32_t i;
if (me == NULL)
return;
for (i = 0; i < nme; i++)
efree(me[i].mp);
efree(me);
}
|
@@ -1197,7 +1197,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((filearr = CAST(char **,
erealloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
- efree(mfn);
php_stream_closedir(dir);
errs++;
goto out;
|
CWE-17
| null | null |
5,878
|
ZEND_API zval *_zend_ts_hash_add_or_update(TsHashTable *ht, zend_string *key, zval *pData, int flag ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = _zend_hash_add_or_update(TS_HASH(ht), key, pData, flag ZEND_FILE_LINE_RELAY_CC);
end_write(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API zval *_zend_ts_hash_add_or_update(TsHashTable *ht, zend_string *key, zval *pData, int flag ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = _zend_hash_add_or_update(TS_HASH(ht), key, pData, flag ZEND_FILE_LINE_RELAY_CC);
end_write(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,879
|
ZEND_API zval *_zend_ts_hash_index_add_or_update(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = _zend_hash_index_add_or_update(TS_HASH(ht), h, pData, flag ZEND_FILE_LINE_RELAY_CC);
end_write(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API zval *_zend_ts_hash_index_add_or_update(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = _zend_hash_index_add_or_update(TS_HASH(ht), h, pData, flag ZEND_FILE_LINE_RELAY_CC);
end_write(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,880
|
ZEND_API void _zend_ts_hash_init(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC)
{
#ifdef ZTS
ht->mx_reader = tsrm_mutex_alloc();
ht->mx_writer = tsrm_mutex_alloc();
ht->reader = 0;
#endif
_zend_hash_init(TS_HASH(ht), nSize, pDestructor, persistent ZEND_FILE_LINE_RELAY_CC);
}
|
DoS
| 0
|
ZEND_API void _zend_ts_hash_init(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC)
{
#ifdef ZTS
ht->mx_reader = tsrm_mutex_alloc();
ht->mx_writer = tsrm_mutex_alloc();
ht->reader = 0;
#endif
_zend_hash_init(TS_HASH(ht), nSize, pDestructor, persistent ZEND_FILE_LINE_RELAY_CC);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,881
|
ZEND_API void _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC)
{
#ifdef ZTS
ht->mx_reader = tsrm_mutex_alloc();
ht->mx_writer = tsrm_mutex_alloc();
ht->reader = 0;
#endif
_zend_hash_init_ex(TS_HASH(ht), nSize, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_RELAY_CC);
}
|
DoS
| 0
|
ZEND_API void _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC)
{
#ifdef ZTS
ht->mx_reader = tsrm_mutex_alloc();
ht->mx_writer = tsrm_mutex_alloc();
ht->reader = 0;
#endif
_zend_hash_init_ex(TS_HASH(ht), nSize, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_RELAY_CC);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,882
|
ZEND_API zval *_zend_ts_hash_str_update(TsHashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = zend_hash_str_update(TS_HASH(ht), key, len, pData);
end_write(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API zval *_zend_ts_hash_str_update(TsHashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC)
{
zval *retval;
begin_write(ht);
retval = zend_hash_str_update(TS_HASH(ht), key, len, pData);
end_write(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,883
|
static void begin_read(TsHashTable *ht)
{
#ifdef ZTS
tsrm_mutex_lock(ht->mx_reader);
if ((++(ht->reader)) == 1) {
tsrm_mutex_lock(ht->mx_writer);
}
tsrm_mutex_unlock(ht->mx_reader);
#endif
}
|
DoS
| 0
|
static void begin_read(TsHashTable *ht)
{
#ifdef ZTS
tsrm_mutex_lock(ht->mx_reader);
if ((++(ht->reader)) == 1) {
tsrm_mutex_lock(ht->mx_writer);
}
tsrm_mutex_unlock(ht->mx_reader);
#endif
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,884
|
static void end_write(TsHashTable *ht)
{
#ifdef ZTS
tsrm_mutex_unlock(ht->mx_writer);
#endif
}
|
DoS
| 0
|
static void end_write(TsHashTable *ht)
{
#ifdef ZTS
tsrm_mutex_unlock(ht->mx_writer);
#endif
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,885
|
ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func)
{
begin_write(ht);
zend_hash_apply(TS_HASH(ht), apply_func);
end_write(ht);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func)
{
begin_write(ht);
zend_hash_apply(TS_HASH(ht), apply_func);
end_write(ht);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,886
|
ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void *argument)
{
begin_write(ht);
zend_hash_apply_with_argument(TS_HASH(ht), apply_func, argument);
end_write(ht);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void *argument)
{
begin_write(ht);
zend_hash_apply_with_argument(TS_HASH(ht), apply_func, argument);
end_write(ht);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,887
|
ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht, apply_func_args_t apply_func, int num_args, ...)
{
va_list args;
va_start(args, num_args);
begin_write(ht);
zend_hash_apply_with_arguments(TS_HASH(ht), apply_func, num_args, args);
end_write(ht);
va_end(args);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht, apply_func_args_t apply_func, int num_args, ...)
{
va_list args;
va_start(args, num_args);
begin_write(ht);
zend_hash_apply_with_arguments(TS_HASH(ht), apply_func, num_args, args);
end_write(ht);
va_end(args);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,888
|
ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered)
{
int retval;
begin_read(ht1);
begin_read(ht2);
retval = zend_hash_compare(TS_HASH(ht1), TS_HASH(ht2), compar, ordered);
end_read(ht2);
end_read(ht1);
return retval;
}
|
DoS
| 0
|
ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered)
{
int retval;
begin_read(ht1);
begin_read(ht2);
retval = zend_hash_compare(TS_HASH(ht1), TS_HASH(ht2), compar, ordered);
end_read(ht2);
end_read(ht1);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,889
|
ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor)
{
begin_read(source);
begin_write(target);
zend_hash_copy(TS_HASH(target), TS_HASH(source), pCopyConstructor);
end_write(target);
end_read(source);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor)
{
begin_read(source);
begin_write(target);
zend_hash_copy(TS_HASH(target), TS_HASH(source), pCopyConstructor);
end_write(target);
end_read(source);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,890
|
ZEND_API void zend_ts_hash_copy_to_hash(HashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor)
{
begin_read(source);
zend_hash_copy(target, TS_HASH(source), pCopyConstructor);
end_read(source);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_copy_to_hash(HashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor)
{
begin_read(source);
zend_hash_copy(target, TS_HASH(source), pCopyConstructor);
end_read(source);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,891
|
ZEND_API int zend_ts_hash_del(TsHashTable *ht, zend_string *key)
{
int retval;
begin_write(ht);
retval = zend_hash_del(TS_HASH(ht), key);
end_write(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API int zend_ts_hash_del(TsHashTable *ht, zend_string *key)
{
int retval;
begin_write(ht);
retval = zend_hash_del(TS_HASH(ht), key);
end_write(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,892
|
ZEND_API void zend_ts_hash_destroy(TsHashTable *ht)
{
begin_write(ht);
zend_hash_destroy(TS_HASH(ht));
end_write(ht);
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
tsrm_mutex_free(ht->mx_writer);
#endif
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_destroy(TsHashTable *ht)
{
begin_write(ht);
zend_hash_destroy(TS_HASH(ht));
end_write(ht);
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
tsrm_mutex_free(ht->mx_writer);
#endif
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,893
|
ZEND_API zval *zend_ts_hash_find(TsHashTable *ht, zend_string *key)
{
zval *retval;
begin_read(ht);
retval = zend_hash_find(TS_HASH(ht), key);
end_read(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API zval *zend_ts_hash_find(TsHashTable *ht, zend_string *key)
{
zval *retval;
begin_read(ht);
retval = zend_hash_find(TS_HASH(ht), key);
end_read(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,894
|
ZEND_API int zend_ts_hash_index_del(TsHashTable *ht, zend_ulong h)
{
int retval;
begin_write(ht);
retval = zend_hash_index_del(TS_HASH(ht), h);
end_write(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API int zend_ts_hash_index_del(TsHashTable *ht, zend_ulong h)
{
int retval;
begin_write(ht);
retval = zend_hash_index_del(TS_HASH(ht), h);
end_write(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,895
|
ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, zend_ulong h)
{
int retval;
begin_read(ht);
retval = zend_hash_index_exists(TS_HASH(ht), h);
end_read(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, zend_ulong h)
{
int retval;
begin_read(ht);
retval = zend_hash_index_exists(TS_HASH(ht), h);
end_read(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,896
|
ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, int overwrite)
{
begin_read(source);
begin_write(target);
zend_hash_merge(TS_HASH(target), TS_HASH(source), pCopyConstructor, overwrite);
end_write(target);
end_read(source);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, int overwrite)
{
begin_read(source);
begin_write(target);
zend_hash_merge(TS_HASH(target), TS_HASH(source), pCopyConstructor, overwrite);
end_write(target);
end_read(source);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,897
|
ZEND_API void zend_ts_hash_merge_ex(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam)
{
begin_read(source);
begin_write(target);
zend_hash_merge_ex(TS_HASH(target), TS_HASH(source), pCopyConstructor, pMergeSource, pParam);
end_write(target);
end_read(source);
}
|
DoS
| 0
|
ZEND_API void zend_ts_hash_merge_ex(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam)
{
begin_read(source);
begin_write(target);
zend_hash_merge_ex(TS_HASH(target), TS_HASH(source), pCopyConstructor, pMergeSource, pParam);
end_write(target);
end_read(source);
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,898
|
ZEND_API zval *zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag)
{
zval *retval;
begin_read(ht);
retval = zend_hash_minmax(TS_HASH(ht), compar, flag);
end_read(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API zval *zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag)
{
zval *retval;
begin_read(ht);
retval = zend_hash_minmax(TS_HASH(ht), compar, flag);
end_read(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
5,899
|
ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht)
{
int retval;
begin_read(ht);
retval = zend_hash_num_elements(TS_HASH(ht));
end_read(ht);
return retval;
}
|
DoS
| 0
|
ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht)
{
int retval;
begin_read(ht);
retval = zend_hash_num_elements(TS_HASH(ht));
end_read(ht);
return retval;
}
|
@@ -140,7 +140,7 @@ ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
#ifdef ZTS
tsrm_mutex_free(ht->mx_reader);
- tsrm_mutex_free(ht->mx_reader);
+ tsrm_mutex_free(ht->mx_writer);
#endif
}
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.