idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
4,400
|
dbus_g_proxy_manager_unmonitor_name_owner (DBusGProxyManager *manager,
const char *name)
{
DBusGProxyNameOwnerInfo *info;
const char *owner;
gboolean ret;
ret = dbus_g_proxy_manager_lookup_name_owner (manager, name, &info, &owner);
g_assert (ret);
g_assert (info != NULL);
g_assert (owner != NULL);
info->refcount--;
if (info->refcount == 0)
{
GSList *names;
GSList *link;
names = g_hash_table_lookup (manager->owner_names, owner);
link = g_slist_find_custom (names, name, find_name_in_info);
names = g_slist_delete_link (names, link);
if (names != NULL)
g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
else
g_hash_table_remove (manager->owner_names, owner);
g_free (info->name);
g_free (info);
}
}
|
+Priv
| 0
|
dbus_g_proxy_manager_unmonitor_name_owner (DBusGProxyManager *manager,
const char *name)
{
DBusGProxyNameOwnerInfo *info;
const char *owner;
gboolean ret;
ret = dbus_g_proxy_manager_lookup_name_owner (manager, name, &info, &owner);
g_assert (ret);
g_assert (info != NULL);
g_assert (owner != NULL);
info->refcount--;
if (info->refcount == 0)
{
GSList *names;
GSList *link;
names = g_hash_table_lookup (manager->owner_names, owner);
link = g_slist_find_custom (names, name, find_name_in_info);
names = g_slist_delete_link (names, link);
if (names != NULL)
g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
else
g_hash_table_remove (manager->owner_names, owner);
g_free (info->name);
g_free (info);
}
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,401
|
dbus_g_proxy_manager_unref (DBusGProxyManager *manager)
{
g_assert (manager != NULL);
g_assert (manager->refcount > 0);
LOCK_MANAGER (manager);
manager->refcount -= 1;
if (manager->refcount == 0)
{
UNLOCK_MANAGER (manager);
if (manager->bus_proxy)
g_object_unref (manager->bus_proxy);
if (manager->proxy_lists)
{
/* can't have any proxies left since they hold
* a reference to the proxy manager.
*/
g_assert (g_hash_table_size (manager->proxy_lists) == 0);
g_hash_table_destroy (manager->proxy_lists);
manager->proxy_lists = NULL;
}
if (manager->owner_match_rules)
{
/* Since we destroyed all proxies, none can be tracking
* name owners
*/
g_assert (g_hash_table_size (manager->owner_match_rules) == 0);
g_hash_table_destroy (manager->owner_match_rules);
manager->owner_match_rules = NULL;
}
if (manager->owner_names)
{
/* Since we destroyed all proxies, none can be tracking
* name owners
*/
g_assert (g_hash_table_size (manager->owner_names) == 0);
g_hash_table_destroy (manager->owner_names);
manager->owner_names = NULL;
}
g_assert (manager->unassociated_proxies == NULL);
g_static_mutex_free (&manager->lock);
g_static_mutex_lock (&connection_g_proxy_lock);
dbus_connection_remove_filter (manager->connection, dbus_g_proxy_manager_filter,
manager);
dbus_connection_set_data (manager->connection,
g_proxy_manager_slot,
NULL, NULL);
g_static_mutex_unlock (&connection_g_proxy_lock);
dbus_connection_unref (manager->connection);
g_free (manager);
dbus_connection_free_data_slot (&g_proxy_manager_slot);
}
else
{
UNLOCK_MANAGER (manager);
}
}
|
+Priv
| 0
|
dbus_g_proxy_manager_unref (DBusGProxyManager *manager)
{
g_assert (manager != NULL);
g_assert (manager->refcount > 0);
LOCK_MANAGER (manager);
manager->refcount -= 1;
if (manager->refcount == 0)
{
UNLOCK_MANAGER (manager);
if (manager->bus_proxy)
g_object_unref (manager->bus_proxy);
if (manager->proxy_lists)
{
/* can't have any proxies left since they hold
* a reference to the proxy manager.
*/
g_assert (g_hash_table_size (manager->proxy_lists) == 0);
g_hash_table_destroy (manager->proxy_lists);
manager->proxy_lists = NULL;
}
if (manager->owner_match_rules)
{
/* Since we destroyed all proxies, none can be tracking
* name owners
*/
g_assert (g_hash_table_size (manager->owner_match_rules) == 0);
g_hash_table_destroy (manager->owner_match_rules);
manager->owner_match_rules = NULL;
}
if (manager->owner_names)
{
/* Since we destroyed all proxies, none can be tracking
* name owners
*/
g_assert (g_hash_table_size (manager->owner_names) == 0);
g_hash_table_destroy (manager->owner_names);
manager->owner_names = NULL;
}
g_assert (manager->unassociated_proxies == NULL);
g_static_mutex_free (&manager->lock);
g_static_mutex_lock (&connection_g_proxy_lock);
dbus_connection_remove_filter (manager->connection, dbus_g_proxy_manager_filter,
manager);
dbus_connection_set_data (manager->connection,
g_proxy_manager_slot,
NULL, NULL);
g_static_mutex_unlock (&connection_g_proxy_lock);
dbus_connection_unref (manager->connection);
g_free (manager);
dbus_connection_free_data_slot (&g_proxy_manager_slot);
}
else
{
UNLOCK_MANAGER (manager);
}
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,402
|
g_proxy_get_signal_match_rule (DBusGProxy *proxy)
{
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
/* FIXME Escaping is required here */
if (priv->name)
return g_strdup_printf ("type='signal',sender='%s',path='%s',interface='%s'",
priv->name, priv->path, priv->interface);
else
return g_strdup_printf ("type='signal',path='%s',interface='%s'",
priv->path, priv->interface);
}
|
+Priv
| 0
|
g_proxy_get_signal_match_rule (DBusGProxy *proxy)
{
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
/* FIXME Escaping is required here */
if (priv->name)
return g_strdup_printf ("type='signal',sender='%s',path='%s',interface='%s'",
priv->name, priv->path, priv->interface);
else
return g_strdup_printf ("type='signal',path='%s',interface='%s'",
priv->path, priv->interface);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,403
|
g_proxy_list_free (DBusGProxyList *list)
{
/* we don't hold a reference to the proxies in the list,
* as they ref the GProxyManager
*/
g_slist_free (list->proxies);
g_free (list);
}
|
+Priv
| 0
|
g_proxy_list_free (DBusGProxyList *list)
{
/* we don't hold a reference to the proxies in the list,
* as they ref the GProxyManager
*/
g_slist_free (list->proxies);
g_free (list);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,404
|
g_proxy_list_new (DBusGProxy *first_proxy)
{
DBusGProxyList *list;
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(first_proxy);
list = (void*) tristring_alloc_from_strings (G_STRUCT_OFFSET (DBusGProxyList, name),
priv->name,
priv->path,
priv->interface);
list->proxies = NULL;
return list;
}
|
+Priv
| 0
|
g_proxy_list_new (DBusGProxy *first_proxy)
{
DBusGProxyList *list;
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(first_proxy);
list = (void*) tristring_alloc_from_strings (G_STRUCT_OFFSET (DBusGProxyList, name),
priv->name,
priv->path,
priv->interface);
list->proxies = NULL;
return list;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,405
|
get_name_owner (DBusConnection *connection,
const char *name,
GError **error)
{
DBusError derror;
DBusMessage *request, *reply;
char *base_name;
dbus_error_init (&derror);
base_name = NULL;
reply = NULL;
request = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner");
if (request == NULL)
g_error ("Out of memory");
if (!dbus_message_append_args (request,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
g_error ("Out of memory");
reply =
dbus_connection_send_with_reply_and_block (connection,
request,
2000, &derror);
if (reply == NULL)
goto error;
if (dbus_set_error_from_message (&derror, reply))
goto error;
if (!dbus_message_get_args (reply, &derror,
DBUS_TYPE_STRING, &base_name,
DBUS_TYPE_INVALID))
goto error;
base_name = g_strdup (base_name);
goto out;
error:
g_assert (dbus_error_is_set (&derror));
dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
out:
if (request)
dbus_message_unref (request);
if (reply)
dbus_message_unref (reply);
return base_name;
}
|
+Priv
| 0
|
get_name_owner (DBusConnection *connection,
const char *name,
GError **error)
{
DBusError derror;
DBusMessage *request, *reply;
char *base_name;
dbus_error_init (&derror);
base_name = NULL;
reply = NULL;
request = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner");
if (request == NULL)
g_error ("Out of memory");
if (!dbus_message_append_args (request,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
g_error ("Out of memory");
reply =
dbus_connection_send_with_reply_and_block (connection,
request,
2000, &derror);
if (reply == NULL)
goto error;
if (dbus_set_error_from_message (&derror, reply))
goto error;
if (!dbus_message_get_args (reply, &derror,
DBUS_TYPE_STRING, &base_name,
DBUS_TYPE_INVALID))
goto error;
base_name = g_strdup (base_name);
goto out;
error:
g_assert (dbus_error_is_set (&derror));
dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
out:
if (request)
dbus_message_unref (request);
if (reply)
dbus_message_unref (reply);
return base_name;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,406
|
get_owner_match_rule (const gchar *name)
{
return g_strdup_printf ("type='signal',sender='" DBUS_SERVICE_DBUS
"',path='" DBUS_PATH_DBUS
"',interface='" DBUS_INTERFACE_DBUS
"',member='NameOwnerChanged'"
",arg0='%s'", name);
}
|
+Priv
| 0
|
get_owner_match_rule (const gchar *name)
{
return g_strdup_printf ("type='signal',sender='" DBUS_SERVICE_DBUS
"',path='" DBUS_PATH_DBUS
"',interface='" DBUS_INTERFACE_DBUS
"',member='NameOwnerChanged'"
",arg0='%s'", name);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,407
|
guint_slice_free (gpointer data)
{
g_slice_free (guint, data);
}
|
+Priv
| 0
|
guint_slice_free (gpointer data)
{
g_slice_free (guint, data);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,408
|
insert_nameinfo (DBusGProxyManager *manager,
const char *owner,
DBusGProxyNameOwnerInfo *info)
{
GSList *names;
gboolean insert;
names = g_hash_table_lookup (manager->owner_names, owner);
/* Only need to g_hash_table_insert the first time */
insert = (names == NULL);
names = g_slist_append (names, info);
if (insert)
g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
}
|
+Priv
| 0
|
insert_nameinfo (DBusGProxyManager *manager,
const char *owner,
DBusGProxyNameOwnerInfo *info)
{
GSList *names;
gboolean insert;
names = g_hash_table_lookup (manager->owner_names, owner);
/* Only need to g_hash_table_insert the first time */
insert = (names == NULL);
names = g_slist_append (names, info);
if (insert)
g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,409
|
list_proxies_foreach (gpointer key,
gpointer value,
gpointer user_data)
{
DBusGProxyList *list;
GSList **ret;
GSList *tmp;
list = value;
ret = user_data;
tmp = list->proxies;
while (tmp != NULL)
{
DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
g_object_ref (proxy);
*ret = g_slist_prepend (*ret, proxy);
tmp = tmp->next;
}
}
|
+Priv
| 0
|
list_proxies_foreach (gpointer key,
gpointer value,
gpointer user_data)
{
DBusGProxyList *list;
GSList **ret;
GSList *tmp;
list = value;
ret = user_data;
tmp = list->proxies;
while (tmp != NULL)
{
DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
g_object_ref (proxy);
*ret = g_slist_prepend (*ret, proxy);
tmp = tmp->next;
}
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,410
|
name_owner_foreach (gpointer key, gpointer val, gpointer data)
{
const char *owner;
DBusGProxyNameOwnerForeachData *foreach_data;
GSList *names;
GSList *link;
owner = key;
names = val;
foreach_data = data;
if (foreach_data->owner != NULL)
return;
g_assert (foreach_data->info == NULL);
link = g_slist_find_custom (names, foreach_data->name, find_name_in_info);
if (link)
{
foreach_data->owner = owner;
foreach_data->info = link->data;
}
}
|
+Priv
| 0
|
name_owner_foreach (gpointer key, gpointer val, gpointer data)
{
const char *owner;
DBusGProxyNameOwnerForeachData *foreach_data;
GSList *names;
GSList *link;
owner = key;
names = val;
foreach_data = data;
if (foreach_data->owner != NULL)
return;
g_assert (foreach_data->info == NULL);
link = g_slist_find_custom (names, foreach_data->name, find_name_in_info);
if (link)
{
foreach_data->owner = owner;
foreach_data->info = link->data;
}
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,411
|
strequal_len (const char *a,
const char *b,
size_t *lenp)
{
size_t a_len;
size_t b_len;
a_len = strlen (a);
b_len = strlen (b);
if (a_len != b_len)
return FALSE;
if (memcmp (a, b, a_len) != 0)
return FALSE;
*lenp = a_len;
return TRUE;
}
|
+Priv
| 0
|
strequal_len (const char *a,
const char *b,
size_t *lenp)
{
size_t a_len;
size_t b_len;
a_len = strlen (a);
b_len = strlen (b);
if (a_len != b_len)
return FALSE;
if (memcmp (a, b, a_len) != 0)
return FALSE;
*lenp = a_len;
return TRUE;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,412
|
tristring_alloc_from_strings (size_t padding_before,
const char *name,
const char *path,
const char *interface)
{
size_t name_len, iface_len, path_len, len;
char *tri;
if (name)
name_len = strlen (name);
else
name_len = 0;
path_len = strlen (path);
iface_len = strlen (interface);
tri = g_malloc (padding_before + name_len + path_len + iface_len + 3);
len = padding_before;
if (name)
memcpy (&tri[len], name, name_len);
len += name_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + 1));
memcpy (&tri[len], path, path_len);
len += path_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + path_len + 2));
memcpy (&tri[len], interface, iface_len);
len += iface_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + path_len + iface_len + 3));
return tri;
}
|
+Priv
| 0
|
tristring_alloc_from_strings (size_t padding_before,
const char *name,
const char *path,
const char *interface)
{
size_t name_len, iface_len, path_len, len;
char *tri;
if (name)
name_len = strlen (name);
else
name_len = 0;
path_len = strlen (path);
iface_len = strlen (interface);
tri = g_malloc (padding_before + name_len + path_len + iface_len + 3);
len = padding_before;
if (name)
memcpy (&tri[len], name, name_len);
len += name_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + 1));
memcpy (&tri[len], path, path_len);
len += path_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + path_len + 2));
memcpy (&tri[len], interface, iface_len);
len += iface_len;
tri[len] = '\0';
len += 1;
g_assert (len == (padding_before + name_len + path_len + iface_len + 3));
return tri;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,413
|
tristring_equal (gconstpointer a,
gconstpointer b)
{
const char *ap = a;
const char *bp = b;
size_t len;
if (!strequal_len (ap, bp, &len))
return FALSE;
ap += len + 1;
bp += len + 1;
if (!strequal_len (ap, bp, &len))
return FALSE;
ap += len + 1;
bp += len + 1;
if (strcmp (ap, bp) != 0)
return FALSE;
return TRUE;
}
|
+Priv
| 0
|
tristring_equal (gconstpointer a,
gconstpointer b)
{
const char *ap = a;
const char *bp = b;
size_t len;
if (!strequal_len (ap, bp, &len))
return FALSE;
ap += len + 1;
bp += len + 1;
if (!strequal_len (ap, bp, &len))
return FALSE;
ap += len + 1;
bp += len + 1;
if (strcmp (ap, bp) != 0)
return FALSE;
return TRUE;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,414
|
tristring_from_message (DBusMessage *message)
{
const char *path;
const char *interface;
path = dbus_message_get_path (message);
interface = dbus_message_get_interface (message);
g_assert (path);
g_assert (interface);
return tristring_alloc_from_strings (0,
dbus_message_get_sender (message),
path, interface);
}
|
+Priv
| 0
|
tristring_from_message (DBusMessage *message)
{
const char *path;
const char *interface;
path = dbus_message_get_path (message);
interface = dbus_message_get_interface (message);
g_assert (path);
g_assert (interface);
return tristring_alloc_from_strings (0,
dbus_message_get_sender (message),
path, interface);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,415
|
tristring_from_proxy (DBusGProxy *proxy)
{
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
return tristring_alloc_from_strings (0,
priv->name,
priv->path,
priv->interface);
}
|
+Priv
| 0
|
tristring_from_proxy (DBusGProxy *proxy)
{
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
return tristring_alloc_from_strings (0,
priv->name,
priv->path,
priv->interface);
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,416
|
tristring_hash (gconstpointer key)
{
const char *p = key;
guint h = *p;
if (h)
{
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
}
/* skip nul and do the next substring */
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
/* skip nul again and another substring */
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
return h;
}
|
+Priv
| 0
|
tristring_hash (gconstpointer key)
{
const char *p = key;
guint h = *p;
if (h)
{
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
}
/* skip nul and do the next substring */
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
/* skip nul again and another substring */
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
return h;
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,417
|
unassociate_proxies (gpointer key, gpointer val, gpointer user_data)
{
DBusGProxyList *list;
const char *name;
GSList *tmp;
DBusGProxyUnassociateData *data;
list = val;
data = user_data;
name = data->name;
for (tmp = list->proxies; tmp; tmp = tmp->next)
{
DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
DBusGProxyManager *manager;
manager = priv->manager;
if (priv->name != NULL && !strcmp (priv->name, name))
{
if (!priv->for_owner)
{
/* If a service appeared and then vanished very quickly,
* it's conceivable we have an inflight request for
* GetNameOwner here. Cancel it.
* https://bugs.freedesktop.org/show_bug.cgi?id=18573
*/
if (priv->name_call)
dbus_g_proxy_cancel_call (manager->bus_proxy, priv->name_call);
priv->name_call = NULL;
priv->associated = FALSE;
manager->unassociated_proxies = g_slist_prepend (manager->unassociated_proxies, proxy);
}
else
{
data->destroyed = g_slist_prepend (data->destroyed, proxy);
/* make contents of list into weak pointers in case the objects
* unref each other when disposing */
g_object_add_weak_pointer (G_OBJECT (proxy),
&(data->destroyed->data));
}
}
}
}
|
+Priv
| 0
|
unassociate_proxies (gpointer key, gpointer val, gpointer user_data)
{
DBusGProxyList *list;
const char *name;
GSList *tmp;
DBusGProxyUnassociateData *data;
list = val;
data = user_data;
name = data->name;
for (tmp = list->proxies; tmp; tmp = tmp->next)
{
DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
DBusGProxyManager *manager;
manager = priv->manager;
if (priv->name != NULL && !strcmp (priv->name, name))
{
if (!priv->for_owner)
{
/* If a service appeared and then vanished very quickly,
* it's conceivable we have an inflight request for
* GetNameOwner here. Cancel it.
* https://bugs.freedesktop.org/show_bug.cgi?id=18573
*/
if (priv->name_call)
dbus_g_proxy_cancel_call (manager->bus_proxy, priv->name_call);
priv->name_call = NULL;
priv->associated = FALSE;
manager->unassociated_proxies = g_slist_prepend (manager->unassociated_proxies, proxy);
}
else
{
data->destroyed = g_slist_prepend (data->destroyed, proxy);
/* make contents of list into weak pointers in case the objects
* unref each other when disposing */
g_object_add_weak_pointer (G_OBJECT (proxy),
&(data->destroyed->data));
}
}
}
}
|
@@ -1250,8 +1250,11 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
GSList *tmp;
const char *sender;
+ sender = dbus_message_get_sender (message);
+
/* First we handle NameOwnerChanged internally */
- if (dbus_message_is_signal (message,
+ if (g_strcmp0 (sender, DBUS_SERVICE_DBUS) == 0 &&
+ dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged"))
{
@@ -1280,8 +1283,6 @@ dbus_g_proxy_manager_filter (DBusConnection *connection,
}
}
- sender = dbus_message_get_sender (message);
-
/* dbus spec requires these, libdbus validates */
g_assert (dbus_message_get_path (message) != NULL);
g_assert (dbus_message_get_interface (message) != NULL);
|
CWE-20
| null | null |
4,418
|
PreserveTrMode(xps_context_t *ctx)
{
gs_c_param_list list;
dev_param_req_t request;
gs_param_name ParamName = "PreserveTrMode";
gs_param_typed_value Param;
char *data;
gs_gstate *pgs = ctx->pgs;
int code = 0;
/* Interrogate the device to see if it supports Text Rendering Mode */
data = (char *)gs_alloc_bytes(ctx->memory, 15, "temporary special_op string");
memset(data, 0x00, 15);
memcpy(data, "PreserveTrMode", 15);
gs_c_param_list_write(&list, ctx->memory);
/* Make a null object so that the param list won't check for requests */
Param.type = gs_param_type_null;
list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);
/* Stuff the data into a structure for passing to the spec_op */
request.Param = data;
request.list = &list;
code = dev_proc(gs_currentdevice(pgs), dev_spec_op)(gs_currentdevice(pgs), gxdso_get_dev_param,
&request, sizeof(dev_param_req_t));
if (code != gs_error_undefined) {
/* The parameter is present in the device, now we need to see its value */
gs_c_param_list_read(&list);
list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);
if (Param.type != gs_param_type_bool) {
/* This really shoudn't happen, but its best to be sure */
gs_free_object(ctx->memory, data,"temporary special_op string");
gs_c_param_list_release(&list);
return gs_error_typecheck;
}
if (Param.value.b) {
code = 1;
} else {
code = 0;
}
} else {
code = 0;
}
gs_free_object(ctx->memory, data,"temporary special_op string");
gs_c_param_list_release(&list);
return code;
}
|
DoS
| 0
|
PreserveTrMode(xps_context_t *ctx)
{
gs_c_param_list list;
dev_param_req_t request;
gs_param_name ParamName = "PreserveTrMode";
gs_param_typed_value Param;
char *data;
gs_gstate *pgs = ctx->pgs;
int code = 0;
/* Interrogate the device to see if it supports Text Rendering Mode */
data = (char *)gs_alloc_bytes(ctx->memory, 15, "temporary special_op string");
memset(data, 0x00, 15);
memcpy(data, "PreserveTrMode", 15);
gs_c_param_list_write(&list, ctx->memory);
/* Make a null object so that the param list won't check for requests */
Param.type = gs_param_type_null;
list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);
/* Stuff the data into a structure for passing to the spec_op */
request.Param = data;
request.list = &list;
code = dev_proc(gs_currentdevice(pgs), dev_spec_op)(gs_currentdevice(pgs), gxdso_get_dev_param,
&request, sizeof(dev_param_req_t));
if (code != gs_error_undefined) {
/* The parameter is present in the device, now we need to see its value */
gs_c_param_list_read(&list);
list.procs->xmit_typed((gs_param_list *)&list, ParamName, &Param);
if (Param.type != gs_param_type_bool) {
/* This really shoudn't happen, but its best to be sure */
gs_free_object(ctx->memory, data,"temporary special_op string");
gs_c_param_list_release(&list);
return gs_error_typecheck;
}
if (Param.value.b) {
code = 1;
} else {
code = 0;
}
} else {
code = 0;
}
gs_free_object(ctx->memory, data,"temporary special_op string");
gs_c_param_list_release(&list);
return code;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,419
|
xps_debug_path(xps_context_t *ctx)
{
segment *seg;
curve_segment *cseg;
seg = (segment*)ctx->pgs->path->first_subpath;
while (seg)
{
switch (seg->type)
{
case s_start:
dmprintf2(ctx->memory, "%g %g moveto\n",
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
case s_line:
dmprintf2(ctx->memory, "%g %g lineto\n",
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
case s_line_close:
dmputs(ctx->memory, "closepath\n");
break;
case s_curve:
cseg = (curve_segment*)seg;
dmprintf6(ctx->memory, "%g %g %g %g %g %g curveto\n",
fixed2float(cseg->p1.x) * 0.001,
fixed2float(cseg->p1.y) * 0.001,
fixed2float(cseg->p2.x) * 0.001,
fixed2float(cseg->p2.y) * 0.001,
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
}
seg = seg->next;
}
}
|
DoS
| 0
|
xps_debug_path(xps_context_t *ctx)
{
segment *seg;
curve_segment *cseg;
seg = (segment*)ctx->pgs->path->first_subpath;
while (seg)
{
switch (seg->type)
{
case s_start:
dmprintf2(ctx->memory, "%g %g moveto\n",
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
case s_line:
dmprintf2(ctx->memory, "%g %g lineto\n",
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
case s_line_close:
dmputs(ctx->memory, "closepath\n");
break;
case s_curve:
cseg = (curve_segment*)seg;
dmprintf6(ctx->memory, "%g %g %g %g %g %g curveto\n",
fixed2float(cseg->p1.x) * 0.001,
fixed2float(cseg->p1.y) * 0.001,
fixed2float(cseg->p2.x) * 0.001,
fixed2float(cseg->p2.y) * 0.001,
fixed2float(seg->pt.x) * 0.001,
fixed2float(seg->pt.y) * 0.001);
break;
}
seg = seg->next;
}
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,420
|
xps_deobfuscate_font_resource(xps_context_t *ctx, xps_part_t *part)
{
byte buf[33];
byte key[16];
char *p;
int i;
p = strrchr(part->name, '/');
if (!p)
p = part->name;
for (i = 0; i < 32 && *p; p++)
{
if (isxdigit(*p))
buf[i++] = *p;
}
buf[i] = 0;
if (i != 32)
{
gs_warn("cannot extract GUID from obfuscated font part name");
return;
}
for (i = 0; i < 16; i++)
key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]);
for (i = 0; i < 16; i++)
{
part->data[i] ^= key[15-i];
part->data[i+16] ^= key[15-i];
}
}
|
DoS
| 0
|
xps_deobfuscate_font_resource(xps_context_t *ctx, xps_part_t *part)
{
byte buf[33];
byte key[16];
char *p;
int i;
p = strrchr(part->name, '/');
if (!p)
p = part->name;
for (i = 0; i < 32 && *p; p++)
{
if (isxdigit(*p))
buf[i++] = *p;
}
buf[i] = 0;
if (i != 32)
{
gs_warn("cannot extract GUID from obfuscated font part name");
return;
}
for (i = 0; i < 16; i++)
key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]);
for (i = 0; i < 16; i++)
{
part->data[i] ^= key[15-i];
part->data[i+16] ^= key[15-i];
}
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,421
|
xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font,
xps_text_buffer_t *buf, int is_charpath)
{
gs_text_params_t params;
gs_text_enum_t *textenum;
float initial_x, x = buf->x[0];
float initial_y, y = buf->y[0];
int code;
int i;
gs_gstate_color saved;
initial_x = x;
initial_y = y;
params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS;
if (is_charpath)
params.operation |= TEXT_DO_FALSE_CHARPATH;
else
params.operation |= TEXT_DO_DRAW;
params.data.glyphs = buf->g;
params.size = buf->count;
params.x_widths = buf->x + 1;
params.y_widths = buf->y + 1;
params.widths_size = buf->count;
for (i = 0; i < buf->count; i++)
{
buf->x[i] = buf->x[i] - x;
buf->y[i] = buf->y[i] - y;
x += buf->x[i];
y += buf->y[i];
}
buf->x[buf->count] = 0;
buf->y[buf->count] = 0;
if (ctx->pgs->text_rendering_mode == 2 ) {
gs_text_enum_t *Tr_textenum;
gs_text_params_t Tr_params;
/* Save the 'stroke' colour, which XPS doesn't normally use, or set.
* This isn't used by rendering, but it is used by the pdfwrite
* device family, and must be correct for stroking text rendering
* modes.
*/
saved = ctx->pgs->color[1];
/* And now make the stroke color the same as the fill color */
ctx->pgs->color[1] = ctx->pgs->color[0];
if (PreserveTrMode(ctx) != 1) {
/* The device doesn't want (or can't handle) Text Rendering Modes
* So start by doing a 'charpath stroke' to embolden the text
*/
gs_moveto(ctx->pgs, initial_x, initial_y);
Tr_params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS | TEXT_DO_TRUE_CHARPATH;
Tr_params.data.glyphs = params.data.glyphs;
Tr_params.size = params.size;
Tr_params.x_widths = params.x_widths;
Tr_params.y_widths = params.y_widths;
Tr_params.widths_size = params.widths_size;
code = gs_text_begin(ctx->pgs, &Tr_params, ctx->memory, &Tr_textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_begin() (%d)", code);
code = gs_text_process(Tr_textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_process() (%d)", code);
gs_text_release(Tr_textenum, "gslt font render");
gs_stroke(ctx->pgs);
} else {
/* Nasty complications; the pdfwrite device always scales the line width
* by 1, not the CTM, when handling stroking text rendering modes (when stroking
* a path it *does* apply the CTM to the line width. Consistency ? We've heard of it....)
* Altering this would mean lots of hackery in the PDF interpreter, so instead alter the
* line width here by the CTM. Note; if we have Text rendering mode set then we know that
* xps_parse_glyphs_imp() will have done a gsave and set the linewidth, so its safe to
* meddle with it here, it will be grestore'd when we trickle back up.
*/
gs_gstate *pgs = ctx->pgs;
double scale = 1;
/* This code is copied from gdev_vector_stroke_scaling() and applies the same CTM
* scaling as we would for a stroke, so that the pdfwrite output will be consistent
* with a rendered stroke and fill operation when Tr is 2.
*/
if (is_xxyy(&pgs->ctm)) {
scale = fabs(pgs->ctm.xx);
} else if (is_xyyx(&pgs->ctm)) {
scale = fabs(pgs->ctm.xy);
} else if ((pgs->ctm.xx == pgs->ctm.yy && pgs->ctm.xy == -pgs->ctm.yx) ||
(pgs->ctm.xx == -pgs->ctm.yy && pgs->ctm.xy == pgs->ctm.yx)
) {
scale = hypot(pgs->ctm.xx, pgs->ctm.xy);
}
gs_setlinewidth(pgs, pgs->line_params.half_width * scale);
}
}
gs_moveto(ctx->pgs, initial_x, initial_y);
code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_begin() (%d)", code);
code = gs_text_process(textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_process() (%d)", code);
gs_text_release(textenum, "gslt font render");
buf->count = 0;
if (ctx->pgs->text_rendering_mode == 2 ) {
/* Restore the stroke colour which we overwrote above */
ctx->pgs->color[1] = saved;
}
return 0;
}
|
DoS
| 0
|
xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font,
xps_text_buffer_t *buf, int is_charpath)
{
gs_text_params_t params;
gs_text_enum_t *textenum;
float initial_x, x = buf->x[0];
float initial_y, y = buf->y[0];
int code;
int i;
gs_gstate_color saved;
initial_x = x;
initial_y = y;
params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS;
if (is_charpath)
params.operation |= TEXT_DO_FALSE_CHARPATH;
else
params.operation |= TEXT_DO_DRAW;
params.data.glyphs = buf->g;
params.size = buf->count;
params.x_widths = buf->x + 1;
params.y_widths = buf->y + 1;
params.widths_size = buf->count;
for (i = 0; i < buf->count; i++)
{
buf->x[i] = buf->x[i] - x;
buf->y[i] = buf->y[i] - y;
x += buf->x[i];
y += buf->y[i];
}
buf->x[buf->count] = 0;
buf->y[buf->count] = 0;
if (ctx->pgs->text_rendering_mode == 2 ) {
gs_text_enum_t *Tr_textenum;
gs_text_params_t Tr_params;
/* Save the 'stroke' colour, which XPS doesn't normally use, or set.
* This isn't used by rendering, but it is used by the pdfwrite
* device family, and must be correct for stroking text rendering
* modes.
*/
saved = ctx->pgs->color[1];
/* And now make the stroke color the same as the fill color */
ctx->pgs->color[1] = ctx->pgs->color[0];
if (PreserveTrMode(ctx) != 1) {
/* The device doesn't want (or can't handle) Text Rendering Modes
* So start by doing a 'charpath stroke' to embolden the text
*/
gs_moveto(ctx->pgs, initial_x, initial_y);
Tr_params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS | TEXT_DO_TRUE_CHARPATH;
Tr_params.data.glyphs = params.data.glyphs;
Tr_params.size = params.size;
Tr_params.x_widths = params.x_widths;
Tr_params.y_widths = params.y_widths;
Tr_params.widths_size = params.widths_size;
code = gs_text_begin(ctx->pgs, &Tr_params, ctx->memory, &Tr_textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_begin() (%d)", code);
code = gs_text_process(Tr_textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_process() (%d)", code);
gs_text_release(Tr_textenum, "gslt font render");
gs_stroke(ctx->pgs);
} else {
/* Nasty complications; the pdfwrite device always scales the line width
* by 1, not the CTM, when handling stroking text rendering modes (when stroking
* a path it *does* apply the CTM to the line width. Consistency ? We've heard of it....)
* Altering this would mean lots of hackery in the PDF interpreter, so instead alter the
* line width here by the CTM. Note; if we have Text rendering mode set then we know that
* xps_parse_glyphs_imp() will have done a gsave and set the linewidth, so its safe to
* meddle with it here, it will be grestore'd when we trickle back up.
*/
gs_gstate *pgs = ctx->pgs;
double scale = 1;
/* This code is copied from gdev_vector_stroke_scaling() and applies the same CTM
* scaling as we would for a stroke, so that the pdfwrite output will be consistent
* with a rendered stroke and fill operation when Tr is 2.
*/
if (is_xxyy(&pgs->ctm)) {
scale = fabs(pgs->ctm.xx);
} else if (is_xyyx(&pgs->ctm)) {
scale = fabs(pgs->ctm.xy);
} else if ((pgs->ctm.xx == pgs->ctm.yy && pgs->ctm.xy == -pgs->ctm.yx) ||
(pgs->ctm.xx == -pgs->ctm.yy && pgs->ctm.xy == pgs->ctm.yx)
) {
scale = hypot(pgs->ctm.xx, pgs->ctm.xy);
}
gs_setlinewidth(pgs, pgs->line_params.half_width * scale);
}
}
gs_moveto(ctx->pgs, initial_x, initial_y);
code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_begin() (%d)", code);
code = gs_text_process(textenum);
if (code != 0)
return gs_throw1(-1, "cannot gs_text_process() (%d)", code);
gs_text_release(textenum, "gslt font render");
buf->count = 0;
if (ctx->pgs->text_rendering_mode == 2 ) {
/* Restore the stroke colour which we overwrote above */
ctx->pgs->color[1] = saved;
}
return 0;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,422
|
xps_parse_digits(char *s, int *digit)
{
*digit = 0;
while (*s >= '0' && *s <= '9')
{
*digit = *digit * 10 + (*s - '0');
s ++;
}
return s;
}
|
DoS
| 0
|
xps_parse_digits(char *s, int *digit)
{
*digit = 0;
while (*s >= '0' && *s <= '9')
{
*digit = *digit * 10 + (*s - '0');
s ++;
}
return s;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,423
|
xps_parse_glyph_index(char *s, int *glyph_index)
{
if (*s >= '0' && *s <= '9')
s = xps_parse_digits(s, glyph_index);
return s;
}
|
DoS
| 0
|
xps_parse_glyph_index(char *s, int *glyph_index)
{
if (*s >= '0' && *s <= '9')
s = xps_parse_digits(s, glyph_index);
return s;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,424
|
xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs, int bidi_level)
{
s = xps_parse_glyph_advance(s, advance, bidi_level);
s = xps_parse_glyph_offsets(s, uofs, vofs);
return s;
}
|
DoS
| 0
|
xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs, int bidi_level)
{
s = xps_parse_glyph_advance(s, advance, bidi_level);
s = xps_parse_glyph_offsets(s, uofs, vofs);
return s;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,425
|
xps_parse_glyphs_imp(xps_context_t *ctx, xps_font_t *font, float size,
float originx, float originy, int is_sideways, int bidi_level,
char *indices, char *unicode, int is_charpath, int sim_bold)
{
xps_text_buffer_t buf;
xps_glyph_metrics_t mtx;
float x = originx;
float y = originy;
char *us = unicode;
char *is = indices;
int un = 0;
int code;
buf.count = 0;
if (!unicode && !indices)
return gs_throw(-1, "no text in glyphs element");
if (us)
{
if (us[0] == '{' && us[1] == '}')
us = us + 2;
un = strlen(us);
}
while ((us && un > 0) || (is && *is))
{
int char_code = '?';
int code_count = 1;
int glyph_count = 1;
if (is && *is)
{
is = xps_parse_cluster_mapping(is, &code_count, &glyph_count);
}
if (code_count < 1)
code_count = 1;
if (glyph_count < 1)
glyph_count = 1;
while (code_count--)
{
if (us && un > 0)
{
int t = xps_utf8_to_ucs(&char_code, us, un);
if (t < 0)
return gs_rethrow(-1, "error decoding UTF-8 string");
us += t; un -= t;
}
}
while (glyph_count--)
{
int glyph_index = -1;
float u_offset = 0.0;
float v_offset = 0.0;
float advance;
if (is && *is)
is = xps_parse_glyph_index(is, &glyph_index);
if (glyph_index == -1)
glyph_index = xps_encode_font_char(font, char_code);
xps_measure_font_glyph(ctx, font, glyph_index, &mtx);
if (is_sideways)
advance = mtx.vadv * 100.0;
else if (bidi_level & 1)
advance = -mtx.hadv * 100.0;
else
advance = mtx.hadv * 100.0;
if (is && *is)
{
is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset, bidi_level);
if (*is == ';')
is ++;
}
if (bidi_level & 1)
u_offset = -mtx.hadv * 100 - u_offset;
u_offset = u_offset * 0.01 * size;
v_offset = v_offset * 0.01 * size;
/* Adjust glyph offset and advance width for emboldening */
if (sim_bold)
{
advance *= 1.02f;
u_offset += 0.01 * size;
v_offset += 0.01 * size;
}
if (buf.count == XPS_TEXT_BUFFER_SIZE)
{
code = xps_flush_text_buffer(ctx, font, &buf, is_charpath);
if (code)
return gs_rethrow(code, "cannot flush buffered text");
}
if (is_sideways)
{
buf.x[buf.count] = x + u_offset + (mtx.vorg * size);
buf.y[buf.count] = y - v_offset + (mtx.hadv * 0.5 * size);
}
else
{
buf.x[buf.count] = x + u_offset;
buf.y[buf.count] = y - v_offset;
}
buf.g[buf.count] = glyph_index;
buf.count ++;
x += advance * 0.01 * size;
}
}
if (buf.count > 0)
{
code = xps_flush_text_buffer(ctx, font, &buf, is_charpath);
if (code)
return gs_rethrow(code, "cannot flush buffered text");
}
return 0;
}
|
DoS
| 0
|
xps_parse_glyphs_imp(xps_context_t *ctx, xps_font_t *font, float size,
float originx, float originy, int is_sideways, int bidi_level,
char *indices, char *unicode, int is_charpath, int sim_bold)
{
xps_text_buffer_t buf;
xps_glyph_metrics_t mtx;
float x = originx;
float y = originy;
char *us = unicode;
char *is = indices;
int un = 0;
int code;
buf.count = 0;
if (!unicode && !indices)
return gs_throw(-1, "no text in glyphs element");
if (us)
{
if (us[0] == '{' && us[1] == '}')
us = us + 2;
un = strlen(us);
}
while ((us && un > 0) || (is && *is))
{
int char_code = '?';
int code_count = 1;
int glyph_count = 1;
if (is && *is)
{
is = xps_parse_cluster_mapping(is, &code_count, &glyph_count);
}
if (code_count < 1)
code_count = 1;
if (glyph_count < 1)
glyph_count = 1;
while (code_count--)
{
if (us && un > 0)
{
int t = xps_utf8_to_ucs(&char_code, us, un);
if (t < 0)
return gs_rethrow(-1, "error decoding UTF-8 string");
us += t; un -= t;
}
}
while (glyph_count--)
{
int glyph_index = -1;
float u_offset = 0.0;
float v_offset = 0.0;
float advance;
if (is && *is)
is = xps_parse_glyph_index(is, &glyph_index);
if (glyph_index == -1)
glyph_index = xps_encode_font_char(font, char_code);
xps_measure_font_glyph(ctx, font, glyph_index, &mtx);
if (is_sideways)
advance = mtx.vadv * 100.0;
else if (bidi_level & 1)
advance = -mtx.hadv * 100.0;
else
advance = mtx.hadv * 100.0;
if (is && *is)
{
is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset, bidi_level);
if (*is == ';')
is ++;
}
if (bidi_level & 1)
u_offset = -mtx.hadv * 100 - u_offset;
u_offset = u_offset * 0.01 * size;
v_offset = v_offset * 0.01 * size;
/* Adjust glyph offset and advance width for emboldening */
if (sim_bold)
{
advance *= 1.02f;
u_offset += 0.01 * size;
v_offset += 0.01 * size;
}
if (buf.count == XPS_TEXT_BUFFER_SIZE)
{
code = xps_flush_text_buffer(ctx, font, &buf, is_charpath);
if (code)
return gs_rethrow(code, "cannot flush buffered text");
}
if (is_sideways)
{
buf.x[buf.count] = x + u_offset + (mtx.vorg * size);
buf.y[buf.count] = y - v_offset + (mtx.hadv * 0.5 * size);
}
else
{
buf.x[buf.count] = x + u_offset;
buf.y[buf.count] = y - v_offset;
}
buf.g[buf.count] = glyph_index;
buf.count ++;
x += advance * 0.01 * size;
}
}
if (buf.count > 0)
{
code = xps_flush_text_buffer(ctx, font, &buf, is_charpath);
if (code)
return gs_rethrow(code, "cannot flush buffered text");
}
return 0;
}
|
@@ -144,8 +144,8 @@ xps_select_best_font_encoding(xps_font_t *font)
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
- xps_select_font_encoding(font, i);
- return;
+ if (xps_select_font_encoding(font, i))
+ return;
}
}
}
|
CWE-125
| null | null |
4,426
|
static inline int u16(const byte *p)
{
return (p[0] << 8) | p[1];
}
|
DoS Overflow
| 0
|
static inline int u16(const byte *p)
{
return (p[0] << 8) | p[1];
}
|
@@ -141,10 +141,14 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
int table_offset;
ulong format;
- uint numGlyphs;
+ int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
+ if (glyph >= GS_MIN_GLYPH_INDEX) {
+ glyph -= GS_MIN_GLYPH_INDEX;
+ }
+
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
@@ -193,8 +197,8 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
}
/* skip over the post header */
- numGlyphs = u16(postp + 32);
- if (glyph > numGlyphs - 1)
+ numGlyphs = (int)u16(postp + 32);
+ if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
|
CWE-119
| null | null |
4,427
|
static inline int u32(const byte *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
|
DoS Overflow
| 0
|
static inline int u32(const byte *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
|
@@ -141,10 +141,14 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
int table_offset;
ulong format;
- uint numGlyphs;
+ int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
+ if (glyph >= GS_MIN_GLYPH_INDEX) {
+ glyph -= GS_MIN_GLYPH_INDEX;
+ }
+
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
@@ -193,8 +197,8 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
}
/* skip over the post header */
- numGlyphs = u16(postp + 32);
- if (glyph > numGlyphs - 1)
+ numGlyphs = (int)u16(postp + 32);
+ if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
|
CWE-119
| null | null |
4,428
|
xps_true_callback_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t spc)
{
xps_font_t *font = pfont->client_data;
int value;
value = xps_encode_font_char(font, chr);
if (value == 0)
return GS_NO_GLYPH;
return value;
}
|
DoS Overflow
| 0
|
xps_true_callback_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t spc)
{
xps_font_t *font = pfont->client_data;
int value;
value = xps_encode_font_char(font, chr);
if (value == 0)
return GS_NO_GLYPH;
return value;
}
|
@@ -141,10 +141,14 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
int table_offset;
ulong format;
- uint numGlyphs;
+ int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
+ if (glyph >= GS_MIN_GLYPH_INDEX) {
+ glyph -= GS_MIN_GLYPH_INDEX;
+ }
+
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
@@ -193,8 +197,8 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
}
/* skip over the post header */
- numGlyphs = u16(postp + 32);
- if (glyph > numGlyphs - 1)
+ numGlyphs = (int)u16(postp + 32);
+ if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
|
CWE-119
| null | null |
4,429
|
xps_true_callback_string_proc(gs_font_type42 *p42, ulong offset, uint length, const byte **pdata)
{
xps_font_t *font = p42->client_data;
if (offset + length > font->length)
{
*pdata = NULL;
return gs_throw2(-1, "font data access out of bounds (offset=%lu size=%u)", offset, length);
}
*pdata = font->data + offset;
return 0;
}
|
DoS Overflow
| 0
|
xps_true_callback_string_proc(gs_font_type42 *p42, ulong offset, uint length, const byte **pdata)
{
xps_font_t *font = p42->client_data;
if (offset + length > font->length)
{
*pdata = NULL;
return gs_throw2(-1, "font data access out of bounds (offset=%lu size=%u)", offset, length);
}
*pdata = font->data + offset;
return 0;
}
|
@@ -141,10 +141,14 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
int table_offset;
ulong format;
- uint numGlyphs;
+ int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
+ if (glyph >= GS_MIN_GLYPH_INDEX) {
+ glyph -= GS_MIN_GLYPH_INDEX;
+ }
+
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
@@ -193,8 +197,8 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps
}
/* skip over the post header */
- numGlyphs = u16(postp + 32);
- if (glyph > numGlyphs - 1)
+ numGlyphs = (int)u16(postp + 32);
+ if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
|
CWE-119
| null | null |
4,430
|
xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr)
{
/* This function is copied verbatim from plfont.c */
int table_length;
int table_offset;
ulong format;
int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
if (glyph >= GS_MIN_GLYPH_INDEX) {
glyph -= GS_MIN_GLYPH_INDEX;
}
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
glyph -= 29;
if (glyph < 258 )
{
pstr->data = (byte*) pl_mac_names[glyph];
pstr->size = strlen((char*)pstr->data);
return 0;
}
else
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
}
table_offset = xps_find_sfnt_table((xps_font_t*)pfont->client_data, "post", &table_length);
/* no post table */
if (table_offset < 0)
return gs_throw(-1, "no post table");
/* this shoudn't happen but... */
if ( table_length == 0 )
return gs_throw(-1, "zero-size post table");
((gs_font_type42 *)pfont)->data.string_proc((gs_font_type42 *)pfont,
table_offset, table_length, &postp);
format = u32(postp);
/* Format 1.0 (mac encoding) is a simple table see the TT spec.
* We don't implement this because we don't see it in practice.
* Format 2.5 is deprecated.
* Format 3.0 means that there is no post data in the font file.
* We see this a lot but can't do much about it.
* The only format we support is 2.0.
*/
if ( format != 0x20000 )
{
/* Invent a name if we don't know the table format. */
char buf[32];
gs_sprintf(buf, "glyph%d", (int)glyph);
pstr->data = (byte*)buf;
pstr->size = strlen((char*)pstr->data);
return 0;
}
/* skip over the post header */
numGlyphs = (int)u16(postp + 32);
if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
/* glyph name index starts at post + 34 each entry is 2 bytes */
glyph_name_index = u16(postp + 34 + (glyph * 2));
/* this shouldn't happen */
if ( glyph_name_index > 0x7fff )
return gs_throw(-1, "post table format error");
/* mac easy */
if ( glyph_name_index < 258 )
{
pstr->data = (byte*) pl_mac_names[glyph_name_index];
pstr->size = strlen((char*)pstr->data);
return 0;
}
/* not mac */
else
{
byte *mydata;
/* and here's the tricky part */
const byte *pascal_stringp = postp + 34 + (numGlyphs * 2);
/* 0 - 257 lives in the mac table above */
glyph_name_index -= 258;
/* The string we want is the index'th pascal string,
* so we "hop" to each length byte "index" times. */
while (glyph_name_index > 0)
{
pascal_stringp += ((int)(*pascal_stringp)+1);
glyph_name_index--;
}
/* length byte */
pstr->size = (int)(*pascal_stringp);
/* + 1 is for the length byte */
pstr->data = pascal_stringp + 1;
/* sanity check */
if ( pstr->data + pstr->size > postp + table_length || pstr->data - 1 < postp)
return gs_throw(-1, "data out of range");
/* sigh - we have to allocate a copy of the data - by the
* time a high level device makes use of it the font data
* may be freed. This is a necessary leak. */
mydata = gs_alloc_bytes(pfont->memory, pstr->size + 1, "glyph to name");
if ( mydata == 0 )
return -1;
memcpy(mydata, pascal_stringp + 1, pstr->size);
pstr->data = mydata;
mydata[pstr->size] = 0;
return 0;
}
}
|
DoS Overflow
| 0
|
xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr)
{
/* This function is copied verbatim from plfont.c */
int table_length;
int table_offset;
ulong format;
int numGlyphs;
uint glyph_name_index;
const byte *postp; /* post table pointer */
if (glyph >= GS_MIN_GLYPH_INDEX) {
glyph -= GS_MIN_GLYPH_INDEX;
}
/* guess if the font type is not truetype */
if ( pfont->FontType != ft_TrueType )
{
glyph -= 29;
if (glyph < 258 )
{
pstr->data = (byte*) pl_mac_names[glyph];
pstr->size = strlen((char*)pstr->data);
return 0;
}
else
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
}
table_offset = xps_find_sfnt_table((xps_font_t*)pfont->client_data, "post", &table_length);
/* no post table */
if (table_offset < 0)
return gs_throw(-1, "no post table");
/* this shoudn't happen but... */
if ( table_length == 0 )
return gs_throw(-1, "zero-size post table");
((gs_font_type42 *)pfont)->data.string_proc((gs_font_type42 *)pfont,
table_offset, table_length, &postp);
format = u32(postp);
/* Format 1.0 (mac encoding) is a simple table see the TT spec.
* We don't implement this because we don't see it in practice.
* Format 2.5 is deprecated.
* Format 3.0 means that there is no post data in the font file.
* We see this a lot but can't do much about it.
* The only format we support is 2.0.
*/
if ( format != 0x20000 )
{
/* Invent a name if we don't know the table format. */
char buf[32];
gs_sprintf(buf, "glyph%d", (int)glyph);
pstr->data = (byte*)buf;
pstr->size = strlen((char*)pstr->data);
return 0;
}
/* skip over the post header */
numGlyphs = (int)u16(postp + 32);
if ((int)glyph > numGlyphs - 1)
{
return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
}
/* glyph name index starts at post + 34 each entry is 2 bytes */
glyph_name_index = u16(postp + 34 + (glyph * 2));
/* this shouldn't happen */
if ( glyph_name_index > 0x7fff )
return gs_throw(-1, "post table format error");
/* mac easy */
if ( glyph_name_index < 258 )
{
pstr->data = (byte*) pl_mac_names[glyph_name_index];
pstr->size = strlen((char*)pstr->data);
return 0;
}
/* not mac */
else
{
byte *mydata;
/* and here's the tricky part */
const byte *pascal_stringp = postp + 34 + (numGlyphs * 2);
/* 0 - 257 lives in the mac table above */
glyph_name_index -= 258;
/* The string we want is the index'th pascal string,
* so we "hop" to each length byte "index" times. */
while (glyph_name_index > 0)
{
pascal_stringp += ((int)(*pascal_stringp)+1);
glyph_name_index--;
}
/* length byte */
pstr->size = (int)(*pascal_stringp);
/* + 1 is for the length byte */
pstr->data = pascal_stringp + 1;
/* sanity check */
if ( pstr->data + pstr->size > postp + table_length || pstr->data - 1 < postp)
return gs_throw(-1, "data out of range");
/* sigh - we have to allocate a copy of the data - by the
* time a high level device makes use of it the font data
* may be freed. This is a necessary leak. */
mydata = gs_alloc_bytes(pfont->memory, pstr->size + 1, "glyph to name");
if ( mydata == 0 )
return -1;
memcpy(mydata, pascal_stringp + 1, pstr->size);
pstr->data = mydata;
mydata[pstr->size] = 0;
return 0;
}
}
|
@@ -385,7 +385,7 @@ xps_init_truetype_font(xps_context_t *ctx, xps_font_t *font)
p42->procs.build_char = xps_true_callback_build_char;
memset(p42->font_name.chars, 0, sizeof(p42->font_name.chars));
- xps_load_sfnt_name(font, (char*)p42->font_name.chars);
+ xps_load_sfnt_name(font, (char*)p42->font_name.chars, sizeof(p42->font_name.chars));
p42->font_name.size = strlen((char*)p42->font_name.chars);
memset(p42->key_name.chars, 0, sizeof(p42->key_name.chars));
|
CWE-119
| null | null |
4,431
|
static void Ins_MDRP( INS_ARG )
{
Int point;
TT_F26Dot6 distance,
org_dist;
point = (Int)args[0];
if ( BOUNDS( args[0], CUR.zp1.n_points ) )
{
/* Current version of FreeType silently ignores this out of bounds error
* and drops the instruction, see bug #691121
CUR.error = TT_Err_Invalid_Reference; */
return;
}
/* XXX: Is there some undocumented feature while in the */
/* twilight zone? */
org_dist = CUR_Func_dualproj( CUR.zp1.org_x[point] -
CUR.zp0.org_x[CUR.GS.rp0],
CUR.zp1.org_y[point] -
CUR.zp0.org_y[CUR.GS.rp0] );
/* single width cutin test */
if ( ABS(org_dist) < CUR.GS.single_width_cutin )
{
if ( org_dist >= 0 )
org_dist = CUR.GS.single_width_value;
else
org_dist = -CUR.GS.single_width_value;
}
/* round flag */
if ( (CUR.opcode & 4) != 0 )
distance = CUR_Func_round( org_dist,
CUR.metrics.compensations[CUR.opcode & 3] );
else
distance = Round_None( EXEC_ARGS
org_dist,
CUR.metrics.compensations[CUR.opcode & 3] );
/* minimum distance flag */
if ( (CUR.opcode & 8) != 0 )
{
if ( org_dist >= 0 )
{
if ( distance < CUR.GS.minimum_distance )
distance = CUR.GS.minimum_distance;
}
else
{
if ( distance > -CUR.GS.minimum_distance )
distance = -CUR.GS.minimum_distance;
}
}
/* now move the point */
org_dist = CUR_Func_project( CUR.zp1.cur_x[point] -
CUR.zp0.cur_x[CUR.GS.rp0],
CUR.zp1.cur_y[point] -
CUR.zp0.cur_y[CUR.GS.rp0] );
CUR_Func_move( &CUR.zp1, point, distance - org_dist );
CUR.GS.rp1 = CUR.GS.rp0;
CUR.GS.rp2 = point;
if ( (CUR.opcode & 16) != 0 )
CUR.GS.rp0 = point;
}
|
DoS
| 0
|
static void Ins_MDRP( INS_ARG )
{
Int point;
TT_F26Dot6 distance,
org_dist;
point = (Int)args[0];
if ( BOUNDS( args[0], CUR.zp1.n_points ) )
{
/* Current version of FreeType silently ignores this out of bounds error
* and drops the instruction, see bug #691121
CUR.error = TT_Err_Invalid_Reference; */
return;
}
/* XXX: Is there some undocumented feature while in the */
/* twilight zone? */
org_dist = CUR_Func_dualproj( CUR.zp1.org_x[point] -
CUR.zp0.org_x[CUR.GS.rp0],
CUR.zp1.org_y[point] -
CUR.zp0.org_y[CUR.GS.rp0] );
/* single width cutin test */
if ( ABS(org_dist) < CUR.GS.single_width_cutin )
{
if ( org_dist >= 0 )
org_dist = CUR.GS.single_width_value;
else
org_dist = -CUR.GS.single_width_value;
}
/* round flag */
if ( (CUR.opcode & 4) != 0 )
distance = CUR_Func_round( org_dist,
CUR.metrics.compensations[CUR.opcode & 3] );
else
distance = Round_None( EXEC_ARGS
org_dist,
CUR.metrics.compensations[CUR.opcode & 3] );
/* minimum distance flag */
if ( (CUR.opcode & 8) != 0 )
{
if ( org_dist >= 0 )
{
if ( distance < CUR.GS.minimum_distance )
distance = CUR.GS.minimum_distance;
}
else
{
if ( distance > -CUR.GS.minimum_distance )
distance = -CUR.GS.minimum_distance;
}
}
/* now move the point */
org_dist = CUR_Func_project( CUR.zp1.cur_x[point] -
CUR.zp0.cur_x[CUR.GS.rp0],
CUR.zp1.cur_y[point] -
CUR.zp0.cur_y[CUR.GS.rp0] );
CUR_Func_move( &CUR.zp1, point, distance - org_dist );
CUR.GS.rp1 = CUR.GS.rp0;
CUR.GS.rp2 = point;
if ( (CUR.opcode & 16) != 0 )
CUR.GS.rp0 = point;
}
|
@@ -3858,7 +3858,8 @@ static int nInstrCount=0;
/* XXX: UNDOCUMENTED! cvt[-1] = 0 always */
if ( BOUNDS( args[0], CUR.zp1.n_points ) ||
- BOUNDS( args[1]+1, CUR.cvtSize+1 ) )
+ BOUNDS( args[1]+1, CUR.cvtSize+1 ) ||
+ BOUNDS(CUR.GS.rp0, CUR.zp0.n_points) )
{
CUR.error = TT_Err_Invalid_Reference;
return;
|
CWE-125
| null | null |
4,432
|
xps_decode_font_char(xps_font_t *font, int code)
{
int gid = xps_decode_font_char_imp(font, code);
if (gid == 0)
return code;
return gid;
}
|
DoS
| 0
|
xps_decode_font_char(xps_font_t *font, int code)
{
int gid = xps_decode_font_char_imp(font, code);
if (gid == 0)
return code;
return gid;
}
|
@@ -182,12 +182,27 @@ xps_load_sfnt_name(xps_font_t *font, char *namep)
return;
}
+ /* validate the offset, and the data for the two
+ * values we're about to read
+ */
+ if (offset + 6 > font->length)
+ {
+ gs_warn("name table byte offset invalid");
+ return;
+ }
namedata = font->data + offset;
/*format = u16(namedata + 0);*/
count = u16(namedata + 2);
stringoffset = u16(namedata + 4);
+ if (stringoffset + offset > font->length
+ || offset + 6 + count * 12 > font->length)
+ {
+ gs_warn("name table invalid");
+ return;
+ }
+
if (length < 6 + (count * 12))
{
gs_warn("name table too short");
|
CWE-125
| null | null |
4,433
|
xps_decode_font_char_imp(xps_font_t *font, int code)
{
byte *table;
/* no cmap selected: return identity */
if (font->cmapsubtable <= 0)
return code;
table = font->data + font->cmapsubtable;
switch (u16(table))
{
case 0: /* Apple standard 1-to-1 mapping. */
{
int i, length = u16(&table[2]) - 6;
if (length < 0 || length > 256)
return gs_error_invalidfont;
for (i=0;i<length;i++) {
if (table[6 + i] == code)
return i;
}
}
return 0;
case 4: /* Microsoft/Adobe segmented mapping. */
{
int segCount2 = u16(table + 6);
byte *endCount = table + 14;
byte *startCount = endCount + segCount2 + 2;
byte *idDelta = startCount + segCount2;
byte *idRangeOffset = idDelta + segCount2;
int i2;
if (segCount2 < 3 || segCount2 > 65535)
return gs_error_invalidfont;
for (i2 = 0; i2 < segCount2 - 3; i2 += 2)
{
int delta = s16(idDelta + i2), roff = s16(idRangeOffset + i2);
int start = u16(startCount + i2);
int end = u16(endCount + i2);
int glyph, i;
if (end < start)
return gs_error_invalidfont;
for (i=start;i<=end;i++) {
if (roff == 0) {
glyph = (i + delta) & 0xffff;
} else {
glyph = u16(idRangeOffset + i2 + roff + ((i - start) << 1));
}
if (glyph == code) {
return i;
}
}
}
}
return 0;
case 6: /* Single interval lookup. */
{
int ch, i, length = u16(&table[8]);
int firstCode = u16(&table[6]);
if (length < 0 || length > 65535)
return gs_error_invalidfont;
for (i=0;i<length;i++) {
ch = u16(&table[10 + (i * 2)]);
if (ch == code)
return (firstCode + i);
}
}
return 0;
case 10: /* Trimmed array (like 6) */
{
unsigned int ch, i, length = u32(&table[20]);
int firstCode = u32(&table[16]);
for (i=0;i<length;i++) {
ch = u16(&table[10 + (i * 2)]);
if (ch == code)
return (firstCode + i);
}
}
return 0;
case 12: /* Segmented coverage. (like 4) */
{
unsigned int nGroups = u32(&table[12]);
int Group;
for (Group=0;Group<nGroups;Group++)
{
int startCharCode = u32(&table[16 + (Group * 12)]);
int endCharCode = u32(&table[16 + (Group * 12) + 4]);
int startGlyphCode = u32(&table[16 + (Group * 12) + 8]);
if (code >= startGlyphCode && code <= (startGlyphCode + (endCharCode - startCharCode))) {
return startGlyphCode + (code - startCharCode);
}
}
}
return 0;
case 2: /* High-byte mapping through table. */
case 8: /* Mixed 16-bit and 32-bit coverage (like 2) */
default:
gs_warn1("unknown cmap format: %d\n", u16(table));
return 0;
}
return 0;
}
|
DoS
| 0
|
xps_decode_font_char_imp(xps_font_t *font, int code)
{
byte *table;
/* no cmap selected: return identity */
if (font->cmapsubtable <= 0)
return code;
table = font->data + font->cmapsubtable;
switch (u16(table))
{
case 0: /* Apple standard 1-to-1 mapping. */
{
int i, length = u16(&table[2]) - 6;
if (length < 0 || length > 256)
return gs_error_invalidfont;
for (i=0;i<length;i++) {
if (table[6 + i] == code)
return i;
}
}
return 0;
case 4: /* Microsoft/Adobe segmented mapping. */
{
int segCount2 = u16(table + 6);
byte *endCount = table + 14;
byte *startCount = endCount + segCount2 + 2;
byte *idDelta = startCount + segCount2;
byte *idRangeOffset = idDelta + segCount2;
int i2;
if (segCount2 < 3 || segCount2 > 65535)
return gs_error_invalidfont;
for (i2 = 0; i2 < segCount2 - 3; i2 += 2)
{
int delta = s16(idDelta + i2), roff = s16(idRangeOffset + i2);
int start = u16(startCount + i2);
int end = u16(endCount + i2);
int glyph, i;
if (end < start)
return gs_error_invalidfont;
for (i=start;i<=end;i++) {
if (roff == 0) {
glyph = (i + delta) & 0xffff;
} else {
glyph = u16(idRangeOffset + i2 + roff + ((i - start) << 1));
}
if (glyph == code) {
return i;
}
}
}
}
return 0;
case 6: /* Single interval lookup. */
{
int ch, i, length = u16(&table[8]);
int firstCode = u16(&table[6]);
if (length < 0 || length > 65535)
return gs_error_invalidfont;
for (i=0;i<length;i++) {
ch = u16(&table[10 + (i * 2)]);
if (ch == code)
return (firstCode + i);
}
}
return 0;
case 10: /* Trimmed array (like 6) */
{
unsigned int ch, i, length = u32(&table[20]);
int firstCode = u32(&table[16]);
for (i=0;i<length;i++) {
ch = u16(&table[10 + (i * 2)]);
if (ch == code)
return (firstCode + i);
}
}
return 0;
case 12: /* Segmented coverage. (like 4) */
{
unsigned int nGroups = u32(&table[12]);
int Group;
for (Group=0;Group<nGroups;Group++)
{
int startCharCode = u32(&table[16 + (Group * 12)]);
int endCharCode = u32(&table[16 + (Group * 12) + 4]);
int startGlyphCode = u32(&table[16 + (Group * 12) + 8]);
if (code >= startGlyphCode && code <= (startGlyphCode + (endCharCode - startCharCode))) {
return startGlyphCode + (code - startCharCode);
}
}
}
return 0;
case 2: /* High-byte mapping through table. */
case 8: /* Mixed 16-bit and 32-bit coverage (like 2) */
default:
gs_warn1("unknown cmap format: %d\n", u16(table));
return 0;
}
return 0;
}
|
@@ -182,12 +182,27 @@ xps_load_sfnt_name(xps_font_t *font, char *namep)
return;
}
+ /* validate the offset, and the data for the two
+ * values we're about to read
+ */
+ if (offset + 6 > font->length)
+ {
+ gs_warn("name table byte offset invalid");
+ return;
+ }
namedata = font->data + offset;
/*format = u16(namedata + 0);*/
count = u16(namedata + 2);
stringoffset = u16(namedata + 4);
+ if (stringoffset + offset > font->length
+ || offset + 6 + count * 12 > font->length)
+ {
+ gs_warn("name table invalid");
+ return;
+ }
+
if (length < 6 + (count * 12))
{
gs_warn("name table too short");
|
CWE-125
| null | null |
4,434
|
xps_encode_font_char(xps_font_t *font, int code)
{
int gid = xps_encode_font_char_imp(font, code);
if (gid == 0 && font->usepua)
gid = xps_encode_font_char_imp(font, 0xF000 | code);
return gid;
}
|
DoS
| 0
|
xps_encode_font_char(xps_font_t *font, int code)
{
int gid = xps_encode_font_char_imp(font, code);
if (gid == 0 && font->usepua)
gid = xps_encode_font_char_imp(font, 0xF000 | code);
return gid;
}
|
@@ -182,12 +182,27 @@ xps_load_sfnt_name(xps_font_t *font, char *namep)
return;
}
+ /* validate the offset, and the data for the two
+ * values we're about to read
+ */
+ if (offset + 6 > font->length)
+ {
+ gs_warn("name table byte offset invalid");
+ return;
+ }
namedata = font->data + offset;
/*format = u16(namedata + 0);*/
count = u16(namedata + 2);
stringoffset = u16(namedata + 4);
+ if (stringoffset + offset > font->length
+ || offset + 6 + count * 12 > font->length)
+ {
+ gs_warn("name table invalid");
+ return;
+ }
+
if (length < 6 + (count * 12))
{
gs_warn("name table too short");
|
CWE-125
| null | null |
4,435
|
xps_encode_font_char_imp(xps_font_t *font, int code)
{
byte *table;
/* no cmap selected: return identity */
if (font->cmapsubtable <= 0)
return code;
table = font->data + font->cmapsubtable;
switch (u16(table))
{
case 0: /* Apple standard 1-to-1 mapping. */
return table[code + 6];
case 4: /* Microsoft/Adobe segmented mapping. */
{
int segCount2 = u16(table + 6);
byte *endCount = table + 14;
byte *startCount = endCount + segCount2 + 2;
byte *idDelta = startCount + segCount2;
byte *idRangeOffset = idDelta + segCount2;
int i2;
for (i2 = 0; i2 < segCount2 - 3; i2 += 2)
{
int delta, roff;
int start = u16(startCount + i2);
int glyph;
if ( code < start )
return 0;
if ( code > u16(endCount + i2) )
continue;
delta = s16(idDelta + i2);
roff = s16(idRangeOffset + i2);
if ( roff == 0 )
{
return ( code + delta ) & 0xffff; /* mod 65536 */
return 0;
}
glyph = u16(idRangeOffset + i2 + roff + ((code - start) << 1));
return (glyph == 0 ? 0 : glyph + delta);
}
/*
* The TrueType documentation says that the last range is
* always supposed to end with 0xffff, so this shouldn't
* happen; however, in some real fonts, it does.
*/
return 0;
}
case 6: /* Single interval lookup. */
{
int firstCode = u16(table + 6);
int entryCount = u16(table + 8);
if ( code < firstCode || code >= firstCode + entryCount )
return 0;
return u16(table + 10 + ((code - firstCode) << 1));
}
case 10: /* Trimmed array (like 6) */
{
int startCharCode = u32(table + 12);
int numChars = u32(table + 16);
if ( code < startCharCode || code >= startCharCode + numChars )
return 0;
return u32(table + 20 + (code - startCharCode) * 4);
}
case 12: /* Segmented coverage. (like 4) */
{
int nGroups = u32(table + 12);
byte *group = table + 16;
int i;
for (i = 0; i < nGroups; i++)
{
int startCharCode = u32(group + 0);
int endCharCode = u32(group + 4);
int startGlyphID = u32(group + 8);
if ( code < startCharCode )
return 0;
if ( code <= endCharCode )
return startGlyphID + (code - startCharCode);
group += 12;
}
return 0;
}
case 2: /* High-byte mapping through table. */
case 8: /* Mixed 16-bit and 32-bit coverage (like 2) */
default:
gs_warn1("unknown cmap format: %d\n", u16(table));
return 0;
}
return 0;
}
|
DoS
| 0
|
xps_encode_font_char_imp(xps_font_t *font, int code)
{
byte *table;
/* no cmap selected: return identity */
if (font->cmapsubtable <= 0)
return code;
table = font->data + font->cmapsubtable;
switch (u16(table))
{
case 0: /* Apple standard 1-to-1 mapping. */
return table[code + 6];
case 4: /* Microsoft/Adobe segmented mapping. */
{
int segCount2 = u16(table + 6);
byte *endCount = table + 14;
byte *startCount = endCount + segCount2 + 2;
byte *idDelta = startCount + segCount2;
byte *idRangeOffset = idDelta + segCount2;
int i2;
for (i2 = 0; i2 < segCount2 - 3; i2 += 2)
{
int delta, roff;
int start = u16(startCount + i2);
int glyph;
if ( code < start )
return 0;
if ( code > u16(endCount + i2) )
continue;
delta = s16(idDelta + i2);
roff = s16(idRangeOffset + i2);
if ( roff == 0 )
{
return ( code + delta ) & 0xffff; /* mod 65536 */
return 0;
}
glyph = u16(idRangeOffset + i2 + roff + ((code - start) << 1));
return (glyph == 0 ? 0 : glyph + delta);
}
/*
* The TrueType documentation says that the last range is
* always supposed to end with 0xffff, so this shouldn't
* happen; however, in some real fonts, it does.
*/
return 0;
}
case 6: /* Single interval lookup. */
{
int firstCode = u16(table + 6);
int entryCount = u16(table + 8);
if ( code < firstCode || code >= firstCode + entryCount )
return 0;
return u16(table + 10 + ((code - firstCode) << 1));
}
case 10: /* Trimmed array (like 6) */
{
int startCharCode = u32(table + 12);
int numChars = u32(table + 16);
if ( code < startCharCode || code >= startCharCode + numChars )
return 0;
return u32(table + 20 + (code - startCharCode) * 4);
}
case 12: /* Segmented coverage. (like 4) */
{
int nGroups = u32(table + 12);
byte *group = table + 16;
int i;
for (i = 0; i < nGroups; i++)
{
int startCharCode = u32(group + 0);
int endCharCode = u32(group + 4);
int startGlyphID = u32(group + 8);
if ( code < startCharCode )
return 0;
if ( code <= endCharCode )
return startGlyphID + (code - startCharCode);
group += 12;
}
return 0;
}
case 2: /* High-byte mapping through table. */
case 8: /* Mixed 16-bit and 32-bit coverage (like 2) */
default:
gs_warn1("unknown cmap format: %d\n", u16(table));
return 0;
}
return 0;
}
|
@@ -182,12 +182,27 @@ xps_load_sfnt_name(xps_font_t *font, char *namep)
return;
}
+ /* validate the offset, and the data for the two
+ * values we're about to read
+ */
+ if (offset + 6 > font->length)
+ {
+ gs_warn("name table byte offset invalid");
+ return;
+ }
namedata = font->data + offset;
/*format = u16(namedata + 0);*/
count = u16(namedata + 2);
stringoffset = u16(namedata + 4);
+ if (stringoffset + offset > font->length
+ || offset + 6 + count * 12 > font->length)
+ {
+ gs_warn("name table invalid");
+ return;
+ }
+
if (length < 6 + (count * 12))
{
gs_warn("name table too short");
|
CWE-125
| null | null |
4,436
|
xps_select_font_encoding(xps_font_t *font, int idx)
{
byte *cmapdata, *entry;
int pid, eid;
if (idx < 0 || idx >= font->cmapsubcount)
return;
cmapdata = font->data + font->cmaptable;
entry = cmapdata + 4 + idx * 8;
pid = u16(entry + 0);
eid = u16(entry + 2);
font->cmapsubtable = font->cmaptable + u32(entry + 4);
font->usepua = (pid == 3 && eid == 0);
}
|
DoS
| 0
|
xps_select_font_encoding(xps_font_t *font, int idx)
{
byte *cmapdata, *entry;
int pid, eid;
if (idx < 0 || idx >= font->cmapsubcount)
return;
cmapdata = font->data + font->cmaptable;
entry = cmapdata + 4 + idx * 8;
pid = u16(entry + 0);
eid = u16(entry + 2);
font->cmapsubtable = font->cmaptable + u32(entry + 4);
font->usepua = (pid == 3 && eid == 0);
}
|
@@ -182,12 +182,27 @@ xps_load_sfnt_name(xps_font_t *font, char *namep)
return;
}
+ /* validate the offset, and the data for the two
+ * values we're about to read
+ */
+ if (offset + 6 > font->length)
+ {
+ gs_warn("name table byte offset invalid");
+ return;
+ }
namedata = font->data + offset;
/*format = u16(namedata + 0);*/
count = u16(namedata + 2);
stringoffset = u16(namedata + 4);
+ if (stringoffset + offset > font->length
+ || offset + 6 + count * 12 > font->length)
+ {
+ gs_warn("name table invalid");
+ return;
+ }
+
if (length < 6 + (count * 12))
{
gs_warn("name table too short");
|
CWE-125
| null | null |
4,437
|
cleanup (pam_handle_t *pamh UNUSED, void *data, int err UNUSED)
{
free (data);
}
|
DoS
| 0
|
cleanup (pam_handle_t *pamh UNUSED, void *data, int err UNUSED)
{
free (data);
}
|
@@ -37,6 +37,9 @@
#include <sys/types.h>
#include <sys/fsuid.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <errno.h>
#include <fnmatch.h>
#include <grp.h>
@@ -232,9 +235,10 @@ check_acl(pam_handle_t *pamh,
{
char path[PATH_MAX];
struct passwd *pwd;
- FILE *fp;
- int i, save_errno;
+ FILE *fp = NULL;
+ int i, fd = -1, save_errno;
uid_t fsuid;
+ struct stat st;
/* Check this user's <sense> file. */
pwd = pam_modutil_getpwnam(pamh, this_user);
if (pwd == NULL) {
@@ -251,10 +255,27 @@ check_acl(pam_handle_t *pamh,
return PAM_SESSION_ERR;
}
fsuid = setfsuid(pwd->pw_uid);
- fp = fopen(path, "r");
+ if (!stat(path, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fd = open(path, O_RDONLY | O_NOCTTY);
+ }
save_errno = errno;
setfsuid(fsuid);
- if (fp != NULL) {
+ if (fd >= 0) {
+ if (!fstat(fd, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fp = fdopen(fd, "r");
+ }
+ if (!fp) {
+ save_errno = errno;
+ close(fd);
+ }
+ }
+ if (fp) {
char buf[LINE_MAX], *tmp;
/* Scan the file for a list of specs of users to "trust". */
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
CWE-399
| null | null |
4,438
|
pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
int argc, const char **argv)
{
void *cookiefile;
int i, debug = 0;
const char* user;
struct passwd *tpwd = NULL;
uid_t unlinkuid, fsuid;
if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS)
pam_syslog(pamh, LOG_ERR, "error determining target user's name");
else {
tpwd = pam_modutil_getpwnam(pamh, user);
if (!tpwd)
pam_syslog(pamh, LOG_ERR, "error determining target user's UID");
else
unlinkuid = tpwd->pw_uid;
}
/* Parse arguments. We don't understand many, so no sense in breaking
* this into a separate function. */
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0) {
debug = 1;
continue;
}
if (strncmp(argv[i], "xauthpath=", 10) == 0) {
continue;
}
if (strncmp(argv[i], "systemuser=", 11) == 0) {
continue;
}
if (strncmp(argv[i], "targetuser=", 11) == 0) {
continue;
}
pam_syslog(pamh, LOG_WARNING, "unrecognized option `%s'",
argv[i]);
}
/* Try to retrieve the name of a file we created when the session was
* opened. */
if (pam_get_data(pamh, DATANAME, (const void**) &cookiefile) == PAM_SUCCESS) {
/* We'll only try to remove the file once. */
if (strlen((char*)cookiefile) > 0) {
if (debug) {
pam_syslog(pamh, LOG_DEBUG, "removing `%s'",
(char*)cookiefile);
}
/* NFS with root_squash requires non-root user */
if (tpwd)
fsuid = setfsuid(unlinkuid);
unlink((char*)cookiefile);
if (tpwd)
setfsuid(fsuid);
*((char*)cookiefile) = '\0';
}
}
return PAM_SUCCESS;
}
|
DoS
| 0
|
pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
int argc, const char **argv)
{
void *cookiefile;
int i, debug = 0;
const char* user;
struct passwd *tpwd = NULL;
uid_t unlinkuid, fsuid;
if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS)
pam_syslog(pamh, LOG_ERR, "error determining target user's name");
else {
tpwd = pam_modutil_getpwnam(pamh, user);
if (!tpwd)
pam_syslog(pamh, LOG_ERR, "error determining target user's UID");
else
unlinkuid = tpwd->pw_uid;
}
/* Parse arguments. We don't understand many, so no sense in breaking
* this into a separate function. */
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0) {
debug = 1;
continue;
}
if (strncmp(argv[i], "xauthpath=", 10) == 0) {
continue;
}
if (strncmp(argv[i], "systemuser=", 11) == 0) {
continue;
}
if (strncmp(argv[i], "targetuser=", 11) == 0) {
continue;
}
pam_syslog(pamh, LOG_WARNING, "unrecognized option `%s'",
argv[i]);
}
/* Try to retrieve the name of a file we created when the session was
* opened. */
if (pam_get_data(pamh, DATANAME, (const void**) &cookiefile) == PAM_SUCCESS) {
/* We'll only try to remove the file once. */
if (strlen((char*)cookiefile) > 0) {
if (debug) {
pam_syslog(pamh, LOG_DEBUG, "removing `%s'",
(char*)cookiefile);
}
/* NFS with root_squash requires non-root user */
if (tpwd)
fsuid = setfsuid(unlinkuid);
unlink((char*)cookiefile);
if (tpwd)
setfsuid(fsuid);
*((char*)cookiefile) = '\0';
}
}
return PAM_SUCCESS;
}
|
@@ -37,6 +37,9 @@
#include <sys/types.h>
#include <sys/fsuid.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <errno.h>
#include <fnmatch.h>
#include <grp.h>
@@ -232,9 +235,10 @@ check_acl(pam_handle_t *pamh,
{
char path[PATH_MAX];
struct passwd *pwd;
- FILE *fp;
- int i, save_errno;
+ FILE *fp = NULL;
+ int i, fd = -1, save_errno;
uid_t fsuid;
+ struct stat st;
/* Check this user's <sense> file. */
pwd = pam_modutil_getpwnam(pamh, this_user);
if (pwd == NULL) {
@@ -251,10 +255,27 @@ check_acl(pam_handle_t *pamh,
return PAM_SESSION_ERR;
}
fsuid = setfsuid(pwd->pw_uid);
- fp = fopen(path, "r");
+ if (!stat(path, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fd = open(path, O_RDONLY | O_NOCTTY);
+ }
save_errno = errno;
setfsuid(fsuid);
- if (fp != NULL) {
+ if (fd >= 0) {
+ if (!fstat(fd, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fp = fdopen(fd, "r");
+ }
+ if (!fp) {
+ save_errno = errno;
+ close(fd);
+ }
+ }
+ if (fp) {
char buf[LINE_MAX], *tmp;
/* Scan the file for a list of specs of users to "trust". */
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
CWE-399
| null | null |
4,439
|
run_coprocess(pam_handle_t *pamh, const char *input, char **output,
uid_t uid, gid_t gid, const char *command, ...)
{
int ipipe[2], opipe[2], i;
char buf[LINE_MAX];
pid_t child;
char *buffer = NULL;
size_t buffer_size = 0;
va_list ap;
*output = NULL;
/* Create stdio pipery. */
if (pipe(ipipe) == -1) {
return -1;
}
if (pipe(opipe) == -1) {
close(ipipe[0]);
close(ipipe[1]);
return -1;
}
/* Fork off a child. */
child = fork();
if (child == -1) {
close(ipipe[0]);
close(ipipe[1]);
close(opipe[0]);
close(opipe[1]);
return -1;
}
if (child == 0) {
/* We're the child. */
size_t j;
char *args[10];
const char *tmp;
int maxopened;
/* Drop privileges. */
if (setgid(gid) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setgid(%lu) failed: %m",
(unsigned long) getegid ());
_exit (err);
}
if (setgroups(0, NULL) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setgroups() failed: %m");
_exit (err);
}
if (setuid(uid) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setuid(%lu) failed: %m",
(unsigned long) geteuid ());
_exit (err);
}
/* Initialize the argument list. */
memset(args, 0, sizeof(args));
/* Set the pipe descriptors up as stdin and stdout, and close
* everything else, including the original values for the
* descriptors. */
dup2(ipipe[0], STDIN_FILENO);
dup2(opipe[1], STDOUT_FILENO);
maxopened = (int)sysconf(_SC_OPEN_MAX);
for (i = 0; i < maxopened; i++) {
if ((i != STDIN_FILENO) && (i != STDOUT_FILENO)) {
close(i);
}
}
/* Convert the varargs list into a regular array of strings. */
va_start(ap, command);
args[0] = strdup(command);
for (j = 1; j < ((sizeof(args) / sizeof(args[0])) - 1); j++) {
tmp = va_arg(ap, const char*);
if (tmp == NULL) {
break;
}
args[j] = strdup(tmp);
}
/* Run the command. */
execv(command, args);
/* Never reached. */
_exit(1);
}
/* We're the parent, so close the other ends of the pipes. */
close(ipipe[0]);
close(opipe[1]);
/* Send input to the process (if we have any), then send an EOF. */
if (input) {
(void)pam_modutil_write(ipipe[1], input, strlen(input));
}
close(ipipe[1]);
/* Read data output until we run out of stuff to read. */
i = pam_modutil_read(opipe[0], buf, sizeof(buf));
while ((i != 0) && (i != -1)) {
char *tmp;
/* Resize the buffer to hold the data. */
tmp = realloc(buffer, buffer_size + i + 1);
if (tmp == NULL) {
/* Uh-oh, bail. */
if (buffer != NULL) {
free(buffer);
}
close(opipe[0]);
waitpid(child, NULL, 0);
return -1;
}
/* Save the new buffer location, copy the newly-read data into
* the buffer, and make sure the result will be
* nul-terminated. */
buffer = tmp;
memcpy(buffer + buffer_size, buf, i);
buffer[buffer_size + i] = '\0';
buffer_size += i;
/* Try to read again. */
i = pam_modutil_read(opipe[0], buf, sizeof(buf));
}
/* No more data. Clean up and return data. */
close(opipe[0]);
*output = buffer;
waitpid(child, NULL, 0);
return 0;
}
|
DoS
| 0
|
run_coprocess(pam_handle_t *pamh, const char *input, char **output,
uid_t uid, gid_t gid, const char *command, ...)
{
int ipipe[2], opipe[2], i;
char buf[LINE_MAX];
pid_t child;
char *buffer = NULL;
size_t buffer_size = 0;
va_list ap;
*output = NULL;
/* Create stdio pipery. */
if (pipe(ipipe) == -1) {
return -1;
}
if (pipe(opipe) == -1) {
close(ipipe[0]);
close(ipipe[1]);
return -1;
}
/* Fork off a child. */
child = fork();
if (child == -1) {
close(ipipe[0]);
close(ipipe[1]);
close(opipe[0]);
close(opipe[1]);
return -1;
}
if (child == 0) {
/* We're the child. */
size_t j;
char *args[10];
const char *tmp;
int maxopened;
/* Drop privileges. */
if (setgid(gid) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setgid(%lu) failed: %m",
(unsigned long) getegid ());
_exit (err);
}
if (setgroups(0, NULL) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setgroups() failed: %m");
_exit (err);
}
if (setuid(uid) == -1)
{
int err = errno;
pam_syslog (pamh, LOG_ERR, "setuid(%lu) failed: %m",
(unsigned long) geteuid ());
_exit (err);
}
/* Initialize the argument list. */
memset(args, 0, sizeof(args));
/* Set the pipe descriptors up as stdin and stdout, and close
* everything else, including the original values for the
* descriptors. */
dup2(ipipe[0], STDIN_FILENO);
dup2(opipe[1], STDOUT_FILENO);
maxopened = (int)sysconf(_SC_OPEN_MAX);
for (i = 0; i < maxopened; i++) {
if ((i != STDIN_FILENO) && (i != STDOUT_FILENO)) {
close(i);
}
}
/* Convert the varargs list into a regular array of strings. */
va_start(ap, command);
args[0] = strdup(command);
for (j = 1; j < ((sizeof(args) / sizeof(args[0])) - 1); j++) {
tmp = va_arg(ap, const char*);
if (tmp == NULL) {
break;
}
args[j] = strdup(tmp);
}
/* Run the command. */
execv(command, args);
/* Never reached. */
_exit(1);
}
/* We're the parent, so close the other ends of the pipes. */
close(ipipe[0]);
close(opipe[1]);
/* Send input to the process (if we have any), then send an EOF. */
if (input) {
(void)pam_modutil_write(ipipe[1], input, strlen(input));
}
close(ipipe[1]);
/* Read data output until we run out of stuff to read. */
i = pam_modutil_read(opipe[0], buf, sizeof(buf));
while ((i != 0) && (i != -1)) {
char *tmp;
/* Resize the buffer to hold the data. */
tmp = realloc(buffer, buffer_size + i + 1);
if (tmp == NULL) {
/* Uh-oh, bail. */
if (buffer != NULL) {
free(buffer);
}
close(opipe[0]);
waitpid(child, NULL, 0);
return -1;
}
/* Save the new buffer location, copy the newly-read data into
* the buffer, and make sure the result will be
* nul-terminated. */
buffer = tmp;
memcpy(buffer + buffer_size, buf, i);
buffer[buffer_size + i] = '\0';
buffer_size += i;
/* Try to read again. */
i = pam_modutil_read(opipe[0], buf, sizeof(buf));
}
/* No more data. Clean up and return data. */
close(opipe[0]);
*output = buffer;
waitpid(child, NULL, 0);
return 0;
}
|
@@ -37,6 +37,9 @@
#include <sys/types.h>
#include <sys/fsuid.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <errno.h>
#include <fnmatch.h>
#include <grp.h>
@@ -232,9 +235,10 @@ check_acl(pam_handle_t *pamh,
{
char path[PATH_MAX];
struct passwd *pwd;
- FILE *fp;
- int i, save_errno;
+ FILE *fp = NULL;
+ int i, fd = -1, save_errno;
uid_t fsuid;
+ struct stat st;
/* Check this user's <sense> file. */
pwd = pam_modutil_getpwnam(pamh, this_user);
if (pwd == NULL) {
@@ -251,10 +255,27 @@ check_acl(pam_handle_t *pamh,
return PAM_SESSION_ERR;
}
fsuid = setfsuid(pwd->pw_uid);
- fp = fopen(path, "r");
+ if (!stat(path, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fd = open(path, O_RDONLY | O_NOCTTY);
+ }
save_errno = errno;
setfsuid(fsuid);
- if (fp != NULL) {
+ if (fd >= 0) {
+ if (!fstat(fd, &st)) {
+ if (!S_ISREG(st.st_mode))
+ errno = EINVAL;
+ else
+ fp = fdopen(fd, "r");
+ }
+ if (!fp) {
+ save_errno = errno;
+ close(fd);
+ }
+ }
+ if (fp) {
char buf[LINE_MAX], *tmp;
/* Scan the file for a list of specs of users to "trust". */
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
CWE-399
| null | null |
4,440
|
_gcry_ecc_eddsa_compute_h_d (unsigned char **r_digest,
gcry_mpi_t d, mpi_ec_t ec)
{
gpg_err_code_t rc;
unsigned char *rawmpi = NULL;
unsigned int rawmpilen;
unsigned char *digest;
gcry_buffer_t hvec[2];
int hashalgo, b;
*r_digest = NULL;
hashalgo = GCRY_MD_SHA512;
if (hashalgo != GCRY_MD_SHA512)
return GPG_ERR_DIGEST_ALGO;
b = (ec->nbits+7)/8;
if (b != 256/8)
return GPG_ERR_INTERNAL; /* We only support 256 bit. */
/* Note that we clear DIGEST so we can use it as input to left pad
the key with zeroes for hashing. */
digest = xtrycalloc_secure (2, b);
if (!digest)
return gpg_err_code_from_syserror ();
memset (hvec, 0, sizeof hvec);
rawmpi = _gcry_mpi_get_buffer (d, 0, &rawmpilen, NULL);
if (!rawmpi)
{
xfree (digest);
return gpg_err_code_from_syserror ();
}
hvec[0].data = digest;
hvec[0].off = 0;
hvec[0].len = b > rawmpilen? b - rawmpilen : 0;
hvec[1].data = rawmpi;
hvec[1].off = 0;
hvec[1].len = rawmpilen;
rc = _gcry_md_hash_buffers (hashalgo, 0, digest, hvec, 2);
xfree (rawmpi);
if (rc)
{
xfree (digest);
return rc;
}
/* Compute the A value. */
reverse_buffer (digest, 32); /* Only the first half of the hash. */
digest[0] = (digest[0] & 0x7f) | 0x40;
digest[31] &= 0xf8;
*r_digest = digest;
return 0;
}
|
+Info
| 0
|
_gcry_ecc_eddsa_compute_h_d (unsigned char **r_digest,
gcry_mpi_t d, mpi_ec_t ec)
{
gpg_err_code_t rc;
unsigned char *rawmpi = NULL;
unsigned int rawmpilen;
unsigned char *digest;
gcry_buffer_t hvec[2];
int hashalgo, b;
*r_digest = NULL;
hashalgo = GCRY_MD_SHA512;
if (hashalgo != GCRY_MD_SHA512)
return GPG_ERR_DIGEST_ALGO;
b = (ec->nbits+7)/8;
if (b != 256/8)
return GPG_ERR_INTERNAL; /* We only support 256 bit. */
/* Note that we clear DIGEST so we can use it as input to left pad
the key with zeroes for hashing. */
digest = xtrycalloc_secure (2, b);
if (!digest)
return gpg_err_code_from_syserror ();
memset (hvec, 0, sizeof hvec);
rawmpi = _gcry_mpi_get_buffer (d, 0, &rawmpilen, NULL);
if (!rawmpi)
{
xfree (digest);
return gpg_err_code_from_syserror ();
}
hvec[0].data = digest;
hvec[0].off = 0;
hvec[0].len = b > rawmpilen? b - rawmpilen : 0;
hvec[1].data = rawmpi;
hvec[1].off = 0;
hvec[1].len = rawmpilen;
rc = _gcry_md_hash_buffers (hashalgo, 0, digest, hvec, 2);
xfree (rawmpi);
if (rc)
{
xfree (digest);
return rc;
}
/* Compute the A value. */
reverse_buffer (digest, 32); /* Only the first half of the hash. */
digest[0] = (digest[0] & 0x7f) | 0x40;
digest[31] &= 0xf8;
*r_digest = digest;
return 0;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,441
|
_gcry_ecc_eddsa_encodepoint (mpi_point_t point, mpi_ec_t ec,
gcry_mpi_t x_in, gcry_mpi_t y_in,
int with_prefix,
unsigned char **r_buffer, unsigned int *r_buflen)
{
gpg_err_code_t rc;
gcry_mpi_t x, y;
x = x_in? x_in : mpi_new (0);
y = y_in? y_in : mpi_new (0);
if (_gcry_mpi_ec_get_affine (x, y, point, ec))
{
log_error ("eddsa_encodepoint: Failed to get affine coordinates\n");
rc = GPG_ERR_INTERNAL;
}
else
rc = eddsa_encode_x_y (x, y, ec->nbits/8, with_prefix, r_buffer, r_buflen);
if (!x_in)
mpi_free (x);
if (!y_in)
mpi_free (y);
return rc;
}
|
+Info
| 0
|
_gcry_ecc_eddsa_encodepoint (mpi_point_t point, mpi_ec_t ec,
gcry_mpi_t x_in, gcry_mpi_t y_in,
int with_prefix,
unsigned char **r_buffer, unsigned int *r_buflen)
{
gpg_err_code_t rc;
gcry_mpi_t x, y;
x = x_in? x_in : mpi_new (0);
y = y_in? y_in : mpi_new (0);
if (_gcry_mpi_ec_get_affine (x, y, point, ec))
{
log_error ("eddsa_encodepoint: Failed to get affine coordinates\n");
rc = GPG_ERR_INTERNAL;
}
else
rc = eddsa_encode_x_y (x, y, ec->nbits/8, with_prefix, r_buffer, r_buflen);
if (!x_in)
mpi_free (x);
if (!y_in)
mpi_free (y);
return rc;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,442
|
_gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value, unsigned int nbits)
{
gpg_err_code_t rc;
const unsigned char *buf;
unsigned int rawmpilen;
gcry_mpi_t x, y;
unsigned char *enc;
unsigned int enclen;
if (!mpi_is_opaque (value))
return GPG_ERR_INV_OBJ;
buf = mpi_get_opaque (value, &rawmpilen);
if (!buf)
return GPG_ERR_INV_OBJ;
rawmpilen = (rawmpilen + 7)/8;
if (rawmpilen > 1 && (rawmpilen%2))
{
if (buf[0] == 0x04)
{
/* Buffer is in SEC1 uncompressed format. Extract y and
compress. */
rc = _gcry_mpi_scan (&x, GCRYMPI_FMT_STD,
buf+1, (rawmpilen-1)/2, NULL);
if (rc)
return rc;
rc = _gcry_mpi_scan (&y, GCRYMPI_FMT_STD,
buf+1+(rawmpilen-1)/2, (rawmpilen-1)/2, NULL);
if (rc)
{
mpi_free (x);
return rc;
}
rc = eddsa_encode_x_y (x, y, nbits/8, 0, &enc, &enclen);
mpi_free (x);
mpi_free (y);
if (rc)
return rc;
mpi_set_opaque (value, enc, 8*enclen);
}
else if (buf[0] == 0x40)
{
/* Buffer is compressed but with our SEC1 alike compression
indicator. Remove that byte. FIXME: We should write and
use a function to manipulate an opaque MPI in place. */
if (!_gcry_mpi_set_opaque_copy (value, buf + 1, (rawmpilen - 1)*8))
return gpg_err_code_from_syserror ();
}
}
return 0;
}
|
+Info
| 0
|
_gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value, unsigned int nbits)
{
gpg_err_code_t rc;
const unsigned char *buf;
unsigned int rawmpilen;
gcry_mpi_t x, y;
unsigned char *enc;
unsigned int enclen;
if (!mpi_is_opaque (value))
return GPG_ERR_INV_OBJ;
buf = mpi_get_opaque (value, &rawmpilen);
if (!buf)
return GPG_ERR_INV_OBJ;
rawmpilen = (rawmpilen + 7)/8;
if (rawmpilen > 1 && (rawmpilen%2))
{
if (buf[0] == 0x04)
{
/* Buffer is in SEC1 uncompressed format. Extract y and
compress. */
rc = _gcry_mpi_scan (&x, GCRYMPI_FMT_STD,
buf+1, (rawmpilen-1)/2, NULL);
if (rc)
return rc;
rc = _gcry_mpi_scan (&y, GCRYMPI_FMT_STD,
buf+1+(rawmpilen-1)/2, (rawmpilen-1)/2, NULL);
if (rc)
{
mpi_free (x);
return rc;
}
rc = eddsa_encode_x_y (x, y, nbits/8, 0, &enc, &enclen);
mpi_free (x);
mpi_free (y);
if (rc)
return rc;
mpi_set_opaque (value, enc, 8*enclen);
}
else if (buf[0] == 0x40)
{
/* Buffer is compressed but with our SEC1 alike compression
indicator. Remove that byte. FIXME: We should write and
use a function to manipulate an opaque MPI in place. */
if (!_gcry_mpi_set_opaque_copy (value, buf + 1, (rawmpilen - 1)*8))
return gpg_err_code_from_syserror ();
}
}
return 0;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,443
|
_gcry_ecc_eddsa_genkey (ECC_secret_key *sk, elliptic_curve_t *E, mpi_ec_t ctx,
int flags)
{
gpg_err_code_t rc;
int b = 256/8; /* The only size we currently support. */
gcry_mpi_t a, x, y;
mpi_point_struct Q;
gcry_random_level_t random_level;
char *dbuf;
size_t dlen;
gcry_buffer_t hvec[1];
unsigned char *hash_d = NULL;
point_init (&Q);
memset (hvec, 0, sizeof hvec);
if ((flags & PUBKEY_FLAG_TRANSIENT_KEY))
random_level = GCRY_STRONG_RANDOM;
else
random_level = GCRY_VERY_STRONG_RANDOM;
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
/* Generate a secret. */
hash_d = xtrymalloc_secure (2*b);
if (!hash_d)
{
rc = gpg_err_code_from_syserror ();
goto leave;
}
dlen = b;
dbuf = _gcry_random_bytes_secure (dlen, random_level);
/* Compute the A value. */
hvec[0].data = dbuf;
hvec[0].len = dlen;
rc = _gcry_md_hash_buffers (GCRY_MD_SHA512, 0, hash_d, hvec, 1);
if (rc)
goto leave;
sk->d = _gcry_mpi_set_opaque (NULL, dbuf, dlen*8);
dbuf = NULL;
reverse_buffer (hash_d, 32); /* Only the first half of the hash. */
hash_d[0] = (hash_d[0] & 0x7f) | 0x40;
hash_d[31] &= 0xf8;
_gcry_mpi_set_buffer (a, hash_d, 32, 0);
xfree (hash_d); hash_d = NULL;
/* log_printmpi ("ecgen a", a); */
/* Compute Q. */
_gcry_mpi_ec_mul_point (&Q, a, &E->G, ctx);
if (DBG_CIPHER)
log_printpnt ("ecgen pk", &Q, ctx);
/* Copy the stuff to the key structures. */
sk->E.model = E->model;
sk->E.dialect = E->dialect;
sk->E.p = mpi_copy (E->p);
sk->E.a = mpi_copy (E->a);
sk->E.b = mpi_copy (E->b);
point_init (&sk->E.G);
point_set (&sk->E.G, &E->G);
sk->E.n = mpi_copy (E->n);
sk->E.h = mpi_copy (E->h);
point_init (&sk->Q);
point_set (&sk->Q, &Q);
leave:
point_free (&Q);
_gcry_mpi_release (a);
_gcry_mpi_release (x);
_gcry_mpi_release (y);
xfree (hash_d);
return rc;
}
|
+Info
| 0
|
_gcry_ecc_eddsa_genkey (ECC_secret_key *sk, elliptic_curve_t *E, mpi_ec_t ctx,
int flags)
{
gpg_err_code_t rc;
int b = 256/8; /* The only size we currently support. */
gcry_mpi_t a, x, y;
mpi_point_struct Q;
gcry_random_level_t random_level;
char *dbuf;
size_t dlen;
gcry_buffer_t hvec[1];
unsigned char *hash_d = NULL;
point_init (&Q);
memset (hvec, 0, sizeof hvec);
if ((flags & PUBKEY_FLAG_TRANSIENT_KEY))
random_level = GCRY_STRONG_RANDOM;
else
random_level = GCRY_VERY_STRONG_RANDOM;
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
/* Generate a secret. */
hash_d = xtrymalloc_secure (2*b);
if (!hash_d)
{
rc = gpg_err_code_from_syserror ();
goto leave;
}
dlen = b;
dbuf = _gcry_random_bytes_secure (dlen, random_level);
/* Compute the A value. */
hvec[0].data = dbuf;
hvec[0].len = dlen;
rc = _gcry_md_hash_buffers (GCRY_MD_SHA512, 0, hash_d, hvec, 1);
if (rc)
goto leave;
sk->d = _gcry_mpi_set_opaque (NULL, dbuf, dlen*8);
dbuf = NULL;
reverse_buffer (hash_d, 32); /* Only the first half of the hash. */
hash_d[0] = (hash_d[0] & 0x7f) | 0x40;
hash_d[31] &= 0xf8;
_gcry_mpi_set_buffer (a, hash_d, 32, 0);
xfree (hash_d); hash_d = NULL;
/* log_printmpi ("ecgen a", a); */
/* Compute Q. */
_gcry_mpi_ec_mul_point (&Q, a, &E->G, ctx);
if (DBG_CIPHER)
log_printpnt ("ecgen pk", &Q, ctx);
/* Copy the stuff to the key structures. */
sk->E.model = E->model;
sk->E.dialect = E->dialect;
sk->E.p = mpi_copy (E->p);
sk->E.a = mpi_copy (E->a);
sk->E.b = mpi_copy (E->b);
point_init (&sk->E.G);
point_set (&sk->E.G, &E->G);
sk->E.n = mpi_copy (E->n);
sk->E.h = mpi_copy (E->h);
point_init (&sk->Q);
point_set (&sk->Q, &Q);
leave:
point_free (&Q);
_gcry_mpi_release (a);
_gcry_mpi_release (x);
_gcry_mpi_release (y);
xfree (hash_d);
return rc;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,444
|
eddsa_encodempi (gcry_mpi_t mpi, unsigned int minlen,
unsigned char **r_buffer, unsigned int *r_buflen)
{
unsigned char *rawmpi;
unsigned int rawmpilen;
rawmpi = _gcry_mpi_get_buffer (mpi, minlen, &rawmpilen, NULL);
if (!rawmpi)
return gpg_err_code_from_syserror ();
*r_buffer = rawmpi;
*r_buflen = rawmpilen;
return 0;
}
|
+Info
| 0
|
eddsa_encodempi (gcry_mpi_t mpi, unsigned int minlen,
unsigned char **r_buffer, unsigned int *r_buflen)
{
unsigned char *rawmpi;
unsigned int rawmpilen;
rawmpi = _gcry_mpi_get_buffer (mpi, minlen, &rawmpilen, NULL);
if (!rawmpi)
return gpg_err_code_from_syserror ();
*r_buffer = rawmpi;
*r_buflen = rawmpilen;
return 0;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,445
|
scanval (const char *string)
{
gpg_err_code_t rc;
gcry_mpi_t val;
rc = _gcry_mpi_scan (&val, GCRYMPI_FMT_HEX, string, 0, NULL);
if (rc)
log_fatal ("scanning ECC parameter failed: %s\n", gpg_strerror (rc));
return val;
}
|
+Info
| 0
|
scanval (const char *string)
{
gpg_err_code_t rc;
gcry_mpi_t val;
rc = _gcry_mpi_scan (&val, GCRYMPI_FMT_HEX, string, 0, NULL);
if (rc)
log_fatal ("scanning ECC parameter failed: %s\n", gpg_strerror (rc));
return val;
}
|
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;
|
CWE-200
| null | null |
4,446
|
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *p,*buf_in=NULL;
int ret= -1,i,inl;
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
inl=i2d(data,NULL);
buf_in=OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
p=buf_in;
i2d(data,&p);
if (!EVP_VerifyInit_ex(&ctx,type, NULL))
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
OPENSSL_cleanse(buf_in,(unsigned int)inl);
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
(unsigned int)signature->length,pkey) <= 0)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
/* we don't need to zero the 'ctx' because we just checked
* public information */
/* memset(&ctx,0,sizeof(ctx)); */
ret=1;
err:
EVP_MD_CTX_cleanup(&ctx);
return(ret);
}
|
DoS
| 0
|
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *p,*buf_in=NULL;
int ret= -1,i,inl;
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
inl=i2d(data,NULL);
buf_in=OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
p=buf_in;
i2d(data,&p);
if (!EVP_VerifyInit_ex(&ctx,type, NULL))
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
OPENSSL_cleanse(buf_in,(unsigned int)inl);
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
(unsigned int)signature->length,pkey) <= 0)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
/* we don't need to zero the 'ctx' because we just checked
* public information */
/* memset(&ctx,0,sizeof(ctx)); */
ret=1;
err:
EVP_MD_CTX_cleanup(&ctx);
return(ret);
}
|
@@ -138,6 +138,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
unsigned char *buf_in=NULL;
int ret= -1,i,inl;
+ if (!pkey)
+ {
+ ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
|
CWE-310
| null | null |
4,447
|
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *p,*buf_in=NULL;
int ret= -1,i,inl;
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
inl=i2d(data,NULL);
buf_in=OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
p=buf_in;
i2d(data,&p);
EVP_VerifyInit_ex(&ctx,type, NULL);
EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
OPENSSL_cleanse(buf_in,(unsigned int)inl);
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
(unsigned int)signature->length,pkey) <= 0)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
/* we don't need to zero the 'ctx' because we just checked
* public information */
/* memset(&ctx,0,sizeof(ctx)); */
ret=1;
err:
EVP_MD_CTX_cleanup(&ctx);
return(ret);
}
|
DoS
| 0
|
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *p,*buf_in=NULL;
int ret= -1,i,inl;
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
inl=i2d(data,NULL);
buf_in=OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
p=buf_in;
i2d(data,&p);
EVP_VerifyInit_ex(&ctx,type, NULL);
EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
OPENSSL_cleanse(buf_in,(unsigned int)inl);
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
(unsigned int)signature->length,pkey) <= 0)
{
ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
/* we don't need to zero the 'ctx' because we just checked
* public information */
/* memset(&ctx,0,sizeof(ctx)); */
ret=1;
err:
EVP_MD_CTX_cleanup(&ctx);
return(ret);
}
|
@@ -136,6 +136,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
int mdnid, pknid;
+ if (!pkey)
+ {
+ ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+
EVP_MD_CTX_init(&ctx);
/* Convert signature OID into digest and public key OIDs */
|
CWE-310
| null | null |
4,448
|
NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
const char *inherit_from_dir,
const char *fname,
SMB_STRUCT_STAT *psbuf)
{
struct smb_filename *smb_fname_parent;
struct smb_filename *smb_fname_cwd = NULL;
char *saved_dir = NULL;
TALLOC_CTX *ctx = talloc_tos();
NTSTATUS status = NT_STATUS_OK;
int ret;
smb_fname_parent = synthetic_smb_fname(ctx,
inherit_from_dir,
NULL,
NULL,
0);
if (smb_fname_parent == NULL) {
return NT_STATUS_NO_MEMORY;
}
ret = SMB_VFS_STAT(conn, smb_fname_parent);
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
smb_fname_str_dbg(smb_fname_parent),
strerror(errno)));
goto out;
}
/* We've already done an lstat into psbuf, and we know it's a
directory. If we can cd into the directory and the dev/ino
are the same then we can safely chown without races as
we're locking the directory in place by being in it. This
should work on any UNIX (thanks tridge :-). JRA.
*/
saved_dir = vfs_GetWd(ctx,conn);
if (!saved_dir) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to get "
"current working directory. Error was %s\n",
strerror(errno)));
goto out;
}
/* Chdir into the new path. */
if (vfs_ChDir(conn, fname) == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to change "
"current working directory to %s. Error "
"was %s\n", fname, strerror(errno) ));
goto chdir;
}
smb_fname_cwd = synthetic_smb_fname(ctx, ".", NULL, NULL, 0);
if (smb_fname_cwd == NULL) {
status = NT_STATUS_NO_MEMORY;
goto chdir;
}
ret = SMB_VFS_STAT(conn, smb_fname_cwd);
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat "
"directory '.' (%s) Error was %s\n",
fname, strerror(errno)));
goto chdir;
}
/* Ensure we're pointing at the same place. */
if (smb_fname_cwd->st.st_ex_dev != psbuf->st_ex_dev ||
smb_fname_cwd->st.st_ex_ino != psbuf->st_ex_ino) {
DEBUG(0,("change_dir_owner_to_parent: "
"device/inode on directory %s changed. "
"Refusing to chown !\n", fname ));
status = NT_STATUS_ACCESS_DENIED;
goto chdir;
}
if (smb_fname_parent->st.st_ex_uid == smb_fname_cwd->st.st_ex_uid) {
/* Already this uid - no need to change. */
DEBUG(10,("change_dir_owner_to_parent: directory %s "
"is already owned by uid %d\n",
fname,
(int)smb_fname_cwd->st.st_ex_uid ));
status = NT_STATUS_OK;
goto chdir;
}
become_root();
ret = SMB_VFS_LCHOWN(conn,
smb_fname_cwd,
smb_fname_parent->st.st_ex_uid,
(gid_t)-1);
unbecome_root();
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(10,("change_dir_owner_to_parent: failed to chown "
"directory %s to parent directory uid %u. "
"Error was %s\n", fname,
(unsigned int)smb_fname_parent->st.st_ex_uid,
strerror(errno) ));
} else {
DEBUG(10,("change_dir_owner_to_parent: changed ownership of new "
"directory %s to parent directory uid %u.\n",
fname, (unsigned int)smb_fname_parent->st.st_ex_uid ));
/* Ensure the uid entry is updated. */
psbuf->st_ex_uid = smb_fname_parent->st.st_ex_uid;
}
chdir:
vfs_ChDir(conn,saved_dir);
out:
TALLOC_FREE(smb_fname_parent);
TALLOC_FREE(smb_fname_cwd);
return status;
}
|
DoS
| 0
|
NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
const char *inherit_from_dir,
const char *fname,
SMB_STRUCT_STAT *psbuf)
{
struct smb_filename *smb_fname_parent;
struct smb_filename *smb_fname_cwd = NULL;
char *saved_dir = NULL;
TALLOC_CTX *ctx = talloc_tos();
NTSTATUS status = NT_STATUS_OK;
int ret;
smb_fname_parent = synthetic_smb_fname(ctx,
inherit_from_dir,
NULL,
NULL,
0);
if (smb_fname_parent == NULL) {
return NT_STATUS_NO_MEMORY;
}
ret = SMB_VFS_STAT(conn, smb_fname_parent);
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
smb_fname_str_dbg(smb_fname_parent),
strerror(errno)));
goto out;
}
/* We've already done an lstat into psbuf, and we know it's a
directory. If we can cd into the directory and the dev/ino
are the same then we can safely chown without races as
we're locking the directory in place by being in it. This
should work on any UNIX (thanks tridge :-). JRA.
*/
saved_dir = vfs_GetWd(ctx,conn);
if (!saved_dir) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to get "
"current working directory. Error was %s\n",
strerror(errno)));
goto out;
}
/* Chdir into the new path. */
if (vfs_ChDir(conn, fname) == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to change "
"current working directory to %s. Error "
"was %s\n", fname, strerror(errno) ));
goto chdir;
}
smb_fname_cwd = synthetic_smb_fname(ctx, ".", NULL, NULL, 0);
if (smb_fname_cwd == NULL) {
status = NT_STATUS_NO_MEMORY;
goto chdir;
}
ret = SMB_VFS_STAT(conn, smb_fname_cwd);
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat "
"directory '.' (%s) Error was %s\n",
fname, strerror(errno)));
goto chdir;
}
/* Ensure we're pointing at the same place. */
if (smb_fname_cwd->st.st_ex_dev != psbuf->st_ex_dev ||
smb_fname_cwd->st.st_ex_ino != psbuf->st_ex_ino) {
DEBUG(0,("change_dir_owner_to_parent: "
"device/inode on directory %s changed. "
"Refusing to chown !\n", fname ));
status = NT_STATUS_ACCESS_DENIED;
goto chdir;
}
if (smb_fname_parent->st.st_ex_uid == smb_fname_cwd->st.st_ex_uid) {
/* Already this uid - no need to change. */
DEBUG(10,("change_dir_owner_to_parent: directory %s "
"is already owned by uid %d\n",
fname,
(int)smb_fname_cwd->st.st_ex_uid ));
status = NT_STATUS_OK;
goto chdir;
}
become_root();
ret = SMB_VFS_LCHOWN(conn,
smb_fname_cwd,
smb_fname_parent->st.st_ex_uid,
(gid_t)-1);
unbecome_root();
if (ret == -1) {
status = map_nt_error_from_unix(errno);
DEBUG(10,("change_dir_owner_to_parent: failed to chown "
"directory %s to parent directory uid %u. "
"Error was %s\n", fname,
(unsigned int)smb_fname_parent->st.st_ex_uid,
strerror(errno) ));
} else {
DEBUG(10,("change_dir_owner_to_parent: changed ownership of new "
"directory %s to parent directory uid %u.\n",
fname, (unsigned int)smb_fname_parent->st.st_ex_uid ));
/* Ensure the uid entry is updated. */
psbuf->st_ex_uid = smb_fname_parent->st.st_ex_uid;
}
chdir:
vfs_ChDir(conn,saved_dir);
out:
TALLOC_FREE(smb_fname_parent);
TALLOC_FREE(smb_fname_cwd);
return status;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,449
|
void change_file_owner_to_parent(connection_struct *conn,
const char *inherit_from_dir,
files_struct *fsp)
{
struct smb_filename *smb_fname_parent;
int ret;
smb_fname_parent = synthetic_smb_fname(talloc_tos(),
inherit_from_dir,
NULL,
NULL,
0);
if (smb_fname_parent == NULL) {
return;
}
ret = SMB_VFS_STAT(conn, smb_fname_parent);
if (ret == -1) {
DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
smb_fname_str_dbg(smb_fname_parent),
strerror(errno)));
TALLOC_FREE(smb_fname_parent);
return;
}
if (smb_fname_parent->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
/* Already this uid - no need to change. */
DEBUG(10,("change_file_owner_to_parent: file %s "
"is already owned by uid %d\n",
fsp_str_dbg(fsp),
(int)fsp->fsp_name->st.st_ex_uid ));
TALLOC_FREE(smb_fname_parent);
return;
}
become_root();
ret = SMB_VFS_FCHOWN(fsp, smb_fname_parent->st.st_ex_uid, (gid_t)-1);
unbecome_root();
if (ret == -1) {
DEBUG(0,("change_file_owner_to_parent: failed to fchown "
"file %s to parent directory uid %u. Error "
"was %s\n", fsp_str_dbg(fsp),
(unsigned int)smb_fname_parent->st.st_ex_uid,
strerror(errno) ));
} else {
DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
"parent directory uid %u.\n", fsp_str_dbg(fsp),
(unsigned int)smb_fname_parent->st.st_ex_uid));
/* Ensure the uid entry is updated. */
fsp->fsp_name->st.st_ex_uid = smb_fname_parent->st.st_ex_uid;
}
TALLOC_FREE(smb_fname_parent);
}
|
DoS
| 0
|
void change_file_owner_to_parent(connection_struct *conn,
const char *inherit_from_dir,
files_struct *fsp)
{
struct smb_filename *smb_fname_parent;
int ret;
smb_fname_parent = synthetic_smb_fname(talloc_tos(),
inherit_from_dir,
NULL,
NULL,
0);
if (smb_fname_parent == NULL) {
return;
}
ret = SMB_VFS_STAT(conn, smb_fname_parent);
if (ret == -1) {
DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
smb_fname_str_dbg(smb_fname_parent),
strerror(errno)));
TALLOC_FREE(smb_fname_parent);
return;
}
if (smb_fname_parent->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
/* Already this uid - no need to change. */
DEBUG(10,("change_file_owner_to_parent: file %s "
"is already owned by uid %d\n",
fsp_str_dbg(fsp),
(int)fsp->fsp_name->st.st_ex_uid ));
TALLOC_FREE(smb_fname_parent);
return;
}
become_root();
ret = SMB_VFS_FCHOWN(fsp, smb_fname_parent->st.st_ex_uid, (gid_t)-1);
unbecome_root();
if (ret == -1) {
DEBUG(0,("change_file_owner_to_parent: failed to fchown "
"file %s to parent directory uid %u. Error "
"was %s\n", fsp_str_dbg(fsp),
(unsigned int)smb_fname_parent->st.st_ex_uid,
strerror(errno) ));
} else {
DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
"parent directory uid %u.\n", fsp_str_dbg(fsp),
(unsigned int)smb_fname_parent->st.st_ex_uid));
/* Ensure the uid entry is updated. */
fsp->fsp_name->st.st_ex_uid = smb_fname_parent->st.st_ex_uid;
}
TALLOC_FREE(smb_fname_parent);
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,450
|
NTSTATUS check_parent_access(struct connection_struct *conn,
struct smb_filename *smb_fname,
uint32_t access_mask)
{
NTSTATUS status;
char *parent_dir = NULL;
struct security_descriptor *parent_sd = NULL;
uint32_t access_granted = 0;
struct smb_filename *parent_smb_fname = NULL;
if (!parent_dirname(talloc_tos(),
smb_fname->base_name,
&parent_dir,
NULL)) {
return NT_STATUS_NO_MEMORY;
}
parent_smb_fname = synthetic_smb_fname(talloc_tos(),
parent_dir,
NULL,
NULL,
smb_fname->flags);
if (parent_smb_fname == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (get_current_uid(conn) == (uid_t)0) {
/* I'm sorry sir, I didn't know you were root... */
DEBUG(10,("check_parent_access: root override "
"on %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
status = SMB_VFS_GET_NT_ACL(conn,
parent_smb_fname,
SECINFO_DACL,
talloc_tos(),
&parent_sd);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(5,("check_parent_access: SMB_VFS_GET_NT_ACL failed for "
"%s with error %s\n",
parent_dir,
nt_errstr(status)));
return status;
}
/*
* If we can access the path to this file, by
* default we have FILE_READ_ATTRIBUTES from the
* containing directory. See the section:
* "Algorithm to Check Access to an Existing File"
* in MS-FSA.pdf.
*
* se_file_access_check() also takes care of
* owner WRITE_DAC and READ_CONTROL.
*/
status = se_file_access_check(parent_sd,
get_current_nttok(conn),
false,
(access_mask & ~FILE_READ_ATTRIBUTES),
&access_granted);
if(!NT_STATUS_IS_OK(status)) {
DEBUG(5,("check_parent_access: access check "
"on directory %s for "
"path %s for mask 0x%x returned (0x%x) %s\n",
parent_dir,
smb_fname->base_name,
access_mask,
access_granted,
nt_errstr(status) ));
return status;
}
return NT_STATUS_OK;
}
|
DoS
| 0
|
NTSTATUS check_parent_access(struct connection_struct *conn,
struct smb_filename *smb_fname,
uint32_t access_mask)
{
NTSTATUS status;
char *parent_dir = NULL;
struct security_descriptor *parent_sd = NULL;
uint32_t access_granted = 0;
struct smb_filename *parent_smb_fname = NULL;
if (!parent_dirname(talloc_tos(),
smb_fname->base_name,
&parent_dir,
NULL)) {
return NT_STATUS_NO_MEMORY;
}
parent_smb_fname = synthetic_smb_fname(talloc_tos(),
parent_dir,
NULL,
NULL,
smb_fname->flags);
if (parent_smb_fname == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (get_current_uid(conn) == (uid_t)0) {
/* I'm sorry sir, I didn't know you were root... */
DEBUG(10,("check_parent_access: root override "
"on %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
status = SMB_VFS_GET_NT_ACL(conn,
parent_smb_fname,
SECINFO_DACL,
talloc_tos(),
&parent_sd);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(5,("check_parent_access: SMB_VFS_GET_NT_ACL failed for "
"%s with error %s\n",
parent_dir,
nt_errstr(status)));
return status;
}
/*
* If we can access the path to this file, by
* default we have FILE_READ_ATTRIBUTES from the
* containing directory. See the section:
* "Algorithm to Check Access to an Existing File"
* in MS-FSA.pdf.
*
* se_file_access_check() also takes care of
* owner WRITE_DAC and READ_CONTROL.
*/
status = se_file_access_check(parent_sd,
get_current_nttok(conn),
false,
(access_mask & ~FILE_READ_ATTRIBUTES),
&access_granted);
if(!NT_STATUS_IS_OK(status)) {
DEBUG(5,("check_parent_access: access check "
"on directory %s for "
"path %s for mask 0x%x returned (0x%x) %s\n",
parent_dir,
smb_fname->base_name,
access_mask,
access_granted,
nt_errstr(status) ));
return status;
}
return NT_STATUS_OK;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,451
|
NTSTATUS fd_close(files_struct *fsp)
{
int ret;
if (fsp->dptr) {
dptr_CloseDir(fsp);
}
if (fsp->fh->fd == -1) {
return NT_STATUS_OK; /* What we used to call a stat open. */
}
if (fsp->fh->ref_count > 1) {
return NT_STATUS_OK; /* Shared handle. Only close last reference. */
}
ret = SMB_VFS_CLOSE(fsp);
fsp->fh->fd = -1;
if (ret == -1) {
return map_nt_error_from_unix(errno);
}
return NT_STATUS_OK;
}
|
DoS
| 0
|
NTSTATUS fd_close(files_struct *fsp)
{
int ret;
if (fsp->dptr) {
dptr_CloseDir(fsp);
}
if (fsp->fh->fd == -1) {
return NT_STATUS_OK; /* What we used to call a stat open. */
}
if (fsp->fh->ref_count > 1) {
return NT_STATUS_OK; /* Shared handle. Only close last reference. */
}
ret = SMB_VFS_CLOSE(fsp);
fsp->fh->fd = -1;
if (ret == -1) {
return map_nt_error_from_unix(errno);
}
return NT_STATUS_OK;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,452
|
NTSTATUS fd_open(struct connection_struct *conn,
files_struct *fsp,
int flags,
mode_t mode)
{
struct smb_filename *smb_fname = fsp->fsp_name;
NTSTATUS status = NT_STATUS_OK;
#ifdef O_NOFOLLOW
/*
* Never follow symlinks on a POSIX client. The
* client should be doing this.
*/
if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) || !lp_follow_symlinks(SNUM(conn))) {
flags |= O_NOFOLLOW;
}
#endif
fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
if (fsp->fh->fd == -1) {
int posix_errno = errno;
#ifdef O_NOFOLLOW
#if defined(ENOTSUP) && defined(OSF1)
/* handle special Tru64 errno */
if (errno == ENOTSUP) {
posix_errno = ELOOP;
}
#endif /* ENOTSUP */
#ifdef EFTYPE
/* fix broken NetBSD errno */
if (errno == EFTYPE) {
posix_errno = ELOOP;
}
#endif /* EFTYPE */
/* fix broken FreeBSD errno */
if (errno == EMLINK) {
posix_errno = ELOOP;
}
#endif /* O_NOFOLLOW */
status = map_nt_error_from_unix(posix_errno);
if (errno == EMFILE) {
static time_t last_warned = 0L;
if (time((time_t *) NULL) > last_warned) {
DEBUG(0,("Too many open files, unable "
"to open more! smbd's max "
"open files = %d\n",
lp_max_open_files()));
last_warned = time((time_t *) NULL);
}
}
}
DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
smb_fname_str_dbg(smb_fname), flags, (int)mode, fsp->fh->fd,
(fsp->fh->fd == -1) ? strerror(errno) : "" ));
return status;
}
|
DoS
| 0
|
NTSTATUS fd_open(struct connection_struct *conn,
files_struct *fsp,
int flags,
mode_t mode)
{
struct smb_filename *smb_fname = fsp->fsp_name;
NTSTATUS status = NT_STATUS_OK;
#ifdef O_NOFOLLOW
/*
* Never follow symlinks on a POSIX client. The
* client should be doing this.
*/
if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) || !lp_follow_symlinks(SNUM(conn))) {
flags |= O_NOFOLLOW;
}
#endif
fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
if (fsp->fh->fd == -1) {
int posix_errno = errno;
#ifdef O_NOFOLLOW
#if defined(ENOTSUP) && defined(OSF1)
/* handle special Tru64 errno */
if (errno == ENOTSUP) {
posix_errno = ELOOP;
}
#endif /* ENOTSUP */
#ifdef EFTYPE
/* fix broken NetBSD errno */
if (errno == EFTYPE) {
posix_errno = ELOOP;
}
#endif /* EFTYPE */
/* fix broken FreeBSD errno */
if (errno == EMLINK) {
posix_errno = ELOOP;
}
#endif /* O_NOFOLLOW */
status = map_nt_error_from_unix(posix_errno);
if (errno == EMFILE) {
static time_t last_warned = 0L;
if (time((time_t *) NULL) > last_warned) {
DEBUG(0,("Too many open files, unable "
"to open more! smbd's max "
"open files = %d\n",
lp_max_open_files()));
last_warned = time((time_t *) NULL);
}
}
}
DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
smb_fname_str_dbg(smb_fname), flags, (int)mode, fsp->fh->fd,
(fsp->fh->fd == -1) ? strerror(errno) : "" ));
return status;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,453
|
static bool parent_override_delete(connection_struct *conn,
const struct smb_filename *smb_fname,
uint32_t access_mask,
uint32_t rejected_mask)
{
if ((access_mask & DELETE_ACCESS) &&
(rejected_mask & DELETE_ACCESS) &&
can_delete_file_in_directory(conn, smb_fname)) {
return true;
}
return false;
}
|
DoS
| 0
|
static bool parent_override_delete(connection_struct *conn,
const struct smb_filename *smb_fname,
uint32_t access_mask,
uint32_t rejected_mask)
{
if ((access_mask & DELETE_ACCESS) &&
(rejected_mask & DELETE_ACCESS) &&
can_delete_file_in_directory(conn, smb_fname)) {
return true;
}
return false;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,454
|
NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
const struct smb_filename *smb_fname,
bool use_privs,
uint32_t access_mask)
{
/* Check if we have rights to open. */
NTSTATUS status;
struct security_descriptor *sd = NULL;
uint32_t rejected_share_access;
uint32_t rejected_mask = access_mask;
uint32_t do_not_check_mask = 0;
rejected_share_access = access_mask & ~(conn->share_access);
if (rejected_share_access) {
DEBUG(10, ("smbd_check_access_rights: rejected share access 0x%x "
"on %s (0x%x)\n",
(unsigned int)access_mask,
smb_fname_str_dbg(smb_fname),
(unsigned int)rejected_share_access ));
return NT_STATUS_ACCESS_DENIED;
}
if (!use_privs && get_current_uid(conn) == (uid_t)0) {
/* I'm sorry sir, I didn't know you were root... */
DEBUG(10,("smbd_check_access_rights: root override "
"on %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
if ((access_mask & DELETE_ACCESS) && !lp_acl_check_permissions(SNUM(conn))) {
DEBUG(10,("smbd_check_access_rights: not checking ACL "
"on DELETE_ACCESS on file %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
if (access_mask == DELETE_ACCESS &&
VALID_STAT(smb_fname->st) &&
S_ISLNK(smb_fname->st.st_ex_mode)) {
/* We can always delete a symlink. */
DEBUG(10,("smbd_check_access_rights: not checking ACL "
"on DELETE_ACCESS on symlink %s.\n",
smb_fname_str_dbg(smb_fname) ));
return NT_STATUS_OK;
}
status = SMB_VFS_GET_NT_ACL(conn, smb_fname,
(SECINFO_OWNER |
SECINFO_GROUP |
SECINFO_DACL), talloc_tos(), &sd);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("smbd_check_access_rights: Could not get acl "
"on %s: %s\n",
smb_fname_str_dbg(smb_fname),
nt_errstr(status)));
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
goto access_denied;
}
return status;
}
/*
* If we can access the path to this file, by
* default we have FILE_READ_ATTRIBUTES from the
* containing directory. See the section:
* "Algorithm to Check Access to an Existing File"
* in MS-FSA.pdf.
*
* se_file_access_check() also takes care of
* owner WRITE_DAC and READ_CONTROL.
*/
do_not_check_mask = FILE_READ_ATTRIBUTES;
/*
* Samba 3.6 and earlier granted execute access even
* if the ACL did not contain execute rights.
* Samba 4.0 is more correct and checks it.
* The compatibilty mode allows one to skip this check
* to smoothen upgrades.
*/
if (lp_acl_allow_execute_always(SNUM(conn))) {
do_not_check_mask |= FILE_EXECUTE;
}
status = se_file_access_check(sd,
get_current_nttok(conn),
use_privs,
(access_mask & ~do_not_check_mask),
&rejected_mask);
DEBUG(10,("smbd_check_access_rights: file %s requesting "
"0x%x returning 0x%x (%s)\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask,
(unsigned int)rejected_mask,
nt_errstr(status) ));
if (!NT_STATUS_IS_OK(status)) {
if (DEBUGLEVEL >= 10) {
DEBUG(10,("smbd_check_access_rights: acl for %s is:\n",
smb_fname_str_dbg(smb_fname) ));
NDR_PRINT_DEBUG(security_descriptor, sd);
}
}
TALLOC_FREE(sd);
if (NT_STATUS_IS_OK(status) ||
!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
return status;
}
/* Here we know status == NT_STATUS_ACCESS_DENIED. */
access_denied:
if ((access_mask & FILE_WRITE_ATTRIBUTES) &&
(rejected_mask & FILE_WRITE_ATTRIBUTES) &&
!lp_store_dos_attributes(SNUM(conn)) &&
(lp_map_readonly(SNUM(conn)) ||
lp_map_archive(SNUM(conn)) ||
lp_map_hidden(SNUM(conn)) ||
lp_map_system(SNUM(conn)))) {
rejected_mask &= ~FILE_WRITE_ATTRIBUTES;
DEBUG(10,("smbd_check_access_rights: "
"overrode "
"FILE_WRITE_ATTRIBUTES "
"on file %s\n",
smb_fname_str_dbg(smb_fname)));
}
if (parent_override_delete(conn,
smb_fname,
access_mask,
rejected_mask)) {
/* Were we trying to do an open
* for delete and didn't get DELETE
* access (only) ? Check if the
* directory allows DELETE_CHILD.
* See here:
* http://blogs.msdn.com/oldnewthing/archive/2004/06/04/148426.aspx
* for details. */
rejected_mask &= ~DELETE_ACCESS;
DEBUG(10,("smbd_check_access_rights: "
"overrode "
"DELETE_ACCESS on "
"file %s\n",
smb_fname_str_dbg(smb_fname)));
}
if (rejected_mask != 0) {
return NT_STATUS_ACCESS_DENIED;
}
return NT_STATUS_OK;
}
|
DoS
| 0
|
NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
const struct smb_filename *smb_fname,
bool use_privs,
uint32_t access_mask)
{
/* Check if we have rights to open. */
NTSTATUS status;
struct security_descriptor *sd = NULL;
uint32_t rejected_share_access;
uint32_t rejected_mask = access_mask;
uint32_t do_not_check_mask = 0;
rejected_share_access = access_mask & ~(conn->share_access);
if (rejected_share_access) {
DEBUG(10, ("smbd_check_access_rights: rejected share access 0x%x "
"on %s (0x%x)\n",
(unsigned int)access_mask,
smb_fname_str_dbg(smb_fname),
(unsigned int)rejected_share_access ));
return NT_STATUS_ACCESS_DENIED;
}
if (!use_privs && get_current_uid(conn) == (uid_t)0) {
/* I'm sorry sir, I didn't know you were root... */
DEBUG(10,("smbd_check_access_rights: root override "
"on %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
if ((access_mask & DELETE_ACCESS) && !lp_acl_check_permissions(SNUM(conn))) {
DEBUG(10,("smbd_check_access_rights: not checking ACL "
"on DELETE_ACCESS on file %s. Granting 0x%x\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask ));
return NT_STATUS_OK;
}
if (access_mask == DELETE_ACCESS &&
VALID_STAT(smb_fname->st) &&
S_ISLNK(smb_fname->st.st_ex_mode)) {
/* We can always delete a symlink. */
DEBUG(10,("smbd_check_access_rights: not checking ACL "
"on DELETE_ACCESS on symlink %s.\n",
smb_fname_str_dbg(smb_fname) ));
return NT_STATUS_OK;
}
status = SMB_VFS_GET_NT_ACL(conn, smb_fname,
(SECINFO_OWNER |
SECINFO_GROUP |
SECINFO_DACL), talloc_tos(), &sd);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("smbd_check_access_rights: Could not get acl "
"on %s: %s\n",
smb_fname_str_dbg(smb_fname),
nt_errstr(status)));
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
goto access_denied;
}
return status;
}
/*
* If we can access the path to this file, by
* default we have FILE_READ_ATTRIBUTES from the
* containing directory. See the section:
* "Algorithm to Check Access to an Existing File"
* in MS-FSA.pdf.
*
* se_file_access_check() also takes care of
* owner WRITE_DAC and READ_CONTROL.
*/
do_not_check_mask = FILE_READ_ATTRIBUTES;
/*
* Samba 3.6 and earlier granted execute access even
* if the ACL did not contain execute rights.
* Samba 4.0 is more correct and checks it.
* The compatibilty mode allows one to skip this check
* to smoothen upgrades.
*/
if (lp_acl_allow_execute_always(SNUM(conn))) {
do_not_check_mask |= FILE_EXECUTE;
}
status = se_file_access_check(sd,
get_current_nttok(conn),
use_privs,
(access_mask & ~do_not_check_mask),
&rejected_mask);
DEBUG(10,("smbd_check_access_rights: file %s requesting "
"0x%x returning 0x%x (%s)\n",
smb_fname_str_dbg(smb_fname),
(unsigned int)access_mask,
(unsigned int)rejected_mask,
nt_errstr(status) ));
if (!NT_STATUS_IS_OK(status)) {
if (DEBUGLEVEL >= 10) {
DEBUG(10,("smbd_check_access_rights: acl for %s is:\n",
smb_fname_str_dbg(smb_fname) ));
NDR_PRINT_DEBUG(security_descriptor, sd);
}
}
TALLOC_FREE(sd);
if (NT_STATUS_IS_OK(status) ||
!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
return status;
}
/* Here we know status == NT_STATUS_ACCESS_DENIED. */
access_denied:
if ((access_mask & FILE_WRITE_ATTRIBUTES) &&
(rejected_mask & FILE_WRITE_ATTRIBUTES) &&
!lp_store_dos_attributes(SNUM(conn)) &&
(lp_map_readonly(SNUM(conn)) ||
lp_map_archive(SNUM(conn)) ||
lp_map_hidden(SNUM(conn)) ||
lp_map_system(SNUM(conn)))) {
rejected_mask &= ~FILE_WRITE_ATTRIBUTES;
DEBUG(10,("smbd_check_access_rights: "
"overrode "
"FILE_WRITE_ATTRIBUTES "
"on file %s\n",
smb_fname_str_dbg(smb_fname)));
}
if (parent_override_delete(conn,
smb_fname,
access_mask,
rejected_mask)) {
/* Were we trying to do an open
* for delete and didn't get DELETE
* access (only) ? Check if the
* directory allows DELETE_CHILD.
* See here:
* http://blogs.msdn.com/oldnewthing/archive/2004/06/04/148426.aspx
* for details. */
rejected_mask &= ~DELETE_ACCESS;
DEBUG(10,("smbd_check_access_rights: "
"overrode "
"DELETE_ACCESS on "
"file %s\n",
smb_fname_str_dbg(smb_fname)));
}
if (rejected_mask != 0) {
return NT_STATUS_ACCESS_DENIED;
}
return NT_STATUS_OK;
}
|
@@ -640,7 +640,9 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
bool *file_created)
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS retry_status;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
+ int curr_flags;
*file_created = false;
@@ -672,59 +674,65 @@ static NTSTATUS fd_open_atomic(struct connection_struct *conn,
* we can never call O_CREAT without O_EXCL. So if
* we think the file existed, try without O_CREAT|O_EXCL.
* If we think the file didn't exist, try with
- * O_CREAT|O_EXCL. Keep bouncing between these two
- * requests until either the file is created, or
- * opened. Either way, we keep going until we get
- * a returnable result (error, or open/create).
+ * O_CREAT|O_EXCL.
+ *
+ * The big problem here is dangling symlinks. Opening
+ * without O_NOFOLLOW means both bad symlink
+ * and missing path return -1, ENOENT from open(). As POSIX
+ * is pathname based it's not possible to tell
+ * the difference between these two cases in a
+ * non-racy way, so change to try only two attempts before
+ * giving up.
+ *
+ * We don't have this problem for the O_NOFOLLOW
+ * case as it just returns NT_STATUS_OBJECT_PATH_NOT_FOUND
+ * mapped from the ELOOP POSIX error.
*/
- while(1) {
- int curr_flags = flags;
+ curr_flags = flags;
- if (file_existed) {
- /* Just try open, do not create. */
- curr_flags &= ~(O_CREAT);
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
- /*
- * Someone deleted it in the meantime.
- * Retry with O_EXCL.
- */
- file_existed = false;
- DEBUG(10,("fd_open_atomic: file %s existed. "
- "Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- } else {
- /* Try create exclusively, fail if it exists. */
- curr_flags |= O_EXCL;
- status = fd_open(conn, fsp, curr_flags, mode);
- if (NT_STATUS_EQUAL(status,
- NT_STATUS_OBJECT_NAME_COLLISION)) {
- /*
- * Someone created it in the meantime.
- * Retry without O_CREAT.
- */
- file_existed = true;
- DEBUG(10,("fd_open_atomic: file %s "
- "did not exist. Retry.\n",
- smb_fname_str_dbg(fsp->fsp_name)));
- continue;
- }
- if (NT_STATUS_IS_OK(status)) {
- /*
- * Here we've opened with O_CREAT|O_EXCL
- * and got success. We *know* we created
- * this file.
- */
- *file_created = true;
- }
+ if (file_existed) {
+ curr_flags &= ~(O_CREAT);
+ retry_status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ } else {
+ curr_flags |= O_EXCL;
+ retry_status = NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+ if (NT_STATUS_IS_OK(status)) {
+ if (!file_existed) {
+ *file_created = true;
}
- /* Create is done, or failed. */
- break;
+ return NT_STATUS_OK;
}
+ if (!NT_STATUS_EQUAL(status, retry_status)) {
+ return status;
+ }
+
+ curr_flags = flags;
+
+ /*
+ * Keep file_existed up to date for clarity.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ file_existed = false;
+ curr_flags |= O_EXCL;
+ DBG_DEBUG("file %s did not exist. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ } else {
+ file_existed = true;
+ curr_flags &= ~(O_CREAT);
+ DBG_DEBUG("file %s existed. Retry.\n",
+ smb_fname_str_dbg(fsp->fsp_name));
+ }
+
+ status = fd_open(conn, fsp, curr_flags, mode);
+
+ if (NT_STATUS_IS_OK(status) && (!file_existed)) {
+ *file_created = true;
+ }
+
return status;
}
|
CWE-835
| null | null |
4,455
|
another_hunk (enum diff difftype, bool rev)
{
char *s;
lin context = 0;
size_t chars_read;
char numbuf0[LINENUM_LENGTH_BOUND + 1];
char numbuf1[LINENUM_LENGTH_BOUND + 1];
char numbuf2[LINENUM_LENGTH_BOUND + 1];
char numbuf3[LINENUM_LENGTH_BOUND + 1];
while (p_end >= 0) {
if (p_end == p_efake)
p_end = p_bfake; /* don't free twice */
else
free(p_line[p_end]);
p_end--;
}
assert(p_end == -1);
p_efake = -1;
if (p_c_function)
{
free (p_c_function);
p_c_function = NULL;
}
p_max = hunkmax; /* gets reduced when --- found */
if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) {
file_offset line_beginning = file_tell (pfp);
/* file pos of the current line */
lin repl_beginning = 0; /* index of --- line */
lin fillcnt = 0; /* #lines of missing ptrn or repl */
lin fillsrc; /* index of first line to copy */
lin filldst; /* index of first missing line */
bool ptrn_spaces_eaten = false; /* ptrn was slightly misformed */
bool some_context = false; /* (perhaps internal) context seen */
bool repl_could_be_missing = true;
bool ptrn_missing = false; /* The pattern was missing. */
bool repl_missing = false; /* Likewise for replacement. */
file_offset repl_backtrack_position = 0;
/* file pos of first repl line */
lin repl_patch_line; /* input line number for same */
lin repl_context; /* context for same */
lin ptrn_prefix_context = -1; /* lines in pattern prefix context */
lin ptrn_suffix_context = -1; /* lines in pattern suffix context */
lin repl_prefix_context = -1; /* lines in replac. prefix context */
lin ptrn_copiable = 0; /* # of copiable lines in ptrn */
lin repl_copiable = 0; /* Likewise for replacement. */
/* Pacify `gcc -Wall'. */
fillsrc = filldst = repl_patch_line = repl_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 8
|| strncmp (buf, "********", 8) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = buf;
while (*s == '*')
s++;
if (*s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
}
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
return -1;
if (!chars_read) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (p_max - p_end < 4) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 3;
} else {
fatal ("unexpected end of file in patch");
}
}
p_end++;
if (p_end == hunkmax)
fatal ("unterminated hunk starting at line %s; giving up at line %s: %s",
format_linenum (numbuf0, pch_hunk_beg ()),
format_linenum (numbuf1, p_input_line), buf);
assert(p_end < hunkmax);
p_Char[p_end] = *buf;
p_len[p_end] = 0;
p_line[p_end] = 0;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
else
fatal ("unexpected end of hunk at line %s",
format_linenum (numbuf0, p_input_line));
}
if (p_end != 0) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
fatal ("unexpected `***' at line %s: %s",
format_linenum (numbuf0, p_input_line), buf);
}
context = 0;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf))) {
p_end--;
return -1;
}
for (s = buf; *s && !ISDIGIT (*s); s++)
/* do nothing */ ;
if (strnEQ(s,"0,0",3))
remove_prefix (s, 2);
s = scan_linenum (s, &p_first);
if (*s == ',') {
while (*s && !ISDIGIT (*s))
s++;
scan_linenum (s, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else if (p_first)
p_ptrn_lines = 1;
else {
p_ptrn_lines = 0;
p_first = 1;
}
p_max = p_ptrn_lines + 6; /* we need this much at least */
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
p_max = hunkmax;
break;
case '-':
if (buf[1] != '-')
goto change_line;
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
ptrn_suffix_context = context;
if (repl_beginning
|| (p_end
!= p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n')))
{
if (p_end == 1)
{
/* `Old' lines were omitted. Set up to fill
them in from `new' context lines. */
ptrn_missing = true;
p_end = p_ptrn_lines + 1;
ptrn_prefix_context = ptrn_suffix_context = -1;
fillsrc = p_end + 1;
filldst = 1;
fillcnt = p_ptrn_lines;
}
else if (! repl_beginning)
fatal ("%s `---' at line %s; check line numbers at line %s",
(p_end <= p_ptrn_lines
? "Premature"
: "Overdue"),
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1, p_hunk_beg));
else if (! repl_could_be_missing)
fatal ("duplicate `---' at line %s; check line numbers at line %s",
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1,
p_hunk_beg + repl_beginning));
else
{
repl_missing = true;
goto hunk_done;
}
}
repl_beginning = p_end;
repl_backtrack_position = file_tell (pfp);
repl_patch_line = p_input_line;
repl_context = context;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf)))
{
p_end--;
return -1;
}
p_Char[p_end] = '=';
for (s = buf; *s && ! ISDIGIT (*s); s++)
/* do nothing */ ;
s = scan_linenum (s, &p_newfirst);
if (*s == ',')
{
do
{
if (!*++s)
malformed ();
}
while (! ISDIGIT (*s));
scan_linenum (s, &p_repl_lines);
p_repl_lines += 1 - p_newfirst;
}
else if (p_newfirst)
p_repl_lines = 1;
else
{
p_repl_lines = 0;
p_newfirst = 1;
}
p_max = p_repl_lines + p_end;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
if (p_repl_lines != ptrn_copiable
&& (p_prefix_context != 0
|| context != 0
|| p_repl_lines != 1))
repl_could_be_missing = false;
context = 0;
break;
case '+': case '!':
repl_could_be_missing = false;
change_line:
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize) {
strcpy (s, " \n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (! repl_beginning)
{
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
}
else
{
if (repl_prefix_context == -1)
repl_prefix_context = context;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
context = 0;
break;
case '\t': case '\n': /* assume spaces got eaten */
s = buf;
if (*buf == '\t') {
s++;
chars_read--;
}
if (repl_beginning && repl_could_be_missing &&
(!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) {
repl_missing = true;
goto hunk_done;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (buf, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
if (p_end != p_ptrn_lines + 1) {
ptrn_spaces_eaten |= (repl_beginning != 0);
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
p_Char[p_end] = ' ';
}
break;
case ' ':
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize) {
strcpy (s, "\n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
break;
default:
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
malformed ();
}
}
hunk_done:
if (p_end >=0 && !repl_beginning)
fatal ("no `---' found in patch at line %s",
format_linenum (numbuf0, pch_hunk_beg ()));
if (repl_missing) {
/* reset state back to just after --- */
p_input_line = repl_patch_line;
context = repl_context;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
Fseek (pfp, repl_backtrack_position, SEEK_SET);
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
fillsrc = 1;
filldst = repl_beginning+1;
fillcnt = p_repl_lines;
p_end = p_max;
}
else if (! ptrn_missing && ptrn_copiable != repl_copiable)
fatal ("context mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
else if (!some_context && fillcnt == 1) {
/* the first hunk was a null hunk with no context */
/* and we were expecting one line -- fix it up. */
while (filldst < p_end) {
p_line[filldst] = p_line[filldst+1];
p_Char[filldst] = p_Char[filldst+1];
p_len[filldst] = p_len[filldst+1];
filldst++;
}
#if 0
repl_beginning--; /* this doesn't need to be fixed */
#endif
p_end--;
p_first++; /* do append rather than insert */
fillcnt = 0;
p_ptrn_lines = 0;
}
p_prefix_context = ((repl_prefix_context == -1
|| (ptrn_prefix_context != -1
&& ptrn_prefix_context < repl_prefix_context))
? ptrn_prefix_context : repl_prefix_context);
p_suffix_context = ((ptrn_suffix_context != -1
&& ptrn_suffix_context < context)
? ptrn_suffix_context : context);
assert (p_prefix_context != -1 && p_suffix_context != -1);
if (difftype == CONTEXT_DIFF
&& (fillcnt
|| (p_first > 1
&& p_prefix_context + p_suffix_context < ptrn_copiable))) {
if (verbosity == VERBOSE)
say ("%s\n%s\n%s\n",
"(Fascinating -- this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
diff_type = difftype = NEW_CONTEXT_DIFF;
}
/* if there were omitted context lines, fill them in now */
if (fillcnt) {
p_bfake = filldst; /* remember where not to free() */
p_efake = filldst + fillcnt - 1;
while (fillcnt-- > 0) {
while (fillsrc <= p_end && fillsrc != repl_beginning
&& p_Char[fillsrc] != ' ')
fillsrc++;
if (p_end < fillsrc || fillsrc == repl_beginning)
{
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
}
p_line[filldst] = p_line[fillsrc];
p_Char[filldst] = p_Char[fillsrc];
p_len[filldst] = p_len[fillsrc];
fillsrc++; filldst++;
}
while (fillsrc <= p_end && fillsrc != repl_beginning)
{
if (p_Char[fillsrc] == ' ')
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
fillsrc++;
}
if (debug & 64)
printf ("fillsrc %s, filldst %s, rb %s, e+1 %s\n",
format_linenum (numbuf0, fillsrc),
format_linenum (numbuf1, filldst),
format_linenum (numbuf2, repl_beginning),
format_linenum (numbuf3, p_end + 1));
assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
assert(filldst==p_end+1 || filldst==repl_beginning);
}
}
else if (difftype == UNI_DIFF) {
file_offset line_beginning = file_tell (pfp); /* file pos of the current line */
lin fillsrc; /* index of old lines */
lin filldst; /* index of new lines */
char ch = '\0';
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 4
|| strncmp (buf, "@@ -", 4) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf + 4, &p_first);
if (*s == ',')
s = scan_linenum (s + 1, &p_ptrn_lines);
else
p_ptrn_lines = 1;
if (*s == ' ') s++;
if (*s != '+')
malformed ();
s = scan_linenum (s + 1, &p_newfirst);
if (*s == ',')
s = scan_linenum (s + 1, &p_repl_lines);
else
p_repl_lines = 1;
if (*s == ' ') s++;
if (*s++ != '@')
malformed ();
if (*s++ == '@' && *s == ' ' && *s != '\0')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
}
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
if (!p_repl_lines)
p_newfirst++;
p_max = p_ptrn_lines + p_repl_lines + 1;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
sprintf (buf, "*** %s,%s ****\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
sprintf (buf, "--- %s,%s ----\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_newfirst + p_repl_lines - 1));
p_len[filldst] = strlen (buf);
if (! (p_line[filldst] = savestr (buf))) {
p_end = 0;
return -1;
}
p_Char[filldst++] = '=';
p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
chars_read = get_line ();
if (!chars_read) {
if (p_max - filldst < 3) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 2;
} else {
fatal ("unexpected end of file in patch");
}
}
if (chars_read == (size_t) -1)
s = 0;
else if (*buf == '\t' || *buf == '\n') {
ch = ' '; /* assume the space got eaten */
s = savebuf (buf, chars_read);
}
else {
ch = *buf;
s = savebuf (buf+1, --chars_read);
}
if (chars_read && ! s)
{
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
switch (ch) {
case '-':
if (fillsrc > p_ptrn_lines) {
free(s);
p_end = filldst-1;
malformed ();
}
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
break;
case '=':
ch = ' ';
/* FALL THROUGH */
case ' ':
if (fillsrc > p_ptrn_lines) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
context++;
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
s = savebuf (s, chars_read);
if (chars_read && ! s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
/* FALL THROUGH */
case '+':
if (filldst > p_end) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
chars_read -= filldst == p_end && incomplete_line ();
p_Char[filldst] = ch;
p_line[filldst] = s;
p_len[filldst++] = chars_read;
break;
default:
p_end = filldst;
malformed ();
}
if (ch != ' ') {
if (p_prefix_context == -1)
p_prefix_context = context;
context = 0;
}
}/* while */
if (p_prefix_context == -1)
malformed ();
p_suffix_context = context;
}
else { /* normal diff--fake it up */
char hunk_type;
int i;
lin min, max;
file_offset line_beginning = file_tell (pfp);
p_prefix_context = p_suffix_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf, &p_first);
if (*s == ',') {
s = scan_linenum (s + 1, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else
p_ptrn_lines = (*s != 'a');
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
s = scan_linenum (s + 1, &min);
if (*s == ',')
scan_linenum (s + 1, &max);
else
max = min;
if (hunk_type == 'd')
min++;
p_end = p_ptrn_lines + 1 + max - min + 1;
while (p_end + 1 >= hunkmax)
if (! grow_hunkmax ())
{
p_end = -1;
return -1;
}
p_newfirst = min;
p_repl_lines = max - min + 1;
sprintf (buf, "*** %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
for (i=1; i<=p_ptrn_lines; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("`<' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '-';
}
if (hunk_type == 'c') {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (! chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (*buf != '-')
fatal ("`---' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
}
sprintf (buf, "--- %s,%s\n",
format_linenum (numbuf0, min),
format_linenum (numbuf1, max));
p_len[i] = strlen (buf);
if (! (p_line[i] = savestr (buf))) {
p_end = i-1;
return -1;
}
p_Char[i] = '=';
for (i++; i<=p_end; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("`>' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_end && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '+';
}
}
if (rev) /* backwards patch? */
if (!pch_swap())
say ("Not enough memory to swap next hunk!\n");
assert (p_end + 1 < hunkmax);
p_Char[p_end + 1] = '^'; /* add a stopper for apply_hunk */
if (debug & 2) {
lin i;
for (i = 0; i <= p_end + 1; i++) {
fprintf (stderr, "%s %c",
format_linenum (numbuf0, i),
p_Char[i]);
if (p_Char[i] == '*')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_ptrn_lines));
else if (p_Char[i] == '=')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_repl_lines));
else if (p_Char[i] != '^')
{
fputs(" |", stderr);
pch_write_line (i, stderr);
}
else
fputc('\n', stderr);
}
fflush (stderr);
}
return 1;
}
|
Dir. Trav.
| 0
|
another_hunk (enum diff difftype, bool rev)
{
char *s;
lin context = 0;
size_t chars_read;
char numbuf0[LINENUM_LENGTH_BOUND + 1];
char numbuf1[LINENUM_LENGTH_BOUND + 1];
char numbuf2[LINENUM_LENGTH_BOUND + 1];
char numbuf3[LINENUM_LENGTH_BOUND + 1];
while (p_end >= 0) {
if (p_end == p_efake)
p_end = p_bfake; /* don't free twice */
else
free(p_line[p_end]);
p_end--;
}
assert(p_end == -1);
p_efake = -1;
if (p_c_function)
{
free (p_c_function);
p_c_function = NULL;
}
p_max = hunkmax; /* gets reduced when --- found */
if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) {
file_offset line_beginning = file_tell (pfp);
/* file pos of the current line */
lin repl_beginning = 0; /* index of --- line */
lin fillcnt = 0; /* #lines of missing ptrn or repl */
lin fillsrc; /* index of first line to copy */
lin filldst; /* index of first missing line */
bool ptrn_spaces_eaten = false; /* ptrn was slightly misformed */
bool some_context = false; /* (perhaps internal) context seen */
bool repl_could_be_missing = true;
bool ptrn_missing = false; /* The pattern was missing. */
bool repl_missing = false; /* Likewise for replacement. */
file_offset repl_backtrack_position = 0;
/* file pos of first repl line */
lin repl_patch_line; /* input line number for same */
lin repl_context; /* context for same */
lin ptrn_prefix_context = -1; /* lines in pattern prefix context */
lin ptrn_suffix_context = -1; /* lines in pattern suffix context */
lin repl_prefix_context = -1; /* lines in replac. prefix context */
lin ptrn_copiable = 0; /* # of copiable lines in ptrn */
lin repl_copiable = 0; /* Likewise for replacement. */
/* Pacify `gcc -Wall'. */
fillsrc = filldst = repl_patch_line = repl_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 8
|| strncmp (buf, "********", 8) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = buf;
while (*s == '*')
s++;
if (*s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
}
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
return -1;
if (!chars_read) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (p_max - p_end < 4) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 3;
} else {
fatal ("unexpected end of file in patch");
}
}
p_end++;
if (p_end == hunkmax)
fatal ("unterminated hunk starting at line %s; giving up at line %s: %s",
format_linenum (numbuf0, pch_hunk_beg ()),
format_linenum (numbuf1, p_input_line), buf);
assert(p_end < hunkmax);
p_Char[p_end] = *buf;
p_len[p_end] = 0;
p_line[p_end] = 0;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
else
fatal ("unexpected end of hunk at line %s",
format_linenum (numbuf0, p_input_line));
}
if (p_end != 0) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
fatal ("unexpected `***' at line %s: %s",
format_linenum (numbuf0, p_input_line), buf);
}
context = 0;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf))) {
p_end--;
return -1;
}
for (s = buf; *s && !ISDIGIT (*s); s++)
/* do nothing */ ;
if (strnEQ(s,"0,0",3))
remove_prefix (s, 2);
s = scan_linenum (s, &p_first);
if (*s == ',') {
while (*s && !ISDIGIT (*s))
s++;
scan_linenum (s, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else if (p_first)
p_ptrn_lines = 1;
else {
p_ptrn_lines = 0;
p_first = 1;
}
p_max = p_ptrn_lines + 6; /* we need this much at least */
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
p_max = hunkmax;
break;
case '-':
if (buf[1] != '-')
goto change_line;
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
ptrn_suffix_context = context;
if (repl_beginning
|| (p_end
!= p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n')))
{
if (p_end == 1)
{
/* `Old' lines were omitted. Set up to fill
them in from `new' context lines. */
ptrn_missing = true;
p_end = p_ptrn_lines + 1;
ptrn_prefix_context = ptrn_suffix_context = -1;
fillsrc = p_end + 1;
filldst = 1;
fillcnt = p_ptrn_lines;
}
else if (! repl_beginning)
fatal ("%s `---' at line %s; check line numbers at line %s",
(p_end <= p_ptrn_lines
? "Premature"
: "Overdue"),
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1, p_hunk_beg));
else if (! repl_could_be_missing)
fatal ("duplicate `---' at line %s; check line numbers at line %s",
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1,
p_hunk_beg + repl_beginning));
else
{
repl_missing = true;
goto hunk_done;
}
}
repl_beginning = p_end;
repl_backtrack_position = file_tell (pfp);
repl_patch_line = p_input_line;
repl_context = context;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf)))
{
p_end--;
return -1;
}
p_Char[p_end] = '=';
for (s = buf; *s && ! ISDIGIT (*s); s++)
/* do nothing */ ;
s = scan_linenum (s, &p_newfirst);
if (*s == ',')
{
do
{
if (!*++s)
malformed ();
}
while (! ISDIGIT (*s));
scan_linenum (s, &p_repl_lines);
p_repl_lines += 1 - p_newfirst;
}
else if (p_newfirst)
p_repl_lines = 1;
else
{
p_repl_lines = 0;
p_newfirst = 1;
}
p_max = p_repl_lines + p_end;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
if (p_repl_lines != ptrn_copiable
&& (p_prefix_context != 0
|| context != 0
|| p_repl_lines != 1))
repl_could_be_missing = false;
context = 0;
break;
case '+': case '!':
repl_could_be_missing = false;
change_line:
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize) {
strcpy (s, " \n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (! repl_beginning)
{
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
}
else
{
if (repl_prefix_context == -1)
repl_prefix_context = context;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
context = 0;
break;
case '\t': case '\n': /* assume spaces got eaten */
s = buf;
if (*buf == '\t') {
s++;
chars_read--;
}
if (repl_beginning && repl_could_be_missing &&
(!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) {
repl_missing = true;
goto hunk_done;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (buf, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
if (p_end != p_ptrn_lines + 1) {
ptrn_spaces_eaten |= (repl_beginning != 0);
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
p_Char[p_end] = ' ';
}
break;
case ' ':
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize) {
strcpy (s, "\n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
break;
default:
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
malformed ();
}
}
hunk_done:
if (p_end >=0 && !repl_beginning)
fatal ("no `---' found in patch at line %s",
format_linenum (numbuf0, pch_hunk_beg ()));
if (repl_missing) {
/* reset state back to just after --- */
p_input_line = repl_patch_line;
context = repl_context;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
Fseek (pfp, repl_backtrack_position, SEEK_SET);
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
fillsrc = 1;
filldst = repl_beginning+1;
fillcnt = p_repl_lines;
p_end = p_max;
}
else if (! ptrn_missing && ptrn_copiable != repl_copiable)
fatal ("context mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
else if (!some_context && fillcnt == 1) {
/* the first hunk was a null hunk with no context */
/* and we were expecting one line -- fix it up. */
while (filldst < p_end) {
p_line[filldst] = p_line[filldst+1];
p_Char[filldst] = p_Char[filldst+1];
p_len[filldst] = p_len[filldst+1];
filldst++;
}
#if 0
repl_beginning--; /* this doesn't need to be fixed */
#endif
p_end--;
p_first++; /* do append rather than insert */
fillcnt = 0;
p_ptrn_lines = 0;
}
p_prefix_context = ((repl_prefix_context == -1
|| (ptrn_prefix_context != -1
&& ptrn_prefix_context < repl_prefix_context))
? ptrn_prefix_context : repl_prefix_context);
p_suffix_context = ((ptrn_suffix_context != -1
&& ptrn_suffix_context < context)
? ptrn_suffix_context : context);
assert (p_prefix_context != -1 && p_suffix_context != -1);
if (difftype == CONTEXT_DIFF
&& (fillcnt
|| (p_first > 1
&& p_prefix_context + p_suffix_context < ptrn_copiable))) {
if (verbosity == VERBOSE)
say ("%s\n%s\n%s\n",
"(Fascinating -- this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
diff_type = difftype = NEW_CONTEXT_DIFF;
}
/* if there were omitted context lines, fill them in now */
if (fillcnt) {
p_bfake = filldst; /* remember where not to free() */
p_efake = filldst + fillcnt - 1;
while (fillcnt-- > 0) {
while (fillsrc <= p_end && fillsrc != repl_beginning
&& p_Char[fillsrc] != ' ')
fillsrc++;
if (p_end < fillsrc || fillsrc == repl_beginning)
{
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
}
p_line[filldst] = p_line[fillsrc];
p_Char[filldst] = p_Char[fillsrc];
p_len[filldst] = p_len[fillsrc];
fillsrc++; filldst++;
}
while (fillsrc <= p_end && fillsrc != repl_beginning)
{
if (p_Char[fillsrc] == ' ')
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
fillsrc++;
}
if (debug & 64)
printf ("fillsrc %s, filldst %s, rb %s, e+1 %s\n",
format_linenum (numbuf0, fillsrc),
format_linenum (numbuf1, filldst),
format_linenum (numbuf2, repl_beginning),
format_linenum (numbuf3, p_end + 1));
assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
assert(filldst==p_end+1 || filldst==repl_beginning);
}
}
else if (difftype == UNI_DIFF) {
file_offset line_beginning = file_tell (pfp); /* file pos of the current line */
lin fillsrc; /* index of old lines */
lin filldst; /* index of new lines */
char ch = '\0';
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 4
|| strncmp (buf, "@@ -", 4) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf + 4, &p_first);
if (*s == ',')
s = scan_linenum (s + 1, &p_ptrn_lines);
else
p_ptrn_lines = 1;
if (*s == ' ') s++;
if (*s != '+')
malformed ();
s = scan_linenum (s + 1, &p_newfirst);
if (*s == ',')
s = scan_linenum (s + 1, &p_repl_lines);
else
p_repl_lines = 1;
if (*s == ' ') s++;
if (*s++ != '@')
malformed ();
if (*s++ == '@' && *s == ' ' && *s != '\0')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
}
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
if (!p_repl_lines)
p_newfirst++;
p_max = p_ptrn_lines + p_repl_lines + 1;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
sprintf (buf, "*** %s,%s ****\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
sprintf (buf, "--- %s,%s ----\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_newfirst + p_repl_lines - 1));
p_len[filldst] = strlen (buf);
if (! (p_line[filldst] = savestr (buf))) {
p_end = 0;
return -1;
}
p_Char[filldst++] = '=';
p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
chars_read = get_line ();
if (!chars_read) {
if (p_max - filldst < 3) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 2;
} else {
fatal ("unexpected end of file in patch");
}
}
if (chars_read == (size_t) -1)
s = 0;
else if (*buf == '\t' || *buf == '\n') {
ch = ' '; /* assume the space got eaten */
s = savebuf (buf, chars_read);
}
else {
ch = *buf;
s = savebuf (buf+1, --chars_read);
}
if (chars_read && ! s)
{
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
switch (ch) {
case '-':
if (fillsrc > p_ptrn_lines) {
free(s);
p_end = filldst-1;
malformed ();
}
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
break;
case '=':
ch = ' ';
/* FALL THROUGH */
case ' ':
if (fillsrc > p_ptrn_lines) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
context++;
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
s = savebuf (s, chars_read);
if (chars_read && ! s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
/* FALL THROUGH */
case '+':
if (filldst > p_end) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
chars_read -= filldst == p_end && incomplete_line ();
p_Char[filldst] = ch;
p_line[filldst] = s;
p_len[filldst++] = chars_read;
break;
default:
p_end = filldst;
malformed ();
}
if (ch != ' ') {
if (p_prefix_context == -1)
p_prefix_context = context;
context = 0;
}
}/* while */
if (p_prefix_context == -1)
malformed ();
p_suffix_context = context;
}
else { /* normal diff--fake it up */
char hunk_type;
int i;
lin min, max;
file_offset line_beginning = file_tell (pfp);
p_prefix_context = p_suffix_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf, &p_first);
if (*s == ',') {
s = scan_linenum (s + 1, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else
p_ptrn_lines = (*s != 'a');
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
s = scan_linenum (s + 1, &min);
if (*s == ',')
scan_linenum (s + 1, &max);
else
max = min;
if (hunk_type == 'd')
min++;
p_end = p_ptrn_lines + 1 + max - min + 1;
while (p_end + 1 >= hunkmax)
if (! grow_hunkmax ())
{
p_end = -1;
return -1;
}
p_newfirst = min;
p_repl_lines = max - min + 1;
sprintf (buf, "*** %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
for (i=1; i<=p_ptrn_lines; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("`<' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '-';
}
if (hunk_type == 'c') {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (! chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (*buf != '-')
fatal ("`---' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
}
sprintf (buf, "--- %s,%s\n",
format_linenum (numbuf0, min),
format_linenum (numbuf1, max));
p_len[i] = strlen (buf);
if (! (p_line[i] = savestr (buf))) {
p_end = i-1;
return -1;
}
p_Char[i] = '=';
for (i++; i<=p_end; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("`>' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_end && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '+';
}
}
if (rev) /* backwards patch? */
if (!pch_swap())
say ("Not enough memory to swap next hunk!\n");
assert (p_end + 1 < hunkmax);
p_Char[p_end + 1] = '^'; /* add a stopper for apply_hunk */
if (debug & 2) {
lin i;
for (i = 0; i <= p_end + 1; i++) {
fprintf (stderr, "%s %c",
format_linenum (numbuf0, i),
p_Char[i]);
if (p_Char[i] == '*')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_ptrn_lines));
else if (p_Char[i] == '=')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_repl_lines));
else if (p_Char[i] != '^')
{
fputs(" |", stderr);
pch_write_line (i, stderr);
}
else
fputc('\n', stderr);
}
fflush (stderr);
}
return 1;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,456
|
best_name (char *const *name, int const *ignore)
{
enum nametype i;
int components[3];
int components_min = INT_MAX;
size_t basename_len[3];
size_t basename_len_min = SIZE_MAX;
size_t len[3];
size_t len_min = SIZE_MAX;
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i])
{
/* Take the names with the fewest prefix components. */
components[i] = prefix_components (name[i], false);
if (components_min < components[i])
continue;
components_min = components[i];
/* Of those, take the names with the shortest basename. */
basename_len[i] = base_len (name[i]);
if (basename_len_min < basename_len[i])
continue;
basename_len_min = basename_len[i];
/* Of those, take the shortest names. */
len[i] = strlen (name[i]);
if (len_min < len[i])
continue;
len_min = len[i];
}
/* Of those, take the first name. */
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i]
&& components[i] == components_min
&& basename_len[i] == basename_len_min
&& len[i] == len_min)
break;
return i;
}
|
Dir. Trav.
| 0
|
best_name (char *const *name, int const *ignore)
{
enum nametype i;
int components[3];
int components_min = INT_MAX;
size_t basename_len[3];
size_t basename_len_min = SIZE_MAX;
size_t len[3];
size_t len_min = SIZE_MAX;
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i])
{
/* Take the names with the fewest prefix components. */
components[i] = prefix_components (name[i], false);
if (components_min < components[i])
continue;
components_min = components[i];
/* Of those, take the names with the shortest basename. */
basename_len[i] = base_len (name[i]);
if (basename_len_min < basename_len[i])
continue;
basename_len_min = basename_len[i];
/* Of those, take the shortest names. */
len[i] = strlen (name[i]);
if (len_min < len[i])
continue;
len_min = len[i];
}
/* Of those, take the first name. */
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i]
&& components[i] == components_min
&& basename_len[i] == basename_len_min
&& len[i] == len_min)
break;
return i;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,457
|
do_ed_script (char const *inname, char const *outname,
int *outname_needs_removal, FILE *ofp)
{
static char const editor_program[] = EDITOR_PROGRAM;
file_offset beginning_of_this_line;
FILE *pipefp = 0;
size_t chars_read;
if (! dry_run && ! skip_rest_of_patch) {
int exclusive = *outname_needs_removal ? 0 : O_EXCL;
assert (! inerrno);
*outname_needs_removal = 1;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
sprintf (buf, "%s %s%s", editor_program,
verbosity == VERBOSE ? "" : "- ",
outname);
fflush (stdout);
pipefp = popen(buf, binary_transput ? "wb" : "w");
if (!pipefp)
pfatal ("Can't open pipe to %s", quotearg (buf));
}
for (;;) {
char ed_command_letter;
beginning_of_this_line = file_tell (pfp);
chars_read = get_line ();
if (! chars_read) {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
ed_command_letter = get_ed_command_letter (buf);
if (ed_command_letter) {
if (pipefp)
if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
write_fatal ();
if (ed_command_letter != 'd' && ed_command_letter != 's') {
p_pass_comments_through = true;
while ((chars_read = get_line ()) != 0) {
if (pipefp)
if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
write_fatal ();
if (chars_read == 2 && strEQ (buf, ".\n"))
break;
}
p_pass_comments_through = false;
}
}
else {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
}
if (!pipefp)
return;
if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, pipefp) == 0
|| fflush (pipefp) != 0)
write_fatal ();
if (pclose (pipefp) != 0)
fatal ("%s FAILED", editor_program);
if (ofp)
{
FILE *ifp = fopen (outname, binary_transput ? "rb" : "r");
int c;
if (!ifp)
pfatal ("can't open `%s'", outname);
while ((c = getc (ifp)) != EOF)
if (putc (c, ofp) == EOF)
write_fatal ();
if (ferror (ifp) || fclose (ifp) != 0)
read_fatal ();
}
}
|
Dir. Trav.
| 0
|
do_ed_script (char const *inname, char const *outname,
int *outname_needs_removal, FILE *ofp)
{
static char const editor_program[] = EDITOR_PROGRAM;
file_offset beginning_of_this_line;
FILE *pipefp = 0;
size_t chars_read;
if (! dry_run && ! skip_rest_of_patch) {
int exclusive = *outname_needs_removal ? 0 : O_EXCL;
assert (! inerrno);
*outname_needs_removal = 1;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
sprintf (buf, "%s %s%s", editor_program,
verbosity == VERBOSE ? "" : "- ",
outname);
fflush (stdout);
pipefp = popen(buf, binary_transput ? "wb" : "w");
if (!pipefp)
pfatal ("Can't open pipe to %s", quotearg (buf));
}
for (;;) {
char ed_command_letter;
beginning_of_this_line = file_tell (pfp);
chars_read = get_line ();
if (! chars_read) {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
ed_command_letter = get_ed_command_letter (buf);
if (ed_command_letter) {
if (pipefp)
if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
write_fatal ();
if (ed_command_letter != 'd' && ed_command_letter != 's') {
p_pass_comments_through = true;
while ((chars_read = get_line ()) != 0) {
if (pipefp)
if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
write_fatal ();
if (chars_read == 2 && strEQ (buf, ".\n"))
break;
}
p_pass_comments_through = false;
}
}
else {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
}
if (!pipefp)
return;
if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, pipefp) == 0
|| fflush (pipefp) != 0)
write_fatal ();
if (pclose (pipefp) != 0)
fatal ("%s FAILED", editor_program);
if (ofp)
{
FILE *ifp = fopen (outname, binary_transput ? "rb" : "r");
int c;
if (!ifp)
pfatal ("can't open `%s'", outname);
while ((c = getc (ifp)) != EOF)
if (putc (c, ofp) == EOF)
write_fatal ();
if (ferror (ifp) || fclose (ifp) != 0)
read_fatal ();
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,458
|
open_patch_file (char const *filename)
{
file_offset file_pos = 0;
struct stat st;
if (!filename || !*filename || strEQ (filename, "-"))
{
file_offset stdin_pos;
#if HAVE_SETMODE_DOS
if (binary_transput)
{
if (isatty (STDIN_FILENO))
fatal ("cannot read binary data from tty on this platform");
setmode (STDIN_FILENO, O_BINARY);
}
#endif
if (fstat (STDIN_FILENO, &st) != 0)
pfatal ("fstat");
if (S_ISREG (st.st_mode) && (stdin_pos = file_tell (stdin)) != -1)
{
pfp = stdin;
file_pos = stdin_pos;
}
else
{
size_t charsread;
int fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0);
TMPPATNAME_needs_removal = 1;
pfp = fdopen (fd, "w+b");
if (! pfp)
pfatal ("Can't open stream for file %s", quotearg (TMPPATNAME));
for (st.st_size = 0;
(charsread = fread (buf, 1, bufsize, stdin)) != 0;
st.st_size += charsread)
if (fwrite (buf, 1, charsread, pfp) != charsread)
write_fatal ();
if (ferror (stdin) || fclose (stdin) != 0)
read_fatal ();
if (fflush (pfp) != 0
|| file_seek (pfp, (file_offset) 0, SEEK_SET) != 0)
write_fatal ();
}
}
else
{
pfp = fopen (filename, binary_transput ? "rb" : "r");
if (!pfp)
pfatal ("Can't open patch file %s", quotearg (filename));
if (fstat (fileno (pfp), &st) != 0)
pfatal ("fstat");
}
p_filesize = st.st_size;
if (p_filesize != (file_offset) p_filesize)
fatal ("patch file is too long");
next_intuit_at (file_pos, 1);
set_hunkmax();
}
|
Dir. Trav.
| 0
|
open_patch_file (char const *filename)
{
file_offset file_pos = 0;
struct stat st;
if (!filename || !*filename || strEQ (filename, "-"))
{
file_offset stdin_pos;
#if HAVE_SETMODE_DOS
if (binary_transput)
{
if (isatty (STDIN_FILENO))
fatal ("cannot read binary data from tty on this platform");
setmode (STDIN_FILENO, O_BINARY);
}
#endif
if (fstat (STDIN_FILENO, &st) != 0)
pfatal ("fstat");
if (S_ISREG (st.st_mode) && (stdin_pos = file_tell (stdin)) != -1)
{
pfp = stdin;
file_pos = stdin_pos;
}
else
{
size_t charsread;
int fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0);
TMPPATNAME_needs_removal = 1;
pfp = fdopen (fd, "w+b");
if (! pfp)
pfatal ("Can't open stream for file %s", quotearg (TMPPATNAME));
for (st.st_size = 0;
(charsread = fread (buf, 1, bufsize, stdin)) != 0;
st.st_size += charsread)
if (fwrite (buf, 1, charsread, pfp) != charsread)
write_fatal ();
if (ferror (stdin) || fclose (stdin) != 0)
read_fatal ();
if (fflush (pfp) != 0
|| file_seek (pfp, (file_offset) 0, SEEK_SET) != 0)
write_fatal ();
}
}
else
{
pfp = fopen (filename, binary_transput ? "rb" : "r");
if (!pfp)
pfatal ("Can't open patch file %s", quotearg (filename));
if (fstat (fileno (pfp), &st) != 0)
pfatal ("fstat");
}
p_filesize = st.st_size;
if (p_filesize != (file_offset) p_filesize)
fatal ("patch file is too long");
next_intuit_at (file_pos, 1);
set_hunkmax();
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,459
|
pch_normalize (enum diff format)
{
lin old = 1;
lin new = p_ptrn_lines + 1;
while (p_Char[new] == '=' || p_Char[new] == '\n')
new++;
if (format == UNI_DIFF)
{
/* Convert '!' markers into '-' and '+' as defined by the Unified
Format. */
for (; old <= p_ptrn_lines; old++)
if (p_Char[old] == '!')
p_Char[old] = '-';
for (; new <= p_end; new++)
if (p_Char[new] == '!')
p_Char[new] = '+';
}
else
{
/* Convert '-' and '+' markers which are part of a group into '!' as
defined by the Context Format. */
while (old <= p_ptrn_lines)
{
if (p_Char[old] == '-')
{
if (new <= p_end && p_Char[new] == '+')
{
do
{
p_Char[old] = '!';
old++;
}
while (old <= p_ptrn_lines && p_Char[old] == '-');
do
{
p_Char[new] = '!';
new++;
}
while (new <= p_end && p_Char[new] == '+');
}
else
{
do
old++;
while (old <= p_ptrn_lines && p_Char[old] == '-');
}
}
else if (new <= p_end && p_Char[new] == '+')
{
do
new++;
while (new <= p_end && p_Char[new] == '+');
}
else
{
old++;
new++;
}
}
}
}
|
Dir. Trav.
| 0
|
pch_normalize (enum diff format)
{
lin old = 1;
lin new = p_ptrn_lines + 1;
while (p_Char[new] == '=' || p_Char[new] == '\n')
new++;
if (format == UNI_DIFF)
{
/* Convert '!' markers into '-' and '+' as defined by the Unified
Format. */
for (; old <= p_ptrn_lines; old++)
if (p_Char[old] == '!')
p_Char[old] = '-';
for (; new <= p_end; new++)
if (p_Char[new] == '!')
p_Char[new] = '+';
}
else
{
/* Convert '-' and '+' markers which are part of a group into '!' as
defined by the Context Format. */
while (old <= p_ptrn_lines)
{
if (p_Char[old] == '-')
{
if (new <= p_end && p_Char[new] == '+')
{
do
{
p_Char[old] = '!';
old++;
}
while (old <= p_ptrn_lines && p_Char[old] == '-');
do
{
p_Char[new] = '!';
new++;
}
while (new <= p_end && p_Char[new] == '+');
}
else
{
do
old++;
while (old <= p_ptrn_lines && p_Char[old] == '-');
}
}
else if (new <= p_end && p_Char[new] == '+')
{
do
new++;
while (new <= p_end && p_Char[new] == '+');
}
else
{
old++;
new++;
}
}
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,460
|
bool pch_rename (void)
{
return p_rename[OLD] && p_rename[NEW]
&& p_name[OLD] && p_name[NEW];
}
|
Dir. Trav.
| 0
|
bool pch_rename (void)
{
return p_rename[OLD] && p_rename[NEW]
&& p_name[OLD] && p_name[NEW];
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,461
|
pch_swap (void)
{
char **tp_line; /* the text of the hunk */
size_t *tp_len; /* length of each line */
char *tp_char; /* +, -, and ! */
lin i;
lin n;
bool blankline = false;
char *s;
i = p_first;
p_first = p_newfirst;
p_newfirst = i;
/* make a scratch copy */
tp_line = p_line;
tp_len = p_len;
tp_char = p_Char;
p_line = 0; /* force set_hunkmax to allocate again */
p_len = 0;
p_Char = 0;
set_hunkmax();
if (!p_line || !p_len || !p_Char) {
if (p_line)
free (p_line);
p_line = tp_line;
if (p_len)
free (p_len);
p_len = tp_len;
if (p_Char)
free (p_Char);
p_Char = tp_char;
return false; /* not enough memory to swap hunk! */
}
/* now turn the new into the old */
i = p_ptrn_lines + 1;
if (tp_char[i] == '\n') { /* account for possible blank line */
blankline = true;
i++;
}
if (p_efake >= 0) { /* fix non-freeable ptr range */
if (p_efake <= i)
n = p_end - i + 1;
else
n = -i;
p_efake += n;
p_bfake += n;
}
for (n=0; i <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '+')
p_Char[n] = '-';
p_len[n] = tp_len[i];
}
if (blankline) {
i = p_ptrn_lines + 1;
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
p_len[n] = tp_len[i];
n++;
}
assert(p_Char[0] == '=');
p_Char[0] = '*';
for (s=p_line[0]; *s; s++)
if (*s == '-')
*s = '*';
/* now turn the old into the new */
assert(tp_char[0] == '*');
tp_char[0] = '=';
for (s=tp_line[0]; *s; s++)
if (*s == '*')
*s = '-';
for (i=0; n <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '-')
p_Char[n] = '+';
p_len[n] = tp_len[i];
}
assert(i == p_ptrn_lines + 1);
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
p_Char[p_end + 1] = '^';
if (tp_line)
free (tp_line);
if (tp_len)
free (tp_len);
if (tp_char)
free (tp_char);
return true;
}
|
Dir. Trav.
| 0
|
pch_swap (void)
{
char **tp_line; /* the text of the hunk */
size_t *tp_len; /* length of each line */
char *tp_char; /* +, -, and ! */
lin i;
lin n;
bool blankline = false;
char *s;
i = p_first;
p_first = p_newfirst;
p_newfirst = i;
/* make a scratch copy */
tp_line = p_line;
tp_len = p_len;
tp_char = p_Char;
p_line = 0; /* force set_hunkmax to allocate again */
p_len = 0;
p_Char = 0;
set_hunkmax();
if (!p_line || !p_len || !p_Char) {
if (p_line)
free (p_line);
p_line = tp_line;
if (p_len)
free (p_len);
p_len = tp_len;
if (p_Char)
free (p_Char);
p_Char = tp_char;
return false; /* not enough memory to swap hunk! */
}
/* now turn the new into the old */
i = p_ptrn_lines + 1;
if (tp_char[i] == '\n') { /* account for possible blank line */
blankline = true;
i++;
}
if (p_efake >= 0) { /* fix non-freeable ptr range */
if (p_efake <= i)
n = p_end - i + 1;
else
n = -i;
p_efake += n;
p_bfake += n;
}
for (n=0; i <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '+')
p_Char[n] = '-';
p_len[n] = tp_len[i];
}
if (blankline) {
i = p_ptrn_lines + 1;
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
p_len[n] = tp_len[i];
n++;
}
assert(p_Char[0] == '=');
p_Char[0] = '*';
for (s=p_line[0]; *s; s++)
if (*s == '-')
*s = '*';
/* now turn the old into the new */
assert(tp_char[0] == '*');
tp_char[0] = '=';
for (s=tp_line[0]; *s; s++)
if (*s == '*')
*s = '-';
for (i=0; n <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '-')
p_Char[n] = '+';
p_len[n] = tp_len[i];
}
assert(i == p_ptrn_lines + 1);
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
p_Char[p_end + 1] = '^';
if (tp_line)
free (tp_line);
if (tp_len)
free (tp_len);
if (tp_char)
free (tp_char);
return true;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,462
|
sha1_says_nonexistent(char const *sha1, char const *end)
{
char const *empty_sha1 = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
char const *s;
/* Nonexisting files have an all-zero checksum. */
for (s = sha1; s != end; s++)
if (*s != '0')
break;
if (s == end)
return 2;
/* Empty files have empty_sha1 as their checksum. */
for (s = sha1; s != end; s++, empty_sha1++)
if (*s != *empty_sha1)
break;
return s == end;
}
|
Dir. Trav.
| 0
|
sha1_says_nonexistent(char const *sha1, char const *end)
{
char const *empty_sha1 = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
char const *s;
/* Nonexisting files have an all-zero checksum. */
for (s = sha1; s != end; s++)
if (*s != '0')
break;
if (s == end)
return 2;
/* Empty files have empty_sha1 as their checksum. */
for (s = sha1; s != end; s++, empty_sha1++)
if (*s != *empty_sha1)
break;
return s == end;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,463
|
there_is_another_patch (bool need_header, mode_t *file_type)
{
if (p_base != 0 && p_base >= p_filesize) {
if (verbosity == VERBOSE)
say ("done\n");
return false;
}
if (verbosity == VERBOSE)
say ("Hmm...");
diff_type = intuit_diff_type (need_header, file_type);
if (diff_type == NO_DIFF) {
if (verbosity == VERBOSE)
say (p_base
? " Ignoring the trailing garbage.\ndone\n"
: " I can't seem to find a patch in there anywhere.\n");
if (! p_base && p_filesize)
fatal ("Only garbage was found in the patch input.");
return false;
}
if (skip_rest_of_patch)
{
Fseek (pfp, p_start, SEEK_SET);
p_input_line = p_sline - 1;
return true;
}
if (verbosity == VERBOSE)
say (" %sooks like %s to me...\n",
(p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
diff_type == NORMAL_DIFF ? "a normal diff" :
diff_type == GIT_BINARY_DIFF ? "a git binary diff" :
"an ed script" );
if (no_strip_trailing_cr)
p_strip_trailing_cr = false;
if (verbosity != SILENT)
{
if (p_indent)
say ("(Patch is indented %lu space%s.)\n",
(unsigned long int) p_indent, p_indent==1?"":"s");
if (p_strip_trailing_cr)
say ("(Stripping trailing CRs from patch.)\n");
if (! inname)
{
char numbuf[LINENUM_LENGTH_BOUND + 1];
say ("can't find file to patch at input line %s\n",
format_linenum (numbuf, p_sline));
if (diff_type != ED_DIFF && diff_type != NORMAL_DIFF)
say (strippath == -1
? "Perhaps you should have used the -p or --strip option?\n"
: "Perhaps you used the wrong -p or --strip option?\n");
}
}
skip_to(p_start,p_sline);
while (!inname) {
char *t;
if (force | batch) {
say ("No file to patch. Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
ask ("File to patch: ");
t = buf + strlen (buf);
if (t > buf + 1 && *(t - 1) == '\n')
{
inname = savebuf (buf, t - buf);
inname[t - buf - 1] = 0;
if (lstat (inname, &instat) == 0)
{
inerrno = 0;
invc = -1;
}
else
{
perror (inname);
fflush (stderr);
free (inname);
inname = 0;
}
}
if (!inname) {
ask ("Skip this patch? [y] ");
if (*buf != 'n') {
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
}
}
return true;
}
|
Dir. Trav.
| 0
|
there_is_another_patch (bool need_header, mode_t *file_type)
{
if (p_base != 0 && p_base >= p_filesize) {
if (verbosity == VERBOSE)
say ("done\n");
return false;
}
if (verbosity == VERBOSE)
say ("Hmm...");
diff_type = intuit_diff_type (need_header, file_type);
if (diff_type == NO_DIFF) {
if (verbosity == VERBOSE)
say (p_base
? " Ignoring the trailing garbage.\ndone\n"
: " I can't seem to find a patch in there anywhere.\n");
if (! p_base && p_filesize)
fatal ("Only garbage was found in the patch input.");
return false;
}
if (skip_rest_of_patch)
{
Fseek (pfp, p_start, SEEK_SET);
p_input_line = p_sline - 1;
return true;
}
if (verbosity == VERBOSE)
say (" %sooks like %s to me...\n",
(p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
diff_type == NORMAL_DIFF ? "a normal diff" :
diff_type == GIT_BINARY_DIFF ? "a git binary diff" :
"an ed script" );
if (no_strip_trailing_cr)
p_strip_trailing_cr = false;
if (verbosity != SILENT)
{
if (p_indent)
say ("(Patch is indented %lu space%s.)\n",
(unsigned long int) p_indent, p_indent==1?"":"s");
if (p_strip_trailing_cr)
say ("(Stripping trailing CRs from patch.)\n");
if (! inname)
{
char numbuf[LINENUM_LENGTH_BOUND + 1];
say ("can't find file to patch at input line %s\n",
format_linenum (numbuf, p_sline));
if (diff_type != ED_DIFF && diff_type != NORMAL_DIFF)
say (strippath == -1
? "Perhaps you should have used the -p or --strip option?\n"
: "Perhaps you used the wrong -p or --strip option?\n");
}
}
skip_to(p_start,p_sline);
while (!inname) {
char *t;
if (force | batch) {
say ("No file to patch. Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
ask ("File to patch: ");
t = buf + strlen (buf);
if (t > buf + 1 && *(t - 1) == '\n')
{
inname = savebuf (buf, t - buf);
inname[t - buf - 1] = 0;
if (lstat (inname, &instat) == 0)
{
inerrno = 0;
invc = -1;
}
else
{
perror (inname);
fflush (stderr);
free (inname);
inname = 0;
}
}
if (!inname) {
ask ("Skip this patch? [y] ");
if (*buf != 'n') {
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
}
}
return true;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
|
CWE-22
| null | null |
4,464
|
append_to_file (char const *from, char const *to)
{
int tofd;
if ((tofd = open (to, O_WRONLY | O_BINARY | O_APPEND)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
write_fatal ();
}
|
Dir. Trav.
| 0
|
append_to_file (char const *from, char const *to)
{
int tofd;
if ((tofd = open (to, O_WRONLY | O_BINARY | O_APPEND)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
write_fatal ();
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,465
|
ask (char const *format, ...)
{
static int ttyfd = -2;
ssize_t r;
va_list args;
va_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
fflush (stdout);
if (ttyfd == -2)
{
/* If standard output is not a tty, don't bother opening /dev/tty,
since it's unlikely that stdout will be seen by the tty user.
The isatty test also works around a bug in GNU Emacs 19.34 under Linux
which makes a call-process `patch' hang when it reads from /dev/tty.
POSIX.1-2001 XCU line 26599 requires that we read /dev/tty,
though. */
ttyfd = (posixly_correct || isatty (STDOUT_FILENO)
? open (TTY_DEVICE, O_RDONLY)
: -1);
}
if (ttyfd < 0)
{
/* No terminal at all -- default it. */
printf ("\n");
buf[0] = '\n';
buf[1] = '\0';
}
else
{
size_t s = 0;
while ((r = read (ttyfd, buf + s, bufsize - 1 - s)) == bufsize - 1 - s
&& buf[bufsize - 2] != '\n')
{
s = bufsize - 1;
bufsize *= 2;
buf = realloc (buf, bufsize);
if (!buf)
xalloc_die ();
}
if (r == 0)
printf ("EOF\n");
else if (r < 0)
{
perror ("tty read");
fflush (stderr);
close (ttyfd);
ttyfd = -1;
r = 0;
}
buf[s + r] = '\0';
}
}
|
Dir. Trav.
| 0
|
ask (char const *format, ...)
{
static int ttyfd = -2;
ssize_t r;
va_list args;
va_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
fflush (stdout);
if (ttyfd == -2)
{
/* If standard output is not a tty, don't bother opening /dev/tty,
since it's unlikely that stdout will be seen by the tty user.
The isatty test also works around a bug in GNU Emacs 19.34 under Linux
which makes a call-process `patch' hang when it reads from /dev/tty.
POSIX.1-2001 XCU line 26599 requires that we read /dev/tty,
though. */
ttyfd = (posixly_correct || isatty (STDOUT_FILENO)
? open (TTY_DEVICE, O_RDONLY)
: -1);
}
if (ttyfd < 0)
{
/* No terminal at all -- default it. */
printf ("\n");
buf[0] = '\n';
buf[1] = '\0';
}
else
{
size_t s = 0;
while ((r = read (ttyfd, buf + s, bufsize - 1 - s)) == bufsize - 1 - s
&& buf[bufsize - 2] != '\n')
{
s = bufsize - 1;
bufsize *= 2;
buf = realloc (buf, bufsize);
if (!buf)
xalloc_die ();
}
if (r == 0)
printf ("EOF\n");
else if (r < 0)
{
perror ("tty read");
fflush (stderr);
close (ttyfd);
ttyfd = -1;
r = 0;
}
buf[s + r] = '\0';
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,466
|
copy_attr_error (struct error_context *ctx, char const *fmt, ...)
{
int err = errno;
va_list ap;
/* use verror module to print error message */
va_start (ap, fmt);
verror (0, err, fmt, ap);
va_end (ap);
}
|
Dir. Trav.
| 0
|
copy_attr_error (struct error_context *ctx, char const *fmt, ...)
{
int err = errno;
va_list ap;
/* use verror module to print error message */
va_start (ap, fmt);
verror (0, err, fmt, ap);
va_end (ap);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,467
|
copy_file (char const *from, char const *to, struct stat *tost,
int to_flags, mode_t mode, bool to_dir_known_to_exist)
{
int tofd;
if (debug & 4)
say ("Copying %s %s to %s\n",
S_ISLNK (mode) ? "symbolic link" : "file",
quotearg_n (0, from), quotearg_n (1, to));
if (S_ISLNK (mode))
{
char *buffer = xmalloc (PATH_MAX);
if (readlink (from, buffer, PATH_MAX) < 0)
pfatal ("Can't read %s %s", "symbolic link", from);
if (symlink (buffer, to) != 0)
pfatal ("Can't create %s %s", "symbolic link", to);
if (tost && lstat (to, tost) != 0)
pfatal ("Can't get file attributes of %s %s", "symbolic link", to);
free (buffer);
}
else
{
assert (S_ISREG (mode));
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
if (tost && fstat (tofd, tost) != 0)
pfatal ("Can't get file attributes of %s %s", "file", to);
if (close (tofd) != 0)
write_fatal ();
}
}
|
Dir. Trav.
| 0
|
copy_file (char const *from, char const *to, struct stat *tost,
int to_flags, mode_t mode, bool to_dir_known_to_exist)
{
int tofd;
if (debug & 4)
say ("Copying %s %s to %s\n",
S_ISLNK (mode) ? "symbolic link" : "file",
quotearg_n (0, from), quotearg_n (1, to));
if (S_ISLNK (mode))
{
char *buffer = xmalloc (PATH_MAX);
if (readlink (from, buffer, PATH_MAX) < 0)
pfatal ("Can't read %s %s", "symbolic link", from);
if (symlink (buffer, to) != 0)
pfatal ("Can't create %s %s", "symbolic link", to);
if (tost && lstat (to, tost) != 0)
pfatal ("Can't get file attributes of %s %s", "symbolic link", to);
free (buffer);
}
else
{
assert (S_ISREG (mode));
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
if (tost && fstat (tofd, tost) != 0)
pfatal ("Can't get file attributes of %s %s", "file", to);
if (close (tofd) != 0)
write_fatal ();
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,468
|
copy_to_fd (const char *from, int tofd)
{
int fromfd;
ssize_t i;
if ((fromfd = open (from, O_RDONLY | O_BINARY)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
if (i == (ssize_t) -1)
read_fatal ();
if (full_write (tofd, buf, i) != i)
write_fatal ();
}
if (close (fromfd) != 0)
read_fatal ();
}
|
Dir. Trav.
| 0
|
copy_to_fd (const char *from, int tofd)
{
int fromfd;
ssize_t i;
if ((fromfd = open (from, O_RDONLY | O_BINARY)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
if (i == (ssize_t) -1)
read_fatal ();
if (full_write (tofd, buf, i) != i)
write_fatal ();
}
if (close (fromfd) != 0)
read_fatal ();
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,469
|
create_backup (char const *to, struct stat *to_st, int *to_errno,
bool leave_original, bool remember_backup)
{
struct stat tmp_st;
int tmp_errno;
/* When the input to patch modifies the same file more than once, patch only
backs up the initial version of each file.
To figure out which files have already been backed up, patch remembers the
files that replace the original files. Files not known already are backed
up; files already known have already been backed up before, and are
skipped.
When a patch deletes a file, this leaves patch without such a "sentinel"
file. In that case, patch remembers the *backup file* instead; when a
patch creates a file, patch checks if the *backup file* is already known.
This strategy is not fully compatible with numbered backups: when a patch
deletes and later recreates a file with numbered backups, two numbered
backups will be created. */
if (! to_st || ! to_errno)
{
to_st = &tmp_st;
to_errno = &tmp_errno;
}
*to_errno = lstat (to, to_st) == 0 ? 0 : errno;
if (! to_errno && ! (S_ISREG (to_st->st_mode) || S_ISLNK (to_st->st_mode)))
fatal ("File %s is not a %s -- refusing to create backup",
to, S_ISLNK (to_st->st_mode) ? "symbolic link" : "regular file");
if (! *to_errno && file_already_seen (to_st))
{
if (debug & 4)
say ("File %s already seen\n", quotearg (to));
}
else
{
int try_makedirs_errno = 0;
char *bakname;
if (origprae || origbase || origsuff)
{
char const *p = origprae ? origprae : "";
char const *b = origbase ? origbase : "";
char const *s = origsuff ? origsuff : "";
char const *t = to;
size_t plen = strlen (p);
size_t blen = strlen (b);
size_t slen = strlen (s);
size_t tlen = strlen (t);
char const *o;
size_t olen;
for (o = t + tlen, olen = 0;
o > t && ! ISSLASH (*(o - 1));
o--)
/* do nothing */ ;
olen = t + tlen - o;
tlen -= olen;
bakname = xmalloc (plen + tlen + blen + olen + slen + 1);
memcpy (bakname, p, plen);
memcpy (bakname + plen, t, tlen);
memcpy (bakname + plen + tlen, b, blen);
memcpy (bakname + plen + tlen + blen, o, olen);
memcpy (bakname + plen + tlen + blen + olen, s, slen + 1);
if ((origprae
&& (contains_slash (origprae + FILE_SYSTEM_PREFIX_LEN (origprae))
|| contains_slash (to)))
|| (origbase && contains_slash (origbase)))
try_makedirs_errno = ENOENT;
}
else
{
bakname = find_backup_file_name (to, backup_type);
if (!bakname)
xalloc_die ();
}
if (*to_errno)
{
struct stat backup_st;
int fd;
if (lstat (bakname, &backup_st) == 0
&& file_already_seen (&backup_st))
{
if (debug & 4)
say ("File %s already seen\n", quotearg (to));
}
else
{
if (debug & 4)
say ("Creating empty file %s\n", quotearg (bakname));
try_makedirs_errno = ENOENT;
unlink (bakname);
while ((fd = creat (bakname, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
makedirs (bakname);
try_makedirs_errno = 0;
}
if (remember_backup && fstat (fd, &backup_st) == 0)
insert_file (&backup_st);
if (close (fd) != 0)
pfatal ("Can't close file %s", quotearg (bakname));
}
}
else if (leave_original)
create_backup_copy (to, bakname, to_st, try_makedirs_errno == 0,
remember_backup);
else
{
if (debug & 4)
say ("Renaming file %s to %s\n",
quotearg_n (0, to), quotearg_n (1, bakname));
while (rename (to, bakname) != 0)
{
if (errno == try_makedirs_errno)
{
makedirs (bakname);
try_makedirs_errno = 0;
}
else if (errno == EXDEV)
{
create_backup_copy (to, bakname, to_st,
try_makedirs_errno == 0,
remember_backup);
unlink (to);
break;
}
else
pfatal ("Can't rename file %s to %s",
quotearg_n (0, to), quotearg_n (1, bakname));
}
if (remember_backup)
insert_file (to_st);
}
free (bakname);
}
}
|
Dir. Trav.
| 0
|
create_backup (char const *to, struct stat *to_st, int *to_errno,
bool leave_original, bool remember_backup)
{
struct stat tmp_st;
int tmp_errno;
/* When the input to patch modifies the same file more than once, patch only
backs up the initial version of each file.
To figure out which files have already been backed up, patch remembers the
files that replace the original files. Files not known already are backed
up; files already known have already been backed up before, and are
skipped.
When a patch deletes a file, this leaves patch without such a "sentinel"
file. In that case, patch remembers the *backup file* instead; when a
patch creates a file, patch checks if the *backup file* is already known.
This strategy is not fully compatible with numbered backups: when a patch
deletes and later recreates a file with numbered backups, two numbered
backups will be created. */
if (! to_st || ! to_errno)
{
to_st = &tmp_st;
to_errno = &tmp_errno;
}
*to_errno = lstat (to, to_st) == 0 ? 0 : errno;
if (! to_errno && ! (S_ISREG (to_st->st_mode) || S_ISLNK (to_st->st_mode)))
fatal ("File %s is not a %s -- refusing to create backup",
to, S_ISLNK (to_st->st_mode) ? "symbolic link" : "regular file");
if (! *to_errno && file_already_seen (to_st))
{
if (debug & 4)
say ("File %s already seen\n", quotearg (to));
}
else
{
int try_makedirs_errno = 0;
char *bakname;
if (origprae || origbase || origsuff)
{
char const *p = origprae ? origprae : "";
char const *b = origbase ? origbase : "";
char const *s = origsuff ? origsuff : "";
char const *t = to;
size_t plen = strlen (p);
size_t blen = strlen (b);
size_t slen = strlen (s);
size_t tlen = strlen (t);
char const *o;
size_t olen;
for (o = t + tlen, olen = 0;
o > t && ! ISSLASH (*(o - 1));
o--)
/* do nothing */ ;
olen = t + tlen - o;
tlen -= olen;
bakname = xmalloc (plen + tlen + blen + olen + slen + 1);
memcpy (bakname, p, plen);
memcpy (bakname + plen, t, tlen);
memcpy (bakname + plen + tlen, b, blen);
memcpy (bakname + plen + tlen + blen, o, olen);
memcpy (bakname + plen + tlen + blen + olen, s, slen + 1);
if ((origprae
&& (contains_slash (origprae + FILE_SYSTEM_PREFIX_LEN (origprae))
|| contains_slash (to)))
|| (origbase && contains_slash (origbase)))
try_makedirs_errno = ENOENT;
}
else
{
bakname = find_backup_file_name (to, backup_type);
if (!bakname)
xalloc_die ();
}
if (*to_errno)
{
struct stat backup_st;
int fd;
if (lstat (bakname, &backup_st) == 0
&& file_already_seen (&backup_st))
{
if (debug & 4)
say ("File %s already seen\n", quotearg (to));
}
else
{
if (debug & 4)
say ("Creating empty file %s\n", quotearg (bakname));
try_makedirs_errno = ENOENT;
unlink (bakname);
while ((fd = creat (bakname, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
makedirs (bakname);
try_makedirs_errno = 0;
}
if (remember_backup && fstat (fd, &backup_st) == 0)
insert_file (&backup_st);
if (close (fd) != 0)
pfatal ("Can't close file %s", quotearg (bakname));
}
}
else if (leave_original)
create_backup_copy (to, bakname, to_st, try_makedirs_errno == 0,
remember_backup);
else
{
if (debug & 4)
say ("Renaming file %s to %s\n",
quotearg_n (0, to), quotearg_n (1, bakname));
while (rename (to, bakname) != 0)
{
if (errno == try_makedirs_errno)
{
makedirs (bakname);
try_makedirs_errno = 0;
}
else if (errno == EXDEV)
{
create_backup_copy (to, bakname, to_st,
try_makedirs_errno == 0,
remember_backup);
unlink (to);
break;
}
else
pfatal ("Can't rename file %s to %s",
quotearg_n (0, to), quotearg_n (1, bakname));
}
if (remember_backup)
insert_file (to_st);
}
free (bakname);
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,470
|
create_file (char const *file, int open_flags, mode_t mode,
bool to_dir_known_to_exist)
{
int try_makedirs_errno = to_dir_known_to_exist ? 0 : ENOENT;
int fd;
mode |= S_IRUSR | S_IWUSR;
mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);
do
{
if (! (O_CREAT && O_TRUNC))
close (creat (file, mode));
fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);
if (fd < 0)
{
char *f;
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (file));
f = xstrdup (file);
makedirs (f);
free (f);
try_makedirs_errno = 0;
}
} while (fd < 0);
return fd;
}
|
Dir. Trav.
| 0
|
create_file (char const *file, int open_flags, mode_t mode,
bool to_dir_known_to_exist)
{
int try_makedirs_errno = to_dir_known_to_exist ? 0 : ENOENT;
int fd;
mode |= S_IRUSR | S_IWUSR;
mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);
do
{
if (! (O_CREAT && O_TRUNC))
close (creat (file, mode));
fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);
if (fd < 0)
{
char *f;
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (file));
f = xstrdup (file);
makedirs (f);
free (f);
try_makedirs_errno = 0;
}
} while (fd < 0);
return fd;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,471
|
exit_with_signal (int sig)
{
sigset_t s;
signal (sig, SIG_DFL);
sigemptyset (&s);
sigaddset (&s, sig);
sigprocmask (SIG_UNBLOCK, &s, (sigset_t *) 0);
raise (sig);
exit (2);
}
|
Dir. Trav.
| 0
|
exit_with_signal (int sig)
{
sigset_t s;
signal (sig, SIG_DFL);
sigemptyset (&s);
sigaddset (&s, sig);
sigprocmask (SIG_UNBLOCK, &s, (sigset_t *) 0);
raise (sig);
exit (2);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,472
|
fatal_exit_handler (int sig)
{
signal (sig, SIG_IGN);
fatal_exit (sig);
}
|
Dir. Trav.
| 0
|
fatal_exit_handler (int sig)
{
signal (sig, SIG_IGN);
fatal_exit (sig);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,473
|
file_id_comparator (void const *entry1, void const *entry2)
{
file_id const *e1 = entry1;
file_id const *e2 = entry2;
return (e1->ino == e2->ino && e1->dev == e2->dev);
}
|
Dir. Trav.
| 0
|
file_id_comparator (void const *entry1, void const *entry2)
{
file_id const *e1 = entry1;
file_id const *e2 = entry2;
return (e1->ino == e2->ino && e1->dev == e2->dev);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,474
|
format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], lin n)
{
char *p = numbuf + LINENUM_LENGTH_BOUND;
*p = '\0';
if (n < 0)
{
do
*--p = '0' - (int) (n % 10);
while ((n /= 10) != 0);
*--p = '-';
}
else
{
do
*--p = '0' + (int) (n % 10);
while ((n /= 10) != 0);
}
return p;
}
|
Dir. Trav.
| 0
|
format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], lin n)
{
char *p = numbuf + LINENUM_LENGTH_BOUND;
*p = '\0';
if (n < 0)
{
do
*--p = '0' - (int) (n % 10);
while ((n /= 10) != 0);
*--p = '-';
}
else
{
do
*--p = '0' + (int) (n % 10);
while ((n /= 10) != 0);
}
return p;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,475
|
ignore_signals (void)
{
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
sigprocmask (SIG_BLOCK, &signals_to_block, &initial_signal_mask);
#else
int i;
for (i = 0; i < NUM_SIGS; i++)
if (sigismember (&signals_to_block, sigs[i]))
signal (sigs[i], SIG_IGN);
#endif
}
|
Dir. Trav.
| 0
|
ignore_signals (void)
{
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
sigprocmask (SIG_BLOCK, &signals_to_block, &initial_signal_mask);
#else
int i;
for (i = 0; i < NUM_SIGS; i++)
if (sigismember (&signals_to_block, sigs[i]))
signal (sigs[i], SIG_IGN);
#endif
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,476
|
init_backup_hash_table (void)
{
file_id_table = hash_initialize (0, NULL, file_id_hasher,
file_id_comparator, free);
if (!file_id_table)
xalloc_die ();
}
|
Dir. Trav.
| 0
|
init_backup_hash_table (void)
{
file_id_table = hash_initialize (0, NULL, file_id_hasher,
file_id_comparator, free);
if (!file_id_table)
xalloc_die ();
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,477
|
init_time (void)
{
gettime (&initial_time);
}
|
Dir. Trav.
| 0
|
init_time (void)
{
gettime (&initial_time);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,478
|
insert_file (struct stat const *st)
{
file_id *p;
static file_id *next_slot;
if (!next_slot)
next_slot = xmalloc (sizeof *next_slot);
next_slot->dev = st->st_dev;
next_slot->ino = st->st_ino;
p = hash_insert (file_id_table, next_slot);
if (!p)
xalloc_die ();
if (p == next_slot)
next_slot = NULL;
}
|
Dir. Trav.
| 0
|
insert_file (struct stat const *st)
{
file_id *p;
static file_id *next_slot;
if (!next_slot)
next_slot = xmalloc (sizeof *next_slot);
next_slot->dev = st->st_dev;
next_slot->ino = st->st_ino;
p = hash_insert (file_id_table, next_slot);
if (!p)
xalloc_die ();
if (p == next_slot)
next_slot = NULL;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,479
|
makedirs (char const *name)
{
char *filename = xstrdup (name);
char *f;
char *flim = replace_slashes (filename);
if (flim)
{
/* Create any missing directories, replacing NULs by '/'s.
Ignore errors. We may have to keep going even after an EEXIST,
since the path may contain ".."s; and when there is an EEXIST
failure the system may return some other error number.
Any problems will eventually be reported when we create the file. */
for (f = filename; f <= flim; f++)
if (!*f)
{
mkdir (filename,
S_IRUSR|S_IWUSR|S_IXUSR
|S_IRGRP|S_IWGRP|S_IXGRP
|S_IROTH|S_IWOTH|S_IXOTH);
*f = '/';
}
}
free (filename);
}
|
Dir. Trav.
| 0
|
makedirs (char const *name)
{
char *filename = xstrdup (name);
char *f;
char *flim = replace_slashes (filename);
if (flim)
{
/* Create any missing directories, replacing NULs by '/'s.
Ignore errors. We may have to keep going even after an EEXIST,
since the path may contain ".."s; and when there is an EEXIST
failure the system may return some other error number.
Any problems will eventually be reported when we create the file. */
for (f = filename; f <= flim; f++)
if (!*f)
{
mkdir (filename,
S_IRUSR|S_IWUSR|S_IXUSR
|S_IRGRP|S_IWGRP|S_IXGRP
|S_IROTH|S_IWOTH|S_IXOTH);
*f = '/';
}
}
free (filename);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,480
|
move_file (char const *from, int *from_needs_removal,
struct stat const *fromst,
char const *to, mode_t mode, bool backup)
{
struct stat to_st;
int to_errno = -1;
if (backup)
create_backup (to, &to_st, &to_errno, false, from == NULL);
if (from)
{
if (S_ISLNK (mode))
{
bool to_dir_known_to_exist = false;
/* FROM contains the contents of the symlink we have patched; need
to convert that back into a symlink. */
char *buffer = xmalloc (PATH_MAX);
int fd, size = 0, i;
if ((fd = open (from, O_RDONLY | O_BINARY)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fd, buffer + size, PATH_MAX - size)) > 0)
size += i;
if (i != 0 || close (fd) != 0)
read_fatal ();
buffer[size] = 0;
if (! backup)
{
if (unlink (to) == 0)
to_dir_known_to_exist = true;
}
if (symlink (buffer, to) != 0)
{
if (errno == ENOENT && ! to_dir_known_to_exist)
makedirs (to);
if (symlink (buffer, to) != 0)
pfatal ("Can't create %s %s", "symbolic link", to);
}
free (buffer);
if (lstat (to, &to_st) != 0)
pfatal ("Can't get file attributes of %s %s", "symbolic link", to);
insert_file (&to_st);
}
else
{
if (debug & 4)
say ("Renaming file %s to %s\n",
quotearg_n (0, from), quotearg_n (1, to));
if (rename (from, to) != 0)
{
bool to_dir_known_to_exist = false;
if (errno == ENOENT
&& (to_errno == -1 || to_errno == ENOENT))
{
makedirs (to);
to_dir_known_to_exist = true;
if (rename (from, to) == 0)
goto rename_succeeded;
}
if (errno == EXDEV)
{
struct stat tost;
if (! backup)
{
if (unlink (to) == 0)
to_dir_known_to_exist = true;
else if (errno != ENOENT)
pfatal ("Can't remove file %s", quotearg (to));
}
copy_file (from, to, &tost, 0, mode, to_dir_known_to_exist);
insert_file (&tost);
return;
}
pfatal ("Can't rename file %s to %s",
quotearg_n (0, from), quotearg_n (1, to));
}
rename_succeeded:
insert_file (fromst);
/* Do not clear *FROM_NEEDS_REMOVAL if it's possible that the
rename returned zero because FROM and TO are hard links to
the same file. */
if (0 < to_errno
|| (to_errno == 0 && to_st.st_nlink <= 1))
*from_needs_removal = 0;
}
}
else if (! backup)
{
if (debug & 4)
say ("Removing file %s\n", quotearg (to));
if (unlink (to) != 0 && errno != ENOENT)
pfatal ("Can't remove file %s", quotearg (to));
}
}
|
Dir. Trav.
| 0
|
move_file (char const *from, int *from_needs_removal,
struct stat const *fromst,
char const *to, mode_t mode, bool backup)
{
struct stat to_st;
int to_errno = -1;
if (backup)
create_backup (to, &to_st, &to_errno, false, from == NULL);
if (from)
{
if (S_ISLNK (mode))
{
bool to_dir_known_to_exist = false;
/* FROM contains the contents of the symlink we have patched; need
to convert that back into a symlink. */
char *buffer = xmalloc (PATH_MAX);
int fd, size = 0, i;
if ((fd = open (from, O_RDONLY | O_BINARY)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fd, buffer + size, PATH_MAX - size)) > 0)
size += i;
if (i != 0 || close (fd) != 0)
read_fatal ();
buffer[size] = 0;
if (! backup)
{
if (unlink (to) == 0)
to_dir_known_to_exist = true;
}
if (symlink (buffer, to) != 0)
{
if (errno == ENOENT && ! to_dir_known_to_exist)
makedirs (to);
if (symlink (buffer, to) != 0)
pfatal ("Can't create %s %s", "symbolic link", to);
}
free (buffer);
if (lstat (to, &to_st) != 0)
pfatal ("Can't get file attributes of %s %s", "symbolic link", to);
insert_file (&to_st);
}
else
{
if (debug & 4)
say ("Renaming file %s to %s\n",
quotearg_n (0, from), quotearg_n (1, to));
if (rename (from, to) != 0)
{
bool to_dir_known_to_exist = false;
if (errno == ENOENT
&& (to_errno == -1 || to_errno == ENOENT))
{
makedirs (to);
to_dir_known_to_exist = true;
if (rename (from, to) == 0)
goto rename_succeeded;
}
if (errno == EXDEV)
{
struct stat tost;
if (! backup)
{
if (unlink (to) == 0)
to_dir_known_to_exist = true;
else if (errno != ENOENT)
pfatal ("Can't remove file %s", quotearg (to));
}
copy_file (from, to, &tost, 0, mode, to_dir_known_to_exist);
insert_file (&tost);
return;
}
pfatal ("Can't rename file %s to %s",
quotearg_n (0, from), quotearg_n (1, to));
}
rename_succeeded:
insert_file (fromst);
/* Do not clear *FROM_NEEDS_REMOVAL if it's possible that the
rename returned zero because FROM and TO are hard links to
the same file. */
if (0 < to_errno
|| (to_errno == 0 && to_st.st_nlink <= 1))
*from_needs_removal = 0;
}
}
else if (! backup)
{
if (debug & 4)
say ("Removing file %s\n", quotearg (to));
if (unlink (to) != 0 && errno != ENOENT)
pfatal ("Can't remove file %s", quotearg (to));
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,481
|
ok_to_reverse (char const *format, ...)
{
bool r = false;
if (noreverse || ! (force && verbosity == SILENT))
{
va_list args;
va_start (args, format);
vsay (format, args);
va_end (args);
}
if (noreverse)
{
say (" Skipping patch.\n");
skip_rest_of_patch = true;
}
else if (force)
{
if (verbosity != SILENT)
say (" Applying it anyway.\n");
}
else if (batch)
{
say (reverse ? " Ignoring -R.\n" : " Assuming -R.\n");
r = true;
}
else
{
ask (reverse ? " Ignore -R? [n] " : " Assume -R? [n] ");
r = *buf == 'y';
if (! r)
{
ask ("Apply anyway? [n] ");
if (*buf != 'y')
{
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
}
}
}
return r;
}
|
Dir. Trav.
| 0
|
ok_to_reverse (char const *format, ...)
{
bool r = false;
if (noreverse || ! (force && verbosity == SILENT))
{
va_list args;
va_start (args, format);
vsay (format, args);
va_end (args);
}
if (noreverse)
{
say (" Skipping patch.\n");
skip_rest_of_patch = true;
}
else if (force)
{
if (verbosity != SILENT)
say (" Applying it anyway.\n");
}
else if (batch)
{
say (reverse ? " Ignoring -R.\n" : " Assuming -R.\n");
r = true;
}
else
{
ask (reverse ? " Ignore -R? [n] " : " Assume -R? [n] ");
r = *buf == 'y';
if (! r)
{
ask ("Apply anyway? [n] ");
if (*buf != 'y')
{
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
}
}
}
return r;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,482
|
pfatal (char const *format, ...)
{
int errnum = errno;
va_list args;
fprintf (stderr, "%s: **** ", program_name);
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
fflush (stderr); /* perror bypasses stdio on some hosts. */
errno = errnum;
perror (" ");
fflush (stderr);
fatal_exit (0);
}
|
Dir. Trav.
| 0
|
pfatal (char const *format, ...)
{
int errnum = errno;
va_list args;
fprintf (stderr, "%s: **** ", program_name);
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
fflush (stderr); /* perror bypasses stdio on some hosts. */
errno = errnum;
perror (" ");
fflush (stderr);
fatal_exit (0);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,483
|
read_fatal (void)
{
pfatal ("read error");
}
|
Dir. Trav.
| 0
|
read_fatal (void)
{
pfatal ("read error");
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,484
|
remove_prefix (char *p, size_t prefixlen)
{
char const *s = p + prefixlen;
while ((*p++ = *s++))
/* do nothing */ ;
}
|
Dir. Trav.
| 0
|
remove_prefix (char *p, size_t prefixlen)
{
char const *s = p + prefixlen;
while ((*p++ = *s++))
/* do nothing */ ;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,485
|
removedirs (char const *name)
{
char *filename = xstrdup (name);
size_t i;
for (i = strlen (filename); i != 0; i--)
if (ISSLASH (filename[i])
&& ! (ISSLASH (filename[i - 1])
|| (filename[i - 1] == '.'
&& (i == 1
|| ISSLASH (filename[i - 2])
|| (filename[i - 2] == '.'
&& (i == 2
|| ISSLASH (filename[i - 3])))))))
{
filename[i] = '\0';
if (rmdir (filename) == 0 && verbosity == VERBOSE)
say ("Removed empty directory %s\n", quotearg (filename));
filename[i] = '/';
}
free (filename);
}
|
Dir. Trav.
| 0
|
removedirs (char const *name)
{
char *filename = xstrdup (name);
size_t i;
for (i = strlen (filename); i != 0; i--)
if (ISSLASH (filename[i])
&& ! (ISSLASH (filename[i - 1])
|| (filename[i - 1] == '.'
&& (i == 1
|| ISSLASH (filename[i - 2])
|| (filename[i - 2] == '.'
&& (i == 2
|| ISSLASH (filename[i - 3])))))))
{
filename[i] = '\0';
if (rmdir (filename) == 0 && verbosity == VERBOSE)
say ("Removed empty directory %s\n", quotearg (filename));
filename[i] = '/';
}
free (filename);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,486
|
replace_slashes (char *filename)
{
char *f;
char *last_location_replaced = 0;
char const *component_start;
for (f = filename + FILE_SYSTEM_PREFIX_LEN (filename); ISSLASH (*f); f++)
/* do nothing */ ;
component_start = f;
for (; *f; f++)
if (ISSLASH (*f))
{
char *slash = f;
/* Treat multiple slashes as if they were one slash. */
while (ISSLASH (f[1]))
f++;
/* Ignore slashes at the end of the path. */
if (! f[1])
break;
/* "." and ".." need not be tested. */
if (! (slash - component_start <= 2
&& component_start[0] == '.' && slash[-1] == '.'))
{
*slash = '\0';
last_location_replaced = slash;
}
component_start = f + 1;
}
return last_location_replaced;
}
|
Dir. Trav.
| 0
|
replace_slashes (char *filename)
{
char *f;
char *last_location_replaced = 0;
char const *component_start;
for (f = filename + FILE_SYSTEM_PREFIX_LEN (filename); ISSLASH (*f); f++)
/* do nothing */ ;
component_start = f;
for (; *f; f++)
if (ISSLASH (*f))
{
char *slash = f;
/* Treat multiple slashes as if they were one slash. */
while (ISSLASH (f[1]))
f++;
/* Ignore slashes at the end of the path. */
if (! f[1])
break;
/* "." and ".." need not be tested. */
if (! (slash - component_start <= 2
&& component_start[0] == '.' && slash[-1] == '.'))
{
*slash = '\0';
last_location_replaced = slash;
}
component_start = f + 1;
}
return last_location_replaced;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,487
|
savebuf (char const *s, size_t size)
{
char *rv;
if (! size)
return NULL;
rv = malloc (size);
if (! rv)
{
if (! using_plan_a)
xalloc_die ();
}
else
memcpy (rv, s, size);
return rv;
}
|
Dir. Trav.
| 0
|
savebuf (char const *s, size_t size)
{
char *rv;
if (! size)
return NULL;
rv = malloc (size);
if (! rv)
{
if (! using_plan_a)
xalloc_die ();
}
else
memcpy (rv, s, size);
return rv;
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,488
|
savestr (char const *s)
{
return savebuf (s, strlen (s) + 1);
}
|
Dir. Trav.
| 0
|
savestr (char const *s)
{
return savebuf (s, strlen (s) + 1);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,489
|
say (char const *format, ...)
{
va_list args;
va_start (args, format);
vsay (format, args);
va_end (args);
}
|
Dir. Trav.
| 0
|
say (char const *format, ...)
{
va_list args;
va_start (args, format);
vsay (format, args);
va_end (args);
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,490
|
set_signals (bool reset)
{
int i;
#if HAVE_SIGACTION
struct sigaction initial_act, fatal_act;
fatal_act.sa_handler = fatal_exit;
sigemptyset (&fatal_act.sa_mask);
fatal_act.sa_flags = 0;
#define setup_handler(sig) sigaction (sig, &fatal_act, (struct sigaction *) 0)
#else
#define setup_handler(sig) signal (sig, fatal_exit_handler)
#endif
if (!reset)
{
#ifdef SIGCHLD
/* System V fork+wait does not work if SIGCHLD is ignored. */
signal (SIGCHLD, SIG_DFL);
#endif
sigemptyset (&signals_to_block);
for (i = 0; i < NUM_SIGS; i++)
{
bool ignoring_signal;
#if HAVE_SIGACTION
if (sigaction (sigs[i], (struct sigaction *) 0, &initial_act) != 0)
continue;
ignoring_signal = initial_act.sa_handler == SIG_IGN;
#else
ignoring_signal = signal (sigs[i], SIG_IGN) == SIG_IGN;
#endif
if (! ignoring_signal)
{
sigaddset (&signals_to_block, sigs[i]);
setup_handler (sigs[i]);
}
}
}
else
{
/* Undo the effect of ignore_signals. */
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
sigprocmask (SIG_SETMASK, &initial_signal_mask, (sigset_t *) 0);
#else
for (i = 0; i < NUM_SIGS; i++)
if (sigismember (&signals_to_block, sigs[i]))
setup_handler (sigs[i]);
#endif
}
}
|
Dir. Trav.
| 0
|
set_signals (bool reset)
{
int i;
#if HAVE_SIGACTION
struct sigaction initial_act, fatal_act;
fatal_act.sa_handler = fatal_exit;
sigemptyset (&fatal_act.sa_mask);
fatal_act.sa_flags = 0;
#define setup_handler(sig) sigaction (sig, &fatal_act, (struct sigaction *) 0)
#else
#define setup_handler(sig) signal (sig, fatal_exit_handler)
#endif
if (!reset)
{
#ifdef SIGCHLD
/* System V fork+wait does not work if SIGCHLD is ignored. */
signal (SIGCHLD, SIG_DFL);
#endif
sigemptyset (&signals_to_block);
for (i = 0; i < NUM_SIGS; i++)
{
bool ignoring_signal;
#if HAVE_SIGACTION
if (sigaction (sigs[i], (struct sigaction *) 0, &initial_act) != 0)
continue;
ignoring_signal = initial_act.sa_handler == SIG_IGN;
#else
ignoring_signal = signal (sigs[i], SIG_IGN) == SIG_IGN;
#endif
if (! ignoring_signal)
{
sigaddset (&signals_to_block, sigs[i]);
setup_handler (sigs[i]);
}
}
}
else
{
/* Undo the effect of ignore_signals. */
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
sigprocmask (SIG_SETMASK, &initial_signal_mask, (sigset_t *) 0);
#else
for (i = 0; i < NUM_SIGS; i++)
if (sigismember (&signals_to_block, sigs[i]))
setup_handler (sigs[i]);
#endif
}
}
|
@@ -3,7 +3,7 @@
/* Copyright (C) 1986 Larry Wall
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006,
- 2009, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading)
n = p+1;
}
}
+ if (IS_ABSOLUTE_FILE_NAME (n))
+ fatal ("rejecting absolute file name: %s", quotearg (n));
+ for (p = n; *p; )
+ {
+ if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+ fatal ("rejecting file name with \"..\" component: %s", quotearg (n));
+ while (*p && ! ISSLASH (*p))
+ p++;
+ while (ISSLASH (*p))
+ p++;
+ }
if ((strip_leading < 0 || s <= 0) && *n)
{
memmove (name, n, strlen (n) + 1);
|
CWE-22
| null | null |
4,491
|
static const char *event_name(XHCIEvent *event)
{
return lookup_name(event->ccode, TRBCCode_names,
ARRAY_SIZE(TRBCCode_names));
}
|
DoS
| 0
|
static const char *event_name(XHCIEvent *event)
{
return lookup_name(event->ccode, TRBCCode_names,
ARRAY_SIZE(TRBCCode_names));
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,492
|
static const char *lookup_name(uint32_t index, const char **list, uint32_t llen)
{
if (index >= llen || list[index] == NULL) {
return "???";
}
return list[index];
}
|
DoS
| 0
|
static const char *lookup_name(uint32_t index, const char **list, uint32_t llen)
{
if (index >= llen || list[index] == NULL) {
return "???";
}
return list[index];
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,493
|
static uint32_t rotl(uint32_t v, unsigned count)
{
count &= 31;
return (v << count) | (v >> (32 - count));
}
|
DoS
| 0
|
static uint32_t rotl(uint32_t v, unsigned count)
{
count &= 31;
return (v << count) | (v >> (32 - count));
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,494
|
static const char *trb_name(XHCITRB *trb)
{
return lookup_name(TRB_TYPE(*trb), TRBType_names,
ARRAY_SIZE(TRBType_names));
}
|
DoS
| 0
|
static const char *trb_name(XHCITRB *trb)
{
return lookup_name(TRB_TYPE(*trb), TRBType_names,
ARRAY_SIZE(TRBType_names));
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,495
|
static void usb_xhci_exit(PCIDevice *dev)
{
int i;
XHCIState *xhci = XHCI(dev);
trace_usb_xhci_exit();
for (i = 0; i < xhci->numslots; i++) {
xhci_disable_slot(xhci, i + 1);
}
if (xhci->mfwrap_timer) {
timer_del(xhci->mfwrap_timer);
timer_free(xhci->mfwrap_timer);
xhci->mfwrap_timer = NULL;
}
memory_region_del_subregion(&xhci->mem, &xhci->mem_cap);
memory_region_del_subregion(&xhci->mem, &xhci->mem_oper);
memory_region_del_subregion(&xhci->mem, &xhci->mem_runtime);
memory_region_del_subregion(&xhci->mem, &xhci->mem_doorbell);
for (i = 0; i < xhci->numports; i++) {
XHCIPort *port = &xhci->ports[i];
memory_region_del_subregion(&xhci->mem, &port->mem);
}
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
}
|
DoS
| 0
|
static void usb_xhci_exit(PCIDevice *dev)
{
int i;
XHCIState *xhci = XHCI(dev);
trace_usb_xhci_exit();
for (i = 0; i < xhci->numslots; i++) {
xhci_disable_slot(xhci, i + 1);
}
if (xhci->mfwrap_timer) {
timer_del(xhci->mfwrap_timer);
timer_free(xhci->mfwrap_timer);
xhci->mfwrap_timer = NULL;
}
memory_region_del_subregion(&xhci->mem, &xhci->mem_cap);
memory_region_del_subregion(&xhci->mem, &xhci->mem_oper);
memory_region_del_subregion(&xhci->mem, &xhci->mem_runtime);
memory_region_del_subregion(&xhci->mem, &xhci->mem_doorbell);
for (i = 0; i < xhci->numports; i++) {
XHCIPort *port = &xhci->ports[i];
memory_region_del_subregion(&xhci->mem, &port->mem);
}
/* destroy msix memory region */
if (dev->msix_table && dev->msix_pba
&& dev->msix_entry_used) {
msix_uninit(dev, &xhci->mem, &xhci->mem);
}
usb_bus_release(&xhci->bus);
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,496
|
static void usb_xhci_init(XHCIState *xhci)
{
DeviceState *dev = DEVICE(xhci);
XHCIPort *port;
int i, usbports, speedmask;
xhci->usbsts = USBSTS_HCH;
if (xhci->numports_2 > MAXPORTS_2) {
xhci->numports_2 = MAXPORTS_2;
}
if (xhci->numports_3 > MAXPORTS_3) {
xhci->numports_3 = MAXPORTS_3;
}
usbports = MAX(xhci->numports_2, xhci->numports_3);
xhci->numports = xhci->numports_2 + xhci->numports_3;
usb_bus_new(&xhci->bus, sizeof(xhci->bus), &xhci_bus_ops, dev);
for (i = 0; i < usbports; i++) {
speedmask = 0;
if (i < xhci->numports_2) {
if (xhci_get_flag(xhci, XHCI_FLAG_SS_FIRST)) {
port = &xhci->ports[i + xhci->numports_3];
port->portnr = i + 1 + xhci->numports_3;
} else {
port = &xhci->ports[i];
port->portnr = i + 1;
}
port->uport = &xhci->uports[i];
port->speedmask =
USB_SPEED_MASK_LOW |
USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH;
snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1);
speedmask |= port->speedmask;
}
if (i < xhci->numports_3) {
if (xhci_get_flag(xhci, XHCI_FLAG_SS_FIRST)) {
port = &xhci->ports[i];
port->portnr = i + 1;
} else {
port = &xhci->ports[i + xhci->numports_2];
port->portnr = i + 1 + xhci->numports_2;
}
port->uport = &xhci->uports[i];
port->speedmask = USB_SPEED_MASK_SUPER;
snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1);
speedmask |= port->speedmask;
}
usb_register_port(&xhci->bus, &xhci->uports[i], xhci, i,
&xhci_uport_ops, speedmask);
}
}
|
DoS
| 0
|
static void usb_xhci_init(XHCIState *xhci)
{
DeviceState *dev = DEVICE(xhci);
XHCIPort *port;
int i, usbports, speedmask;
xhci->usbsts = USBSTS_HCH;
if (xhci->numports_2 > MAXPORTS_2) {
xhci->numports_2 = MAXPORTS_2;
}
if (xhci->numports_3 > MAXPORTS_3) {
xhci->numports_3 = MAXPORTS_3;
}
usbports = MAX(xhci->numports_2, xhci->numports_3);
xhci->numports = xhci->numports_2 + xhci->numports_3;
usb_bus_new(&xhci->bus, sizeof(xhci->bus), &xhci_bus_ops, dev);
for (i = 0; i < usbports; i++) {
speedmask = 0;
if (i < xhci->numports_2) {
if (xhci_get_flag(xhci, XHCI_FLAG_SS_FIRST)) {
port = &xhci->ports[i + xhci->numports_3];
port->portnr = i + 1 + xhci->numports_3;
} else {
port = &xhci->ports[i];
port->portnr = i + 1;
}
port->uport = &xhci->uports[i];
port->speedmask =
USB_SPEED_MASK_LOW |
USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH;
snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1);
speedmask |= port->speedmask;
}
if (i < xhci->numports_3) {
if (xhci_get_flag(xhci, XHCI_FLAG_SS_FIRST)) {
port = &xhci->ports[i];
port->portnr = i + 1;
} else {
port = &xhci->ports[i + xhci->numports_2];
port->portnr = i + 1 + xhci->numports_2;
}
port->uport = &xhci->uports[i];
port->speedmask = USB_SPEED_MASK_SUPER;
snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1);
speedmask |= port->speedmask;
}
usb_register_port(&xhci->bus, &xhci->uports[i], xhci, i,
&xhci_uport_ops, speedmask);
}
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,497
|
static int usb_xhci_post_load(void *opaque, int version_id)
{
XHCIState *xhci = opaque;
PCIDevice *pci_dev = PCI_DEVICE(xhci);
XHCISlot *slot;
XHCIEPContext *epctx;
dma_addr_t dcbaap, pctx;
uint32_t slot_ctx[4];
uint32_t ep_ctx[5];
int slotid, epid, state, intr;
dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
for (slotid = 1; slotid <= xhci->numslots; slotid++) {
slot = &xhci->slots[slotid-1];
if (!slot->addressed) {
continue;
}
slot->ctx =
xhci_mask64(ldq_le_pci_dma(pci_dev, dcbaap + 8 * slotid));
xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx));
slot->uport = xhci_lookup_uport(xhci, slot_ctx);
if (!slot->uport) {
/* should not happen, but may trigger on guest bugs */
slot->enabled = 0;
slot->addressed = 0;
continue;
}
assert(slot->uport && slot->uport->dev);
for (epid = 1; epid <= 31; epid++) {
pctx = slot->ctx + 32 * epid;
xhci_dma_read_u32s(xhci, pctx, ep_ctx, sizeof(ep_ctx));
state = ep_ctx[0] & EP_STATE_MASK;
if (state == EP_DISABLED) {
continue;
}
epctx = xhci_alloc_epctx(xhci, slotid, epid);
slot->eps[epid-1] = epctx;
xhci_init_epctx(epctx, pctx, ep_ctx);
epctx->state = state;
if (state == EP_RUNNING) {
/* kick endpoint after vmload is finished */
timer_mod(epctx->kick_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
}
}
}
for (intr = 0; intr < xhci->numintrs; intr++) {
if (xhci->intr[intr].msix_used) {
msix_vector_use(pci_dev, intr);
} else {
msix_vector_unuse(pci_dev, intr);
}
}
return 0;
}
|
DoS
| 0
|
static int usb_xhci_post_load(void *opaque, int version_id)
{
XHCIState *xhci = opaque;
PCIDevice *pci_dev = PCI_DEVICE(xhci);
XHCISlot *slot;
XHCIEPContext *epctx;
dma_addr_t dcbaap, pctx;
uint32_t slot_ctx[4];
uint32_t ep_ctx[5];
int slotid, epid, state, intr;
dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
for (slotid = 1; slotid <= xhci->numslots; slotid++) {
slot = &xhci->slots[slotid-1];
if (!slot->addressed) {
continue;
}
slot->ctx =
xhci_mask64(ldq_le_pci_dma(pci_dev, dcbaap + 8 * slotid));
xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx));
slot->uport = xhci_lookup_uport(xhci, slot_ctx);
if (!slot->uport) {
/* should not happen, but may trigger on guest bugs */
slot->enabled = 0;
slot->addressed = 0;
continue;
}
assert(slot->uport && slot->uport->dev);
for (epid = 1; epid <= 31; epid++) {
pctx = slot->ctx + 32 * epid;
xhci_dma_read_u32s(xhci, pctx, ep_ctx, sizeof(ep_ctx));
state = ep_ctx[0] & EP_STATE_MASK;
if (state == EP_DISABLED) {
continue;
}
epctx = xhci_alloc_epctx(xhci, slotid, epid);
slot->eps[epid-1] = epctx;
xhci_init_epctx(epctx, pctx, ep_ctx);
epctx->state = state;
if (state == EP_RUNNING) {
/* kick endpoint after vmload is finished */
timer_mod(epctx->kick_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
}
}
}
for (intr = 0; intr < xhci->numintrs; intr++) {
if (xhci->intr[intr].msix_used) {
msix_vector_use(pci_dev, intr);
} else {
msix_vector_unuse(pci_dev, intr);
}
}
return 0;
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,498
|
static inline dma_addr_t xhci_addr64(uint32_t low, uint32_t high)
{
if (sizeof(dma_addr_t) == 4) {
return low;
} else {
return low | (((dma_addr_t)high << 16) << 16);
}
}
|
DoS
| 0
|
static inline dma_addr_t xhci_addr64(uint32_t low, uint32_t high)
{
if (sizeof(dma_addr_t) == 4) {
return low;
} else {
return low | (((dma_addr_t)high << 16) << 16);
}
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
4,499
|
static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
uint64_t pictx, bool bsr)
{
XHCISlot *slot;
USBPort *uport;
USBDevice *dev;
dma_addr_t ictx, octx, dcbaap;
uint64_t poctx;
uint32_t ictl_ctx[2];
uint32_t slot_ctx[4];
uint32_t ep0_ctx[5];
int i;
TRBCCode res;
assert(slotid >= 1 && slotid <= xhci->numslots);
dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
poctx = ldq_le_pci_dma(PCI_DEVICE(xhci), dcbaap + 8 * slotid);
ictx = xhci_mask64(pictx);
octx = xhci_mask64(poctx);
DPRINTF("xhci: input context at "DMA_ADDR_FMT"\n", ictx);
DPRINTF("xhci: output context at "DMA_ADDR_FMT"\n", octx);
xhci_dma_read_u32s(xhci, ictx, ictl_ctx, sizeof(ictl_ctx));
if (ictl_ctx[0] != 0x0 || ictl_ctx[1] != 0x3) {
DPRINTF("xhci: invalid input context control %08x %08x\n",
ictl_ctx[0], ictl_ctx[1]);
return CC_TRB_ERROR;
}
xhci_dma_read_u32s(xhci, ictx+32, slot_ctx, sizeof(slot_ctx));
xhci_dma_read_u32s(xhci, ictx+64, ep0_ctx, sizeof(ep0_ctx));
DPRINTF("xhci: input slot context: %08x %08x %08x %08x\n",
slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
DPRINTF("xhci: input ep0 context: %08x %08x %08x %08x %08x\n",
ep0_ctx[0], ep0_ctx[1], ep0_ctx[2], ep0_ctx[3], ep0_ctx[4]);
uport = xhci_lookup_uport(xhci, slot_ctx);
if (uport == NULL) {
DPRINTF("xhci: port not found\n");
return CC_TRB_ERROR;
}
trace_usb_xhci_slot_address(slotid, uport->path);
dev = uport->dev;
if (!dev || !dev->attached) {
DPRINTF("xhci: port %s not connected\n", uport->path);
return CC_USB_TRANSACTION_ERROR;
}
for (i = 0; i < xhci->numslots; i++) {
if (i == slotid-1) {
continue;
}
if (xhci->slots[i].uport == uport) {
DPRINTF("xhci: port %s already assigned to slot %d\n",
uport->path, i+1);
return CC_TRB_ERROR;
}
}
slot = &xhci->slots[slotid-1];
slot->uport = uport;
slot->ctx = octx;
/* Make sure device is in USB_STATE_DEFAULT state */
usb_device_reset(dev);
if (bsr) {
slot_ctx[3] = SLOT_DEFAULT << SLOT_STATE_SHIFT;
} else {
USBPacket p;
uint8_t buf[1];
slot_ctx[3] = (SLOT_ADDRESSED << SLOT_STATE_SHIFT) | slotid;
memset(&p, 0, sizeof(p));
usb_packet_addbuf(&p, buf, sizeof(buf));
usb_packet_setup(&p, USB_TOKEN_OUT,
usb_ep_get(dev, USB_TOKEN_OUT, 0), 0,
0, false, false);
usb_device_handle_control(dev, &p,
DeviceOutRequest | USB_REQ_SET_ADDRESS,
slotid, 0, 0, NULL);
assert(p.status != USB_RET_ASYNC);
}
res = xhci_enable_ep(xhci, slotid, 1, octx+32, ep0_ctx);
DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
DPRINTF("xhci: output ep0 context: %08x %08x %08x %08x %08x\n",
ep0_ctx[0], ep0_ctx[1], ep0_ctx[2], ep0_ctx[3], ep0_ctx[4]);
xhci_dma_write_u32s(xhci, octx, slot_ctx, sizeof(slot_ctx));
xhci_dma_write_u32s(xhci, octx+32, ep0_ctx, sizeof(ep0_ctx));
xhci->slots[slotid-1].addressed = 1;
return res;
}
|
DoS
| 0
|
static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
uint64_t pictx, bool bsr)
{
XHCISlot *slot;
USBPort *uport;
USBDevice *dev;
dma_addr_t ictx, octx, dcbaap;
uint64_t poctx;
uint32_t ictl_ctx[2];
uint32_t slot_ctx[4];
uint32_t ep0_ctx[5];
int i;
TRBCCode res;
assert(slotid >= 1 && slotid <= xhci->numslots);
dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
poctx = ldq_le_pci_dma(PCI_DEVICE(xhci), dcbaap + 8 * slotid);
ictx = xhci_mask64(pictx);
octx = xhci_mask64(poctx);
DPRINTF("xhci: input context at "DMA_ADDR_FMT"\n", ictx);
DPRINTF("xhci: output context at "DMA_ADDR_FMT"\n", octx);
xhci_dma_read_u32s(xhci, ictx, ictl_ctx, sizeof(ictl_ctx));
if (ictl_ctx[0] != 0x0 || ictl_ctx[1] != 0x3) {
DPRINTF("xhci: invalid input context control %08x %08x\n",
ictl_ctx[0], ictl_ctx[1]);
return CC_TRB_ERROR;
}
xhci_dma_read_u32s(xhci, ictx+32, slot_ctx, sizeof(slot_ctx));
xhci_dma_read_u32s(xhci, ictx+64, ep0_ctx, sizeof(ep0_ctx));
DPRINTF("xhci: input slot context: %08x %08x %08x %08x\n",
slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
DPRINTF("xhci: input ep0 context: %08x %08x %08x %08x %08x\n",
ep0_ctx[0], ep0_ctx[1], ep0_ctx[2], ep0_ctx[3], ep0_ctx[4]);
uport = xhci_lookup_uport(xhci, slot_ctx);
if (uport == NULL) {
DPRINTF("xhci: port not found\n");
return CC_TRB_ERROR;
}
trace_usb_xhci_slot_address(slotid, uport->path);
dev = uport->dev;
if (!dev || !dev->attached) {
DPRINTF("xhci: port %s not connected\n", uport->path);
return CC_USB_TRANSACTION_ERROR;
}
for (i = 0; i < xhci->numslots; i++) {
if (i == slotid-1) {
continue;
}
if (xhci->slots[i].uport == uport) {
DPRINTF("xhci: port %s already assigned to slot %d\n",
uport->path, i+1);
return CC_TRB_ERROR;
}
}
slot = &xhci->slots[slotid-1];
slot->uport = uport;
slot->ctx = octx;
/* Make sure device is in USB_STATE_DEFAULT state */
usb_device_reset(dev);
if (bsr) {
slot_ctx[3] = SLOT_DEFAULT << SLOT_STATE_SHIFT;
} else {
USBPacket p;
uint8_t buf[1];
slot_ctx[3] = (SLOT_ADDRESSED << SLOT_STATE_SHIFT) | slotid;
memset(&p, 0, sizeof(p));
usb_packet_addbuf(&p, buf, sizeof(buf));
usb_packet_setup(&p, USB_TOKEN_OUT,
usb_ep_get(dev, USB_TOKEN_OUT, 0), 0,
0, false, false);
usb_device_handle_control(dev, &p,
DeviceOutRequest | USB_REQ_SET_ADDRESS,
slotid, 0, 0, NULL);
assert(p.status != USB_RET_ASYNC);
}
res = xhci_enable_ep(xhci, slotid, 1, octx+32, ep0_ctx);
DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
DPRINTF("xhci: output ep0 context: %08x %08x %08x %08x %08x\n",
ep0_ctx[0], ep0_ctx[1], ep0_ctx[2], ep0_ctx[3], ep0_ctx[4]);
xhci_dma_write_u32s(xhci, octx, slot_ctx, sizeof(slot_ctx));
xhci_dma_write_u32s(xhci, octx+32, ep0_ctx, sizeof(ep0_ctx));
xhci->slots[slotid-1].addressed = 1;
return res;
}
|
@@ -390,6 +390,7 @@ struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+ uint32_t kick_active;
/* streams */
unsigned int max_pstreams;
@@ -2131,6 +2132,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
return;
}
+ if (epctx->kick_active) {
+ return;
+ }
xhci_kick_epctx(epctx, streamid);
}
@@ -2146,6 +2150,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
int i;
trace_usb_xhci_ep_kick(epctx->slotid, epctx->epid, streamid);
+ assert(!epctx->kick_active);
/* If the device has been detached, but the guest has not noticed this
yet the 2 above checks will succeed, but we must NOT continue */
@@ -2217,6 +2222,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
}
assert(ring->dequeue != 0);
+ epctx->kick_active++;
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
@@ -2253,6 +2259,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
break;
}
}
+ epctx->kick_active--;
ep = xhci_epid_to_usbep(epctx);
if (ep) {
|
CWE-835
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.