func
stringlengths 0
484k
| target
int64 0
1
| cwe
sequence | project
stringlengths 2
29
| commit_id
stringlengths 40
40
| hash
float64 1,215,700,430,453,689,100,000,000B
340,281,914,521,452,260,000,000,000,000B
| size
int64 1
24k
| message
stringlengths 0
13.3k
|
---|---|---|---|---|---|---|---|
read_connections (NMAGConfSettings *settings)
{
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (settings);
GSList *dir_list;
GSList *iter;
dir_list = nm_gconf_get_all_connections (priv->client);
if (!dir_list)
return;
for (iter = dir_list; iter; iter = iter->next) {
char *dir = (char *) iter->data;
add_connection_real (settings, nma_gconf_connection_new (priv->client, dir));
g_free (dir);
}
g_slist_free (dir_list);
priv->connections = g_slist_reverse (priv->connections);
} | 1 | [
"CWE-200"
] | network-manager-applet | 8627880e07c8345f69ed639325280c7f62a8f894 | 190,055,981,073,339,570,000,000,000,000,000,000,000 | 20 | editor: prevent any registration of objects on the system bus
D-Bus access-control is name-based; so requests for a specific name
are allowed/denied based on the rules in /etc/dbus-1/system.d. But
apparently apps still get a non-named service on the bus, and if we
register *any* object even though we don't have a named service,
dbus and dbus-glib will happily proxy signals. Since the connection
editor shouldn't ever expose anything having to do with connections
on any bus, make sure that's the case. |
dispose (GObject *object)
{
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_hash_table_destroy (priv->pending_changes);
if (priv->read_connections_id) {
g_source_remove (priv->read_connections_id);
priv->read_connections_id = 0;
}
gconf_client_notify_remove (priv->client, priv->conf_notify_id);
gconf_client_remove_dir (priv->client, GCONF_PATH_CONNECTIONS, NULL);
g_slist_foreach (priv->connections, (GFunc) g_object_unref, NULL);
g_slist_free (priv->connections);
g_object_unref (priv->client);
G_OBJECT_CLASS (nma_gconf_settings_parent_class)->dispose (object);
} | 1 | [
"CWE-200"
] | network-manager-applet | 56d87fcb86acb5359558e0a2ee702cfc0c3391f2 | 173,104,310,666,530,200,000,000,000,000,000,000,000 | 26 | applet: fix dbus connection refcounting after 8627880e07c8345f69ed639325280c7f62a8f894 |
add_connection_real (NMAGConfSettings *self, NMAGConfConnection *connection)
{
NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (self);
g_return_if_fail (connection != NULL);
priv->connections = g_slist_prepend (priv->connections, connection);
g_signal_connect (connection, "new-secrets-requested",
G_CALLBACK (connection_new_secrets_requested_cb),
self);
g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
/* Export the connection over dbus if requested */
if (priv->bus) {
nm_exported_connection_register_object (NM_EXPORTED_CONNECTION (connection),
NM_CONNECTION_SCOPE_USER,
priv->bus);
dbus_g_connection_unref (priv->bus);
}
nm_settings_signal_new_connection (NM_SETTINGS (self), NM_EXPORTED_CONNECTION (connection));
} | 1 | [
"CWE-200"
] | network-manager-applet | 56d87fcb86acb5359558e0a2ee702cfc0c3391f2 | 137,957,941,458,855,410,000,000,000,000,000,000,000 | 23 | applet: fix dbus connection refcounting after 8627880e07c8345f69ed639325280c7f62a8f894 |
nma_gconf_connection_new (GConfClient *client, const char *conf_dir)
{
NMConnection *connection;
NMAGConfConnection *gconf_connection;
g_return_val_if_fail (GCONF_IS_CLIENT (client), NULL);
g_return_val_if_fail (conf_dir != NULL, NULL);
/* retrieve GConf data */
connection = nm_gconf_read_connection (client, conf_dir);
if (connection) {
gconf_connection = nma_gconf_connection_new_from_connection (client, conf_dir, connection);
g_object_unref (connection);
} else {
nm_warning ("No connection read from GConf at %s.", conf_dir);
gconf_connection = NULL;
}
return gconf_connection;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 258,525,374,362,735,340,000,000,000,000,000,000,000 | 20 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
nma_gconf_connection_changed (NMAGConfConnection *self)
{
NMAGConfConnectionPrivate *priv;
GHashTable *settings;
NMConnection *wrapped_connection;
NMConnection *gconf_connection;
GHashTable *new_settings;
GError *error = NULL;
g_return_val_if_fail (NMA_IS_GCONF_CONNECTION (self), FALSE);
priv = NMA_GCONF_CONNECTION_GET_PRIVATE (self);
wrapped_connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (self));
gconf_connection = nm_gconf_read_connection (priv->client, priv->dir);
if (!gconf_connection) {
g_warning ("No connection read from GConf at %s.", priv->dir);
goto invalid;
}
utils_fill_connection_certs (gconf_connection);
if (!nm_connection_verify (gconf_connection, &error)) {
utils_clear_filled_connection_certs (gconf_connection);
g_warning ("%s: Invalid connection %s: '%s' / '%s' invalid: %d",
__func__, priv->dir,
g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),
error->message, error->code);
goto invalid;
}
utils_clear_filled_connection_certs (gconf_connection);
/* Ignore the GConf update if nothing changed */
if ( nm_connection_compare (wrapped_connection, gconf_connection, NM_SETTING_COMPARE_FLAG_EXACT)
&& nm_gconf_compare_private_connection_values (wrapped_connection, gconf_connection))
return TRUE;
/* Update private values to catch any certificate path changes */
nm_gconf_copy_private_connection_values (wrapped_connection, gconf_connection);
utils_fill_connection_certs (gconf_connection);
new_settings = nm_connection_to_hash (gconf_connection);
utils_clear_filled_connection_certs (gconf_connection);
if (!nm_connection_replace_settings (wrapped_connection, new_settings, &error)) {
utils_clear_filled_connection_certs (wrapped_connection);
g_hash_table_destroy (new_settings);
g_warning ("%s: '%s' / '%s' invalid: %d",
__func__,
error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)",
(error && error->message) ? error->message : "(none)",
error ? error->code : -1);
goto invalid;
}
g_object_unref (gconf_connection);
g_hash_table_destroy (new_settings);
fill_vpn_user_name (wrapped_connection);
settings = nm_connection_to_hash (wrapped_connection);
utils_clear_filled_connection_certs (wrapped_connection);
nm_exported_connection_signal_updated (NM_EXPORTED_CONNECTION (self), settings);
g_hash_table_destroy (settings);
return TRUE;
invalid:
g_clear_error (&error);
nm_exported_connection_signal_removed (NM_EXPORTED_CONNECTION (self));
return FALSE;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 196,886,284,970,420,630,000,000,000,000,000,000,000 | 71 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
utils_fill_connection_certs (NMConnection *connection)
{
NMSetting8021x *s_8021x;
const char *filename;
GError *error = NULL;
gboolean need_client_cert = TRUE;
g_return_if_fail (connection != NULL);
s_8021x = NM_SETTING_802_1X (nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X));
if (!s_8021x)
return;
filename = g_object_get_data (G_OBJECT (connection), NMA_PATH_CA_CERT_TAG);
if (filename) {
if (!nm_setting_802_1x_set_ca_cert_from_file (s_8021x, filename, NULL, &error))
g_warning ("%s: couldn't read CA certificate: %d %s", __func__, error->code, error->message);
g_clear_error (&error);
}
/* If the private key is PKCS#12, don't set the client cert */
need_client_cert = fill_one_private_key (connection,
NMA_PATH_PRIVATE_KEY_TAG,
NM_SETTING_802_1X_PRIVATE_KEY,
NM_SETTING_802_1X_CLIENT_CERT);
if (need_client_cert) {
filename = g_object_get_data (G_OBJECT (connection), NMA_PATH_CLIENT_CERT_TAG);
if (filename) {
if (!nm_setting_802_1x_set_client_cert_from_file (s_8021x, filename, NULL, &error))
g_warning ("%s: couldn't read client certificate: %d %s", __func__, error->code, error->message);
g_clear_error (&error);
}
}
filename = g_object_get_data (G_OBJECT (connection), NMA_PATH_PHASE2_CA_CERT_TAG);
if (filename) {
if (!nm_setting_802_1x_set_phase2_ca_cert_from_file (s_8021x, filename, NULL, &error))
g_warning ("%s: couldn't read phase2 CA certificate: %d %s", __func__, error->code, error->message);
g_clear_error (&error);
}
/* If the private key is PKCS#12, don't set the client cert */
need_client_cert = fill_one_private_key (connection,
NMA_PATH_PHASE2_PRIVATE_KEY_TAG,
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY,
NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
if (need_client_cert) {
filename = g_object_get_data (G_OBJECT (connection), NMA_PATH_PHASE2_CLIENT_CERT_TAG);
if (filename) {
if (!nm_setting_802_1x_set_phase2_client_cert_from_file (s_8021x, filename, NULL, &error))
g_warning ("%s: couldn't read phase2 client certificate: %d %s", __func__, error->code, error->message);
g_clear_error (&error);
}
}
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 107,178,332,972,783,100,000,000,000,000,000,000,000 | 55 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
update_connection (NMConnectionList *list,
NMConnectionEditor *editor,
NMExportedConnection *original,
NMConnection *modified,
ConnectionUpdatedFn callback,
gpointer user_data)
{
NMConnectionScope original_scope;
ConnectionUpdateInfo *info;
info = g_slice_new0 (ConnectionUpdateInfo);
info->list = list;
info->editor = editor;
info->original = g_object_ref (original);
info->modified = g_object_ref (modified);
info->callback = callback;
info->user_data = user_data;
original_scope = nm_connection_get_scope (nm_exported_connection_get_connection (original));
if (nm_connection_get_scope (modified) == original_scope) {
/* The easy part: Connection is updated */
GHashTable *new_settings;
GError *error = NULL;
gboolean success;
gboolean pending_auth = FALSE;
GtkWindow *parent;
utils_fill_connection_certs (modified);
new_settings = nm_connection_to_hash (modified);
/* Hack; make sure that gconf private values are copied */
nm_gconf_copy_private_connection_values (nm_exported_connection_get_connection (original),
modified);
success = nm_exported_connection_update (original, new_settings, &error);
g_hash_table_destroy (new_settings);
utils_clear_filled_connection_certs (modified);
parent = nm_connection_editor_get_window (editor);
if (!success) {
if (pk_helper_is_permission_denied_error (error)) {
GError *auth_error = NULL;
pending_auth = pk_helper_obtain_auth (error, parent, update_connection_cb, info, &auth_error);
if (auth_error) {
error_dialog (parent,
_("Could not update connection"),
"%s", auth_error->message);
g_error_free (auth_error);
}
} else {
error_dialog (parent,
_("Could not update connection"),
"%s", error->message);
}
g_error_free (error);
} else {
/* Save user-connection vpn secrets */
if (editor && (original_scope == NM_CONNECTION_SCOPE_USER))
nm_connection_editor_save_vpn_secrets (editor);
}
if (!pending_auth)
connection_update_done (info, success);
} else {
/* The hard part: Connection scope changed:
Add the exported connection,
if it succeeds, remove the old one. */
add_connection (list, editor, modified, connection_update_add_done, info);
}
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 69,344,125,097,621,190,000,000,000,000,000,000,000 | 72 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
add_connection (NMConnectionList *self,
NMConnectionEditor *editor,
NMConnection *connection,
ConnectionAddedFn callback,
gpointer user_data)
{
NMExportedConnection *exported = NULL;
NMConnectionScope scope;
gboolean success = FALSE;
scope = nm_connection_get_scope (connection);
if (scope == NM_CONNECTION_SCOPE_SYSTEM) {
GError *error = NULL;
utils_fill_connection_certs (connection);
success = nm_dbus_settings_system_add_connection (self->system_settings, connection, &error);
utils_clear_filled_connection_certs (connection);
if (!success) {
gboolean pending_auth = FALSE;
GtkWindow *parent;
parent = nm_connection_editor_get_window (editor);
if (pk_helper_is_permission_denied_error (error)) {
ConnectionAddInfo *info;
GError *auth_error = NULL;
info = g_slice_new (ConnectionAddInfo);
info->list = self;
info->editor = editor;
info->connection = g_object_ref (connection);
info->callback = callback;
info->user_data = user_data;
pending_auth = pk_helper_obtain_auth (error, parent, add_connection_cb, info, &auth_error);
if (auth_error) {
error_dialog (parent,
_("Could not add connection"),
"%s", auth_error->message);
g_error_free (auth_error);
}
if (!pending_auth) {
g_object_unref (info->connection);
g_slice_free (ConnectionAddInfo, info);
}
} else {
error_dialog (parent,
_("Could not add connection"),
"%s", error->message);
}
g_error_free (error);
if (pending_auth)
return;
}
} else if (scope == NM_CONNECTION_SCOPE_USER) {
exported = (NMExportedConnection *) nma_gconf_settings_add_connection (self->gconf_settings, connection);
success = exported != NULL;
if (success && editor)
nm_connection_editor_save_vpn_secrets (editor);
} else
g_warning ("%s: unhandled connection scope %d!", __func__, scope);
if (callback)
callback (exported, success, user_data);
if (exported)
g_object_unref (exported);
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 164,502,455,550,204,190,000,000,000,000,000,000,000 | 71 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
read_one_cert (ReadFromGConfInfo *info,
const char *setting_name,
const char *key)
{
char *value = NULL;
if (!nm_gconf_get_string_helper (info->client, info->dir, key, setting_name, &value))
return;
g_object_set_data_full (G_OBJECT (info->connection),
key, value,
(GDestroyNotify) g_free);
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 57,641,357,943,977,500,000,000,000,000,000,000,000 | 13 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
read_applet_private_values_from_gconf (NMSetting *setting,
ReadFromGConfInfo *info)
{
if (NM_IS_SETTING_802_1X (setting)) {
const char *setting_name = nm_setting_get_name (setting);
gboolean value;
if (nm_gconf_get_bool_helper (info->client, info->dir,
NMA_CA_CERT_IGNORE_TAG,
setting_name, &value)) {
g_object_set_data (G_OBJECT (info->connection),
NMA_CA_CERT_IGNORE_TAG,
GUINT_TO_POINTER (value));
}
if (nm_gconf_get_bool_helper (info->client, info->dir,
NMA_PHASE2_CA_CERT_IGNORE_TAG,
setting_name, &value)) {
g_object_set_data (G_OBJECT (info->connection),
NMA_PHASE2_CA_CERT_IGNORE_TAG,
GUINT_TO_POINTER (value));
}
/* Binary certificate and key data doesn't get stored in GConf. Instead,
* the path to the certificate gets stored in a special key and the
* certificate is read and stuffed into the setting right before
* the connection is sent to NM
*/
read_one_cert (info, setting_name, NMA_PATH_CA_CERT_TAG);
read_one_cert (info, setting_name, NMA_PATH_CLIENT_CERT_TAG);
read_one_cert (info, setting_name, NMA_PATH_PRIVATE_KEY_TAG);
read_one_cert (info, setting_name, NMA_PATH_PHASE2_CA_CERT_TAG);
read_one_cert (info, setting_name, NMA_PATH_PHASE2_CLIENT_CERT_TAG);
read_one_cert (info, setting_name, NMA_PATH_PHASE2_PRIVATE_KEY_TAG);
}
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 237,410,975,103,383,960,000,000,000,000,000,000,000 | 36 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
get_8021x_secrets_cb (GtkDialog *dialog,
gint response,
gpointer user_data)
{
NM8021xInfo *info = user_data;
NMAGConfConnection *gconf_connection;
NMConnection *connection = NULL;
NMSetting *setting;
GHashTable *settings_hash;
GHashTable *secrets;
GError *err = NULL;
/* Got a user response, clear the NMActiveConnection destroy handler for
* this dialog since this function will now take over dialog destruction.
*/
g_object_weak_unref (G_OBJECT (info->active_connection), destroy_8021x_dialog, info);
if (response != GTK_RESPONSE_OK) {
g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_SECRETS_REQUEST_CANCELED,
"%s.%d (%s): canceled",
__FILE__, __LINE__, __func__);
goto done;
}
connection = nma_wired_dialog_get_connection (info->dialog);
if (!connection) {
g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INTERNAL_ERROR,
"%s.%d (%s): couldn't get connection from wired dialog.",
__FILE__, __LINE__, __func__);
goto done;
}
setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X);
if (!setting) {
g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"%s.%d (%s): requested setting '802-1x' didn't"
" exist in the connection.",
__FILE__, __LINE__, __func__);
goto done;
}
utils_fill_connection_certs (NM_CONNECTION (connection));
secrets = nm_setting_to_hash (setting);
utils_clear_filled_connection_certs (NM_CONNECTION (connection));
if (!secrets) {
g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INTERNAL_ERROR,
"%s.%d (%s): failed to hash setting '%s'.",
__FILE__, __LINE__, __func__, nm_setting_get_name (setting));
goto done;
}
/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
* will contain all the individual settings hashes.
*/
settings_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_hash_table_destroy);
g_hash_table_insert (settings_hash, g_strdup (nm_setting_get_name (setting)), secrets);
dbus_g_method_return (info->context, settings_hash);
g_hash_table_destroy (settings_hash);
/* Save the connection back to GConf _after_ hashing it, because
* saving to GConf might trigger the GConf change notifiers, resulting
* in the connection being read back in from GConf which clears secrets.
*/
gconf_connection = nma_gconf_settings_get_by_connection (info->applet->gconf_settings, connection);
if (gconf_connection)
nma_gconf_connection_save (gconf_connection);
done:
if (err) {
g_warning ("%s", err->message);
dbus_g_method_return_error (info->context, err);
g_error_free (err);
}
if (connection)
nm_connection_clear_secrets (connection);
destroy_8021x_dialog (info, NULL);
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 20,392,142,445,402,345,000,000,000,000,000,000,000 | 82 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
add_one_setting (GHashTable *settings,
NMConnection *connection,
NMSetting *setting,
GError **error)
{
GHashTable *secrets;
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (setting != NULL, FALSE);
g_return_val_if_fail (error != NULL, FALSE);
g_return_val_if_fail (*error == NULL, FALSE);
utils_fill_connection_certs (connection);
secrets = nm_setting_to_hash (setting);
utils_clear_filled_connection_certs (connection);
if (secrets) {
g_hash_table_insert (settings, g_strdup (nm_setting_get_name (setting)), secrets);
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INTERNAL_ERROR,
"%s.%d (%s): failed to hash setting '%s'.",
__FILE__, __LINE__, __func__, nm_setting_get_name (setting));
}
return secrets ? TRUE : FALSE;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 283,746,707,249,343,980,000,000,000,000,000,000,000 | 27 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
get_settings (NMExportedConnection *exported)
{
NMConnection *connection;
GHashTable *settings;
connection = nm_exported_connection_get_connection (exported);
utils_fill_connection_certs (connection);
settings = nm_connection_to_hash (connection);
utils_clear_filled_connection_certs (connection);
return settings;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 81,869,905,497,253,220,000,000,000,000,000,000,000 | 13 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
NMAGConfConnectionPrivate *priv;
NMConnection *connection;
GError *error = NULL;
object = G_OBJECT_CLASS (nma_gconf_connection_parent_class)->constructor (type, n_construct_params, construct_params);
if (!object)
return NULL;
priv = NMA_GCONF_CONNECTION_GET_PRIVATE (object);
if (!priv->client) {
nm_warning ("GConfClient not provided.");
goto err;
}
if (!priv->dir) {
nm_warning ("GConf directory not provided.");
goto err;
}
connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (object));
utils_fill_connection_certs (connection);
if (!nm_connection_verify (connection, &error)) {
utils_clear_filled_connection_certs (connection);
g_warning ("Invalid connection: '%s' / '%s' invalid: %d",
g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),
error->message, error->code);
g_error_free (error);
goto err;
}
utils_clear_filled_connection_certs (connection);
fill_vpn_user_name (connection);
return object;
err:
g_object_unref (object);
return NULL;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 92,523,945,177,845,830,000,000,000,000,000,000,000 | 48 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
nm_gconf_read_connection (GConfClient *client,
const char *dir)
{
ReadFromGConfInfo info;
GSList *list;
GError *err = NULL;
list = gconf_client_all_dirs (client, dir, &err);
if (err) {
g_warning ("Error while reading connection: %s", err->message);
g_error_free (err);
return NULL;
}
if (!list) {
g_warning ("Invalid connection (empty)");
return NULL;
}
info.connection = nm_connection_new ();
info.client = client;
info.dir = dir;
info.dir_len = strlen (dir);
g_slist_foreach (list, read_one_setting, &info);
g_slist_free (list);
return info.connection;
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 197,370,786,329,335,370,000,000,000,000,000,000,000 | 29 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
edit_done_cb (NMConnectionEditor *editor, gint response, GError *error, gpointer user_data)
{
EditConnectionInfo *info = (EditConnectionInfo *) user_data;
const char *message = _("An unknown error ocurred.");
g_hash_table_remove (info->list->editors, info->original_connection);
if (response == GTK_RESPONSE_NONE) {
if (error && error->message)
message = error->message;
error_dialog (GTK_WINDOW (editor->window), _("Error initializing editor"), "%s", message);
} else if (response == GTK_RESPONSE_OK) {
NMConnection *connection;
GError *edit_error = NULL;
gboolean success;
connection = nm_connection_editor_get_connection (editor);
utils_fill_connection_certs (connection);
success = nm_connection_verify (connection, &edit_error);
utils_clear_filled_connection_certs (connection);
if (success) {
update_connection (info->list, editor, info->original_connection,
connection, connection_updated_cb, info);
} else {
g_warning ("%s: invalid connection after update: bug in the "
"'%s' / '%s' invalid: %d",
__func__,
g_type_name (nm_connection_lookup_setting_type_by_quark (edit_error->domain)),
edit_error->message, edit_error->code);
g_error_free (edit_error);
connection_updated_cb (info->list, FALSE, user_data);
}
}
} | 1 | [
"CWE-310"
] | network-manager-applet | 4020594dfbf566f1852f0acb36ad631a9e73a82b | 130,618,747,488,396,050,000,000,000,000,000,000,000 | 36 | core: fix CA cert mishandling after cert file deletion (deb #560067) (rh #546793)
If a connection was created with a CA certificate, but the user later
moved or deleted that CA certificate, the applet would simply provide the
connection to NetworkManager without any CA certificate. This could cause
NM to connect to the original network (or a network spoofing the original
network) without verifying the identity of the network as the user
expects.
In the future we can/should do better here by (1) alerting the user that
some connection is now no longer complete by flagging it in the connection
editor or notifying the user somehow, and (2) by using a freaking' cert
store already (not that Linux has one yet). |
static int ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
struct fw_iso_packet *packet,
struct fw_iso_buffer *buffer,
unsigned long payload)
{
struct iso_context *ctx = container_of(base, struct iso_context, base);
struct db_descriptor *db = NULL;
struct descriptor *d;
struct fw_iso_packet *p;
dma_addr_t d_bus, page_bus;
u32 z, header_z, length, rest;
int page, offset, packet_count, header_size;
/*
* FIXME: Cycle lost behavior should be configurable: lose
* packet, retransmit or terminate..
*/
p = packet;
z = 2;
/*
* The OHCI controller puts the isochronous header and trailer in the
* buffer, so we need at least 8 bytes.
*/
packet_count = p->header_length / ctx->base.header_size;
header_size = packet_count * max(ctx->base.header_size, (size_t)8);
/* Get header size in number of descriptors. */
header_z = DIV_ROUND_UP(header_size, sizeof(*d));
page = payload >> PAGE_SHIFT;
offset = payload & ~PAGE_MASK;
rest = p->payload_length;
/* FIXME: make packet-per-buffer/dual-buffer a context option */
while (rest > 0) {
d = context_get_descriptors(&ctx->context,
z + header_z, &d_bus);
if (d == NULL)
return -ENOMEM;
db = (struct db_descriptor *) d;
db->control = cpu_to_le16(DESCRIPTOR_STATUS |
DESCRIPTOR_BRANCH_ALWAYS);
db->first_size =
cpu_to_le16(max(ctx->base.header_size, (size_t)8));
if (p->skip && rest == p->payload_length) {
db->control |= cpu_to_le16(DESCRIPTOR_WAIT);
db->first_req_count = db->first_size;
} else {
db->first_req_count = cpu_to_le16(header_size);
}
db->first_res_count = db->first_req_count;
db->first_buffer = cpu_to_le32(d_bus + sizeof(*db));
if (p->skip && rest == p->payload_length)
length = 4;
else if (offset + rest < PAGE_SIZE)
length = rest;
else
length = PAGE_SIZE - offset;
db->second_req_count = cpu_to_le16(length);
db->second_res_count = db->second_req_count;
page_bus = page_private(buffer->pages[page]);
db->second_buffer = cpu_to_le32(page_bus + offset);
if (p->interrupt && length == rest)
db->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
context_append(&ctx->context, d, z, header_z);
offset = (offset + length) & ~PAGE_MASK;
rest -= length;
if (offset == 0)
page++;
}
return 0;
} | 1 | [
"CWE-399"
] | linux-2.6 | 8c0c0cc2d9f4c523fde04bdfe41e4380dec8ee54 | 56,033,067,427,024,540,000,000,000,000,000,000,000 | 79 | firewire: ohci: handle receive packets with a data length of zero
Queueing to receive an ISO packet with a payload length of zero
silently does nothing in dualbuffer mode, and crashes the kernel in
packet-per-buffer mode. Return an error in dualbuffer mode, because
the DMA controller won't let us do what we want, and work correctly in
packet-per-buffer mode.
Signed-off-by: Jay Fenlason <fenlason@redhat.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: stable@kernel.org |
static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
struct fw_iso_packet *packet,
struct fw_iso_buffer *buffer,
unsigned long payload)
{
struct iso_context *ctx = container_of(base, struct iso_context, base);
struct descriptor *d = NULL, *pd = NULL;
struct fw_iso_packet *p = packet;
dma_addr_t d_bus, page_bus;
u32 z, header_z, rest;
int i, j, length;
int page, offset, packet_count, header_size, payload_per_buffer;
/*
* The OHCI controller puts the isochronous header and trailer in the
* buffer, so we need at least 8 bytes.
*/
packet_count = p->header_length / ctx->base.header_size;
header_size = max(ctx->base.header_size, (size_t)8);
/* Get header size in number of descriptors. */
header_z = DIV_ROUND_UP(header_size, sizeof(*d));
page = payload >> PAGE_SHIFT;
offset = payload & ~PAGE_MASK;
payload_per_buffer = p->payload_length / packet_count;
for (i = 0; i < packet_count; i++) {
/* d points to the header descriptor */
z = DIV_ROUND_UP(payload_per_buffer + offset, PAGE_SIZE) + 1;
d = context_get_descriptors(&ctx->context,
z + header_z, &d_bus);
if (d == NULL)
return -ENOMEM;
d->control = cpu_to_le16(DESCRIPTOR_STATUS |
DESCRIPTOR_INPUT_MORE);
if (p->skip && i == 0)
d->control |= cpu_to_le16(DESCRIPTOR_WAIT);
d->req_count = cpu_to_le16(header_size);
d->res_count = d->req_count;
d->transfer_status = 0;
d->data_address = cpu_to_le32(d_bus + (z * sizeof(*d)));
rest = payload_per_buffer;
for (j = 1; j < z; j++) {
pd = d + j;
pd->control = cpu_to_le16(DESCRIPTOR_STATUS |
DESCRIPTOR_INPUT_MORE);
if (offset + rest < PAGE_SIZE)
length = rest;
else
length = PAGE_SIZE - offset;
pd->req_count = cpu_to_le16(length);
pd->res_count = pd->req_count;
pd->transfer_status = 0;
page_bus = page_private(buffer->pages[page]);
pd->data_address = cpu_to_le32(page_bus + offset);
offset = (offset + length) & ~PAGE_MASK;
rest -= length;
if (offset == 0)
page++;
}
pd->control = cpu_to_le16(DESCRIPTOR_STATUS |
DESCRIPTOR_INPUT_LAST |
DESCRIPTOR_BRANCH_ALWAYS);
if (p->interrupt && i == packet_count - 1)
pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
context_append(&ctx->context, d, z, header_z);
}
return 0;
} | 1 | [
"CWE-399"
] | linux-2.6 | 8c0c0cc2d9f4c523fde04bdfe41e4380dec8ee54 | 99,766,993,200,932,650,000,000,000,000,000,000,000 | 76 | firewire: ohci: handle receive packets with a data length of zero
Queueing to receive an ISO packet with a payload length of zero
silently does nothing in dualbuffer mode, and crashes the kernel in
packet-per-buffer mode. Return an error in dualbuffer mode, because
the DMA controller won't let us do what we want, and work correctly in
packet-per-buffer mode.
Signed-off-by: Jay Fenlason <fenlason@redhat.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: stable@kernel.org |
activate_parameters_install_free (ActivateParametersInstall *parameters_install)
{
if (parameters_install->slot_info) {
g_object_remove_weak_pointer (G_OBJECT (parameters_install->slot_info), (gpointer *)¶meters_install->slot_info);
}
if (parameters_install->parent_window) {
g_object_remove_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *)¶meters_install->parent_window);
}
nautilus_file_list_free (parameters_install->files);
g_free (parameters_install->activation_directory);
g_free (parameters_install);
} | 1 | [] | nautilus | 7632a3e13874a2c5e8988428ca913620a25df983 | 209,005,000,117,092,340,000,000,000,000,000,000,000 | 12 | Check for trusted desktop file launchers.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
Check for trusted desktop file launchers.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
Add nautilus_file_is_trusted_link.
Allow unsetting of custom display name.
* libnautilus-private/nautilus-mime-actions.c:
Display dialog when trying to launch a non-trusted desktop file.
svn path=/trunk/; revision=15003 |
link_info_done (NautilusDirectory *directory,
NautilusFile *file,
const char *uri,
const char *name,
const char *icon,
gboolean is_launcher,
gboolean is_foreign)
{
file->details->link_info_is_up_to_date = TRUE;
nautilus_file_set_display_name (file, name, name, TRUE);
file->details->got_link_info = TRUE;
g_free (file->details->custom_icon);
if (uri) {
if (file->details->activation_location) {
g_object_unref (file->details->activation_location);
file->details->activation_location = NULL;
}
file->details->got_custom_activation_location = TRUE;
file->details->activation_location = g_file_new_for_uri (uri);
}
file->details->custom_icon = g_strdup (icon);
file->details->is_launcher = is_launcher;
file->details->is_foreign_link = is_foreign;
nautilus_directory_async_state_changed (directory);
} | 1 | [] | nautilus | 7632a3e13874a2c5e8988428ca913620a25df983 | 242,951,921,570,172,700,000,000,000,000,000,000,000 | 28 | Check for trusted desktop file launchers.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
Check for trusted desktop file launchers.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
Add nautilus_file_is_trusted_link.
Allow unsetting of custom display name.
* libnautilus-private/nautilus-mime-actions.c:
Display dialog when trying to launch a non-trusted desktop file.
svn path=/trunk/; revision=15003 |
nautilus_file_set_display_name (NautilusFile *file,
const char *display_name,
const char *edit_name,
gboolean custom)
{
gboolean changed;
if (display_name == NULL || *display_name == 0) {
return FALSE;
}
if (!custom && file->details->got_custom_display_name) {
return FALSE;
}
if (custom && display_name == NULL) {
/* We're re-setting a custom display name, invalidate it if
we already set it so that the old one is re-read */
if (file->details->got_custom_display_name) {
file->details->got_custom_display_name = FALSE;
nautilus_file_invalidate_attributes (file,
NAUTILUS_FILE_ATTRIBUTE_INFO);
}
return FALSE;
}
if (edit_name == NULL) {
edit_name = display_name;
}
changed = FALSE;
if (eel_strcmp (eel_ref_str_peek (file->details->display_name), display_name) != 0) {
changed = TRUE;
eel_ref_str_unref (file->details->display_name);
if (eel_strcmp (eel_ref_str_peek (file->details->name), display_name) == 0) {
file->details->display_name = eel_ref_str_ref (file->details->name);
} else {
file->details->display_name = eel_ref_str_new (display_name);
}
g_free (file->details->display_name_collation_key);
file->details->display_name_collation_key = g_utf8_collate_key_for_filename (display_name, -1);
}
if (eel_strcmp (eel_ref_str_peek (file->details->edit_name), edit_name) != 0) {
changed = TRUE;
eel_ref_str_unref (file->details->edit_name);
if (eel_strcmp (eel_ref_str_peek (file->details->display_name), edit_name) == 0) {
file->details->edit_name = eel_ref_str_ref (file->details->display_name);
} else {
file->details->edit_name = eel_ref_str_new (edit_name);
}
}
file->details->got_custom_display_name = custom;
return changed;
} | 1 | [] | nautilus | 7632a3e13874a2c5e8988428ca913620a25df983 | 36,011,517,159,863,600,000,000,000,000,000,000,000 | 61 | Check for trusted desktop file launchers.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
Check for trusted desktop file launchers.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
Add nautilus_file_is_trusted_link.
Allow unsetting of custom display name.
* libnautilus-private/nautilus-mime-actions.c:
Display dialog when trying to launch a non-trusted desktop file.
svn path=/trunk/; revision=15003 |
activate_files (ActivateParameters *parameters)
{
NautilusWindowInfo *window_info;
NautilusWindowOpenFlags flags;
NautilusFile *file;
GList *launch_desktop_files;
GList *launch_files;
GList *launch_in_terminal_files;
GList *open_in_app_files;
GList *open_in_app_parameters;
GList *unhandled_open_in_app_files;
ApplicationLaunchParameters *one_parameters;
GList *open_in_view_files;
GList *l;
int count;
char *uri;
char *executable_path, *quoted_path, *name;
char *old_working_dir;
ActivationAction action;
GdkScreen *screen;
screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
launch_desktop_files = NULL;
launch_files = NULL;
launch_in_terminal_files = NULL;
open_in_app_files = NULL;
open_in_view_files = NULL;
for (l = parameters->files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
if (file_was_cancelled (file)) {
continue;
}
action = get_activation_action (file);
if (action == ACTIVATION_ACTION_ASK) {
/* Special case for executable text files, since it might be
* dangerous & unexpected to launch these.
*/
pause_activation_timed_cancel (parameters);
action = get_executable_text_file_action (parameters->parent_window, file);
unpause_activation_timed_cancel (parameters);
}
switch (action) {
case ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE :
launch_desktop_files = g_list_prepend (launch_desktop_files, file);
break;
case ACTIVATION_ACTION_LAUNCH :
launch_files = g_list_prepend (launch_files, file);
break;
case ACTIVATION_ACTION_LAUNCH_IN_TERMINAL :
launch_in_terminal_files = g_list_prepend (launch_in_terminal_files, file);
break;
case ACTIVATION_ACTION_OPEN_IN_VIEW :
open_in_view_files = g_list_prepend (open_in_view_files, file);
break;
case ACTIVATION_ACTION_OPEN_IN_APPLICATION :
open_in_app_files = g_list_prepend (open_in_app_files, file);
break;
case ACTIVATION_ACTION_DO_NOTHING :
break;
case ACTIVATION_ACTION_ASK :
g_assert_not_reached ();
break;
}
}
launch_desktop_files = g_list_reverse (launch_desktop_files);
for (l = launch_desktop_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
uri = nautilus_file_get_uri (file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_desktop_file window=%p: %s",
parameters->parent_window, uri);
nautilus_launch_desktop_file (screen, uri, NULL,
parameters->parent_window);
g_free (uri);
}
old_working_dir = NULL;
if (parameters->activation_directory &&
(launch_files != NULL || launch_in_terminal_files != NULL)) {
old_working_dir = g_get_current_dir ();
g_chdir (parameters->activation_directory);
}
launch_files = g_list_reverse (launch_files);
for (l = launch_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
uri = nautilus_file_get_activation_uri (file);
executable_path = g_filename_from_uri (uri, NULL, NULL);
quoted_path = g_shell_quote (executable_path);
name = nautilus_file_get_name (file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_file window=%p: %s",
parameters->parent_window, quoted_path);
nautilus_launch_application_from_command (screen, name, quoted_path, FALSE, NULL);
g_free (name);
g_free (quoted_path);
g_free (executable_path);
g_free (uri);
}
launch_in_terminal_files = g_list_reverse (launch_in_terminal_files);
for (l = launch_in_terminal_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
uri = nautilus_file_get_activation_uri (file);
executable_path = g_filename_from_uri (uri, NULL, NULL);
quoted_path = g_shell_quote (executable_path);
name = nautilus_file_get_name (file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_in_terminal window=%p: %s",
parameters->parent_window, quoted_path);
nautilus_launch_application_from_command (screen, name, quoted_path, TRUE, NULL);
g_free (name);
g_free (quoted_path);
g_free (executable_path);
g_free (uri);
}
if (old_working_dir != NULL) {
g_chdir (old_working_dir);
g_free (old_working_dir);
}
open_in_view_files = g_list_reverse (open_in_view_files);
count = g_list_length (open_in_view_files);
flags = parameters->flags;
if (count > 1) {
if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ENABLE_TABS) &&
(parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0) {
flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
} else {
flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
}
}
if (parameters->slot_info != NULL &&
(!parameters->user_confirmation ||
confirm_multiple_windows (parameters->parent_window, count,
(flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0))) {
if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0 &&
eel_preferences_get_enum (NAUTILUS_PREFERENCES_NEW_TAB_POSITION) ==
NAUTILUS_NEW_TAB_POSITION_AFTER_CURRENT_TAB) {
/* When inserting N tabs after the current one,
* we first open tab N, then tab N-1, ..., then tab 0.
* Each of them is appended to the current tab, i.e.
* prepended to the list of tabs to open.
*/
open_in_view_files = g_list_reverse (open_in_view_files);
}
for (l = open_in_view_files; l != NULL; l = l->next) {
GFile *f;
/* The ui should ask for navigation or object windows
* depending on what the current one is */
file = NAUTILUS_FILE (l->data);
uri = nautilus_file_get_activation_uri (file);
f = g_file_new_for_uri (uri);
nautilus_window_slot_info_open_location (parameters->slot_info,
f, parameters->mode, flags, NULL);
g_object_unref (f);
g_free (uri);
}
}
open_in_app_parameters = NULL;
unhandled_open_in_app_files = NULL;
if (open_in_app_files != NULL) {
open_in_app_files = g_list_reverse (open_in_app_files);
open_in_app_parameters = fm_directory_view_make_activation_parameters
(open_in_app_files, &unhandled_open_in_app_files);
}
for (l = open_in_app_parameters; l != NULL; l = l->next) {
one_parameters = l->data;
nautilus_launch_application (one_parameters->application,
one_parameters->files,
parameters->parent_window);
application_launch_parameters_free (one_parameters);
}
for (l = unhandled_open_in_app_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
/* this does not block */
application_unhandled_file (parameters, file);
}
window_info = NULL;
if (parameters->slot_info != NULL) {
window_info = nautilus_window_slot_info_get_window (parameters->slot_info);
}
if (open_in_app_parameters != NULL ||
unhandled_open_in_app_files != NULL) {
if ((parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0 &&
window_info != NULL &&
nautilus_window_info_get_window_type (window_info) == NAUTILUS_WINDOW_SPATIAL) {
nautilus_window_info_close (window_info);
}
}
g_list_free (launch_desktop_files);
g_list_free (launch_files);
g_list_free (launch_in_terminal_files);
g_list_free (open_in_view_files);
g_list_free (open_in_app_files);
g_list_free (open_in_app_parameters);
g_list_free (unhandled_open_in_app_files);
activation_parameters_free (parameters);
} | 1 | [] | nautilus | 7632a3e13874a2c5e8988428ca913620a25df983 | 311,219,075,900,851,730,000,000,000,000,000,000,000 | 232 | Check for trusted desktop file launchers.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
Check for trusted desktop file launchers.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
Add nautilus_file_is_trusted_link.
Allow unsetting of custom display name.
* libnautilus-private/nautilus-mime-actions.c:
Display dialog when trying to launch a non-trusted desktop file.
svn path=/trunk/; revision=15003 |
nautilus_file_clear_info (NautilusFile *file)
{
file->details->got_file_info = FALSE;
if (file->details->get_info_error) {
g_error_free (file->details->get_info_error);
file->details->get_info_error = NULL;
}
/* Reset to default type, which might be other than unknown for
special kinds of files like the desktop or a search directory */
file->details->type = NAUTILUS_FILE_GET_CLASS (file)->default_file_type;
if (!file->details->got_custom_display_name) {
nautilus_file_clear_display_name (file);
}
if (!file->details->got_custom_activation_location &&
file->details->activation_location != NULL) {
g_object_unref (file->details->activation_location);
file->details->activation_location = NULL;
}
if (file->details->icon != NULL) {
g_object_unref (file->details->icon);
file->details->icon = NULL;
}
g_free (file->details->thumbnail_path);
file->details->thumbnail_path = NULL;
file->details->thumbnailing_failed = FALSE;
file->details->is_launcher = FALSE;
file->details->is_foreign_link = FALSE;
file->details->is_symlink = FALSE;
file->details->is_hidden = FALSE;
file->details->is_backup = FALSE;
file->details->is_mountpoint = FALSE;
file->details->uid = -1;
file->details->gid = -1;
file->details->can_read = TRUE;
file->details->can_write = TRUE;
file->details->can_execute = TRUE;
file->details->can_delete = TRUE;
file->details->can_trash = TRUE;
file->details->can_rename = TRUE;
file->details->can_mount = FALSE;
file->details->can_unmount = FALSE;
file->details->can_eject = FALSE;
file->details->has_permissions = FALSE;
file->details->permissions = 0;
file->details->size = -1;
file->details->sort_order = 0;
file->details->mtime = 0;
file->details->atime = 0;
file->details->ctime = 0;
g_free (file->details->symlink_name);
file->details->symlink_name = NULL;
eel_ref_str_unref (file->details->mime_type);
file->details->mime_type = NULL;
g_free (file->details->selinux_context);
file->details->selinux_context = NULL;
g_free (file->details->description);
file->details->description = NULL;
eel_ref_str_unref (file->details->filesystem_id);
file->details->filesystem_id = NULL;
} | 1 | [] | nautilus | 7632a3e13874a2c5e8988428ca913620a25df983 | 230,672,749,510,001,500,000,000,000,000,000,000,000 | 66 | Check for trusted desktop file launchers.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
Check for trusted desktop file launchers.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
Add nautilus_file_is_trusted_link.
Allow unsetting of custom display name.
* libnautilus-private/nautilus-mime-actions.c:
Display dialog when trying to launch a non-trusted desktop file.
svn path=/trunk/; revision=15003 |
mark_trusted_callback (NautilusFile *file,
GFile *result_location,
GError *error,
gpointer callback_data)
{
ActivateParametersDesktop *parameters;
parameters = callback_data;
if (error) {
eel_show_error_dialog (_("Unable to mark launcher trusted (executable)"),
error->message,
parameters->parent_window);
}
activate_parameters_desktop_free (parameters);
} | 1 | [] | nautilus | ca2fd475297946f163c32dcea897f25da892b89d | 259,051,940,915,963,100,000,000,000,000,000,000,000 | 16 | Add nautilus_file_mark_desktop_file_trusted(), this now adds a #! line if
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
Add nautilus_file_mark_desktop_file_trusted(), this now
adds a #! line if there is none as well as makes the file
executable.
* libnautilus-private/nautilus-mime-actions.c:
Use nautilus_file_mark_desktop_file_trusted() instead of
just setting the permissions.
svn path=/trunk/; revision=15006 |
untrusted_launcher_response_callback (GtkDialog *dialog,
int response_id,
ActivateParametersDesktop *parameters)
{
GdkScreen *screen;
char *uri;
gboolean free_params;
free_params = TRUE;
switch (response_id) {
case RESPONSE_RUN:
screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
uri = nautilus_file_get_uri (parameters->file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_desktop_file window=%p: %s",
parameters->parent_window, uri);
nautilus_launch_desktop_file (screen, uri, NULL,
parameters->parent_window);
g_free (uri);
break;
case RESPONSE_MARK_TRUSTED:
nautilus_file_set_permissions (parameters->file,
nautilus_file_get_permissions (parameters->file) | S_IXGRP | S_IXUSR | S_IXOTH,
mark_trusted_callback,
parameters);
free_params = FALSE;
break;
default:
/* Just destroy dialog */
break;
}
gtk_widget_destroy (GTK_WIDGET (dialog));
if (free_params) {
activate_parameters_desktop_free (parameters);
}
} | 1 | [] | nautilus | ca2fd475297946f163c32dcea897f25da892b89d | 12,852,336,747,372,898,000,000,000,000,000,000,000 | 37 | Add nautilus_file_mark_desktop_file_trusted(), this now adds a #! line if
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
Add nautilus_file_mark_desktop_file_trusted(), this now
adds a #! line if there is none as well as makes the file
executable.
* libnautilus-private/nautilus-mime-actions.c:
Use nautilus_file_mark_desktop_file_trusted() instead of
just setting the permissions.
svn path=/trunk/; revision=15006 |
finish_startup (NautilusApplication *application)
{
GList *drives;
/* initialize nautilus modules */
nautilus_module_setup ();
/* attach menu-provider module callback */
menu_provider_init_callback ();
/* Initialize the desktop link monitor singleton */
nautilus_desktop_link_monitor_get ();
/* Watch for mounts so we can restore open windows This used
* to be for showing new window on mount, but is not used
* anymore */
/* Watch for unmounts so we can close open windows */
/* TODO-gio: This should be using the UNMOUNTED feature of GFileMonitor instead */
application->volume_monitor = g_volume_monitor_get ();
g_signal_connect_object (application->volume_monitor, "mount_removed",
G_CALLBACK (mount_removed_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "mount_pre_unmount",
G_CALLBACK (mount_removed_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "mount_added",
G_CALLBACK (mount_added_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "volume_added",
G_CALLBACK (volume_added_callback), application, 0);
g_signal_connect_object (application->volume_monitor, "drive_connected",
G_CALLBACK (drive_connected_callback), application, 0);
/* listen for eject button presses */
drives = g_volume_monitor_get_connected_drives (application->volume_monitor);
g_list_foreach (drives, (GFunc) drive_listen_for_eject_button, application);
g_list_foreach (drives, (GFunc) g_object_unref, NULL);
g_list_free (drives);
application->automount_idle_id =
g_idle_add_full (G_PRIORITY_LOW,
automount_all_volumes_idle_cb,
application, NULL);
} | 1 | [] | nautilus | 1e1c916f5537eb5e4144950f291f4a3962fc2395 | 97,009,948,731,994,360,000,000,000,000,000,000,000 | 42 | Add "interactive" argument to nautilus_file_mark_desktop_file_trusted.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
* libnautilus-private/nautilus-mime-actions.c:
Add "interactive" argument to
nautilus_file_mark_desktop_file_trusted.
* src/nautilus-application.c:
Mark all desktopfiles on the desktop trusted on first
run.
svn path=/trunk/; revision=15009 |
mark_trusted_job (GIOSchedulerJob *io_job,
GCancellable *cancellable,
gpointer user_data)
{
MarkTrustedJob *job = user_data;
CommonJob *common;
char *contents, *new_contents;
gsize length, new_length;
GError *error;
guint32 current;
int response;
GFileInfo *info;
common = (CommonJob *)job;
common->io_job = io_job;
nautilus_progress_info_start (job->common.progress);
retry:
error = NULL;
if (!g_file_load_contents (job->file,
cancellable,
&contents, &length,
NULL, &error)) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (!g_str_has_prefix (contents, "#!")) {
new_length = length + strlen (TRUSTED_SHEBANG);
new_contents = g_malloc (new_length);
strcpy (new_contents, TRUSTED_SHEBANG);
memcpy (new_contents + strlen (TRUSTED_SHEBANG),
contents, length);
if (!g_file_replace_contents (job->file,
new_contents,
new_length,
NULL,
FALSE, 0,
NULL, cancellable, &error)) {
g_free (contents);
g_free (new_contents);
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
g_free (new_contents);
}
g_free (contents);
info = g_file_query_info (job->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_UNIX_MODE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable,
&error);
if (info == NULL) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
current = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
current = current | S_IXGRP | S_IXUSR | S_IXOTH;
if (!g_file_set_attribute_uint32 (job->file, G_FILE_ATTRIBUTE_UNIX_MODE,
current, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable, &error))
{
g_object_unref (info);
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
}
g_object_unref (info);
out:
g_io_scheduler_job_send_to_mainloop_async (io_job,
mark_trusted_job_done,
job,
NULL);
return FALSE;
} | 1 | [] | nautilus | 1e1c916f5537eb5e4144950f291f4a3962fc2395 | 93,816,849,436,748,860,000,000,000,000,000,000,000 | 151 | Add "interactive" argument to nautilus_file_mark_desktop_file_trusted.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
* libnautilus-private/nautilus-mime-actions.c:
Add "interactive" argument to
nautilus_file_mark_desktop_file_trusted.
* src/nautilus-application.c:
Mark all desktopfiles on the desktop trusted on first
run.
svn path=/trunk/; revision=15009 |
untrusted_launcher_response_callback (GtkDialog *dialog,
int response_id,
ActivateParametersDesktop *parameters)
{
GdkScreen *screen;
char *uri;
GFile *file;
switch (response_id) {
case RESPONSE_RUN:
screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
uri = nautilus_file_get_uri (parameters->file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_desktop_file window=%p: %s",
parameters->parent_window, uri);
nautilus_launch_desktop_file (screen, uri, NULL,
parameters->parent_window);
g_free (uri);
break;
case RESPONSE_MARK_TRUSTED:
file = nautilus_file_get_location (parameters->file);
nautilus_file_mark_desktop_file_trusted (file,
parameters->parent_window,
NULL, NULL);
g_object_unref (file);
break;
default:
/* Just destroy dialog */
break;
}
gtk_widget_destroy (GTK_WIDGET (dialog));
activate_parameters_desktop_free (parameters);
} | 1 | [] | nautilus | 1e1c916f5537eb5e4144950f291f4a3962fc2395 | 280,535,660,110,794,430,000,000,000,000,000,000,000 | 34 | Add "interactive" argument to nautilus_file_mark_desktop_file_trusted.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
* libnautilus-private/nautilus-mime-actions.c:
Add "interactive" argument to
nautilus_file_mark_desktop_file_trusted.
* src/nautilus-application.c:
Mark all desktopfiles on the desktop trusted on first
run.
svn path=/trunk/; revision=15009 |
nautilus_application_startup (NautilusApplication *application,
gboolean kill_shell,
gboolean no_default_window,
gboolean no_desktop,
gboolean browser_window,
const char *geometry,
char **urls)
{
UniqueMessageData *message;
/* Check the user's ~/.nautilus directories and post warnings
* if there are problems.
*/
if (!kill_shell && !check_required_directories (application)) {
return;
}
if (kill_shell) {
if (unique_app_is_running (application->unique_app)) {
unique_app_send_message (application->unique_app,
UNIQUE_CLOSE, NULL);
}
} else {
/* If KDE desktop is running, then force no_desktop */
if (is_kdesktop_present ()) {
no_desktop = TRUE;
}
if (!no_desktop && eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
if (unique_app_is_running (application->unique_app)) {
unique_app_send_message (application->unique_app,
COMMAND_START_DESKTOP, NULL);
} else {
nautilus_application_open_desktop (application);
}
}
if (!unique_app_is_running (application->unique_app)) {
finish_startup (application);
g_signal_connect (application->unique_app, "message-received", G_CALLBACK (message_received_cb), application);
}
/* Monitor the preference to show or hide the desktop */
eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
desktop_changed_callback,
application,
G_OBJECT (application));
/* Monitor the preference to have the desktop */
/* point to the Unix home folder */
eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
desktop_location_changed_callback,
NULL,
G_OBJECT (application));
/* Create the other windows. */
if (urls != NULL || !no_default_window) {
if (unique_app_is_running (application->unique_app)) {
message = unique_message_data_new ();
_unique_message_data_set_geometry_and_uris (message, geometry, urls);
if (browser_window) {
unique_app_send_message (application->unique_app,
COMMAND_OPEN_BROWSER, message);
} else {
unique_app_send_message (application->unique_app,
UNIQUE_OPEN, message);
}
unique_message_data_free (message);
} else {
open_windows (application, NULL,
urls,
geometry,
browser_window);
}
}
/* Load session info if availible */
nautilus_application_load_session (application);
}
} | 1 | [] | nautilus | 1e1c916f5537eb5e4144950f291f4a3962fc2395 | 46,398,737,534,363,160,000,000,000,000,000,000,000 | 81 | Add "interactive" argument to nautilus_file_mark_desktop_file_trusted.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
* libnautilus-private/nautilus-mime-actions.c:
Add "interactive" argument to
nautilus_file_mark_desktop_file_trusted.
* src/nautilus-application.c:
Mark all desktopfiles on the desktop trusted on first
run.
svn path=/trunk/; revision=15009 |
copy_job_done (gpointer user_data)
{
CopyMoveJob *job;
job = user_data;
if (job->done_callback) {
job->done_callback (job->debuting_files, job->done_callback_data);
}
eel_g_object_list_free (job->files);
if (job->destination) {
g_object_unref (job->destination);
}
g_hash_table_unref (job->debuting_files);
g_free (job->icon_positions);
finalize_common ((CommonJob *)job);
nautilus_file_changes_consume_changes (TRUE);
return FALSE;
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 167,717,794,138,903,520,000,000,000,000,000,000,000 | 21 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
mark_desktop_files_trusted (void)
{
char *user_dir, *do_once_file;
GFile *f, *c;
GFileEnumerator *e;
GFileInfo *info;
const char *name;
int fd;
user_dir = nautilus_get_user_directory ();
do_once_file = g_build_filename (user_dir, "converted-launchers", NULL);
g_free (user_dir);
if (g_file_test (do_once_file, G_FILE_TEST_EXISTS)) {
goto out;
}
f = nautilus_get_desktop_location ();
e = g_file_enumerate_children (f,
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE
,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, NULL);
if (e == NULL) {
goto out2;
}
while ((info = g_file_enumerator_next_file (e, NULL, NULL)) != NULL) {
name = g_file_info_get_name (info);
if (g_str_has_suffix (name, ".desktop") &&
!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
c = g_file_get_child (f, name);
nautilus_file_mark_desktop_file_trusted (c,
NULL, FALSE,
NULL, NULL);
g_object_unref (c);
}
g_object_unref (info);
}
g_object_unref (e);
out2:
fd = g_creat (do_once_file, 0666);
close (fd);
g_object_unref (f);
out:
g_free (do_once_file);
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 329,345,661,402,451,840,000,000,000,000,000,000,000 | 52 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
nautilus_file_operations_copy (GList *files,
GArray *relative_item_points,
GFile *target_dir,
GtkWindow *parent_window,
NautilusCopyCallback done_callback,
gpointer done_callback_data)
{
CopyMoveJob *job;
job = op_job_new (CopyMoveJob, parent_window);
job->done_callback = done_callback;
job->done_callback_data = done_callback_data;
job->files = eel_g_object_list_copy (files);
job->destination = g_object_ref (target_dir);
if (relative_item_points != NULL &&
relative_item_points->len > 0) {
job->icon_positions =
g_memdup (relative_item_points->data,
sizeof (GdkPoint) * relative_item_points->len);
job->n_icon_positions = relative_item_points->len;
}
job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
g_io_scheduler_push_job (copy_job,
job,
NULL, /* destroy notify */
0,
job->common.cancellable);
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 242,621,355,176,398,350,000,000,000,000,000,000,000 | 29 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
mark_trusted_job (GIOSchedulerJob *io_job,
GCancellable *cancellable,
gpointer user_data)
{
MarkTrustedJob *job = user_data;
CommonJob *common;
char *contents, *new_contents;
gsize length, new_length;
GError *error;
guint32 current;
int response;
GFileInfo *info;
common = (CommonJob *)job;
common->io_job = io_job;
nautilus_progress_info_start (job->common.progress);
retry:
error = NULL;
if (!g_file_load_contents (job->file,
cancellable,
&contents, &length,
NULL, &error)) {
if (job->interactive) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
} else {
response = 0;
}
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (!g_str_has_prefix (contents, "#!")) {
new_length = length + strlen (TRUSTED_SHEBANG);
new_contents = g_malloc (new_length);
strcpy (new_contents, TRUSTED_SHEBANG);
memcpy (new_contents + strlen (TRUSTED_SHEBANG),
contents, length);
if (!g_file_replace_contents (job->file,
new_contents,
new_length,
NULL,
FALSE, 0,
NULL, cancellable, &error)) {
g_free (contents);
g_free (new_contents);
if (job->interactive) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
} else {
response = 0;
}
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
g_free (new_contents);
}
g_free (contents);
info = g_file_query_info (job->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_UNIX_MODE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable,
&error);
if (info == NULL) {
if (job->interactive) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
} else {
response = 0;
}
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
current = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
current = current | S_IXGRP | S_IXUSR | S_IXOTH;
if (!g_file_set_attribute_uint32 (job->file, G_FILE_ATTRIBUTE_UNIX_MODE,
current, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable, &error))
{
g_object_unref (info);
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
}
g_object_unref (info);
out:
g_io_scheduler_job_send_to_mainloop_async (io_job,
mark_trusted_job_done,
job,
NULL);
return FALSE;
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 262,902,604,970,857,600,000,000,000,000,000,000,000 | 164 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
copy_move_file (CopyMoveJob *copy_job,
GFile *src,
GFile *dest_dir,
gboolean same_fs,
gboolean unique_names,
char **dest_fs_type,
SourceInfo *source_info,
TransferInfo *transfer_info,
GHashTable *debuting_files,
GdkPoint *position,
gboolean overwrite,
gboolean *skipped_file,
gboolean readonly_source_fs)
{
GFile *dest, *new_dest;
GError *error;
GFileCopyFlags flags;
char *primary, *secondary, *details;
int response;
ProgressData pdata;
gboolean would_recurse, is_merge;
CommonJob *job;
gboolean res;
int unique_name_nr;
gboolean handled_invalid_filename;
job = (CommonJob *)copy_job;
if (should_skip_file (job, src)) {
*skipped_file = TRUE;
return;
}
unique_name_nr = 1;
/* another file in the same directory might have handled the invalid
* filename condition for us
*/
handled_invalid_filename = *dest_fs_type != NULL;
if (unique_names) {
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
} else {
dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
}
/* Don't allow recursive move/copy into itself.
* (We would get a file system error if we proceeded but it is nicer to
* detect and report it at this level) */
if (test_dir_is_parent (dest_dir, src)) {
if (job->skip_all_error) {
g_error_free (error);
goto out;
}
/* the run_warning() frees all strings passed in automatically */
primary = copy_job->is_move ? g_strdup (_("You cannot move a folder into itself."))
: g_strdup (_("You cannot copy a folder into itself."));
secondary = g_strdup (_("The destination folder is inside the source folder."));
response = run_warning (job,
primary,
secondary,
NULL,
(source_info->num_files - transfer_info->num_files) > 1,
GTK_STOCK_CANCEL, SKIP_ALL, SKIP,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (job);
} else if (response == 1) { /* skip all */
job->skip_all_error = TRUE;
} else if (response == 2) { /* skip */
/* do nothing */
} else {
g_assert_not_reached ();
}
goto out;
}
/* Don't allow copying over the source or one of the parents of the source.
*/
if (test_dir_is_parent (src, dest)) {
if (job->skip_all_error) {
g_error_free (error);
goto out;
}
/* the run_warning() frees all strings passed in automatically */
primary = copy_job->is_move ? g_strdup (_("You cannot move a file over itself."))
: g_strdup (_("You cannot copy a file over itself."));
secondary = g_strdup (_("The source file would be overwritten by the destination."));
response = run_warning (job,
primary,
secondary,
NULL,
(source_info->num_files - transfer_info->num_files) > 1,
GTK_STOCK_CANCEL, SKIP_ALL, SKIP,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (job);
} else if (response == 1) { /* skip all */
job->skip_all_error = TRUE;
} else if (response == 2) { /* skip */
/* do nothing */
} else {
g_assert_not_reached ();
}
goto out;
}
retry:
error = NULL;
flags = G_FILE_COPY_NOFOLLOW_SYMLINKS;
if (overwrite) {
flags |= G_FILE_COPY_OVERWRITE;
}
if (readonly_source_fs) {
flags |= G_FILE_COPY_TARGET_DEFAULT_PERMS;
}
pdata.job = copy_job;
pdata.last_size = 0;
pdata.source_info = source_info;
pdata.transfer_info = transfer_info;
if (copy_job->is_move) {
res = g_file_move (src, dest,
flags,
job->cancellable,
copy_file_progress_callback,
&pdata,
&error);
} else {
res = g_file_copy (src, dest,
flags,
job->cancellable,
copy_file_progress_callback,
&pdata,
&error);
}
if (res) {
transfer_info->num_files ++;
report_copy_progress (copy_job, source_info, transfer_info);
if (debuting_files) {
if (copy_job->is_move) {
nautilus_file_changes_queue_schedule_metadata_move (src, dest);
} else {
nautilus_file_changes_queue_schedule_metadata_copy (src, dest);
}
if (position) {
nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
} else {
nautilus_file_changes_queue_schedule_position_remove (dest);
}
g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
}
if (copy_job->is_move) {
nautilus_file_changes_queue_file_moved (src, dest);
} else {
nautilus_file_changes_queue_file_added (dest);
}
g_object_unref (dest);
return;
}
if (!handled_invalid_filename &&
IS_IO_ERROR (error, INVALID_FILENAME)) {
handled_invalid_filename = TRUE;
g_assert (*dest_fs_type == NULL);
*dest_fs_type = query_fs_type (dest_dir, job->cancellable);
if (unique_names) {
new_dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr);
} else {
new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
}
if (!g_file_equal (dest, new_dest)) {
g_object_unref (dest);
dest = new_dest;
g_error_free (error);
goto retry;
} else {
g_object_unref (new_dest);
}
}
/* Conflict */
if (!overwrite &&
IS_IO_ERROR (error, EXISTS)) {
gboolean is_merge;
if (unique_names) {
g_object_unref (dest);
dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
g_error_free (error);
goto retry;
}
is_merge = FALSE;
if (is_dir (dest)) {
if (is_dir (src)) {
is_merge = TRUE;
primary = f (_("A folder named \"%B\" already exists. Do you want to merge the source folder?"),
dest);
secondary = f (_("The source folder already exists in \"%B\". "
"Merging will ask for confirmation before replacing any files in the folder that conflict with the files being copied."),
dest_dir);
} else {
primary = f (_("A folder named \"%B\" already exists. Do you want to replace it?"),
dest);
secondary = f (_("The folder already exists in \"%F\". "
"Replacing it will remove all files in the folder."),
dest_dir);
}
} else {
primary = f (_("A file named \"%B\" already exists. Do you want to replace it?"),
dest);
secondary = f (_("The file already exists in \"%F\". "
"Replacing it will overwrite its content."),
dest_dir);
}
if ((is_merge && job->merge_all) ||
(!is_merge && job->replace_all)) {
g_free (primary);
g_free (secondary);
g_error_free (error);
overwrite = TRUE;
goto retry;
}
if (job->skip_all_conflict) {
g_free (primary);
g_free (secondary);
g_error_free (error);
goto out;
}
response = run_warning (job,
primary,
secondary,
NULL,
(source_info->num_files - transfer_info->num_files) > 1,
GTK_STOCK_CANCEL,
SKIP_ALL,
is_merge?MERGE_ALL:REPLACE_ALL,
SKIP,
is_merge?MERGE:REPLACE,
NULL);
g_error_free (error);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (job);
} else if (response == 1 || response == 3) { /* skip all / skip */
if (response == 1) {
job->skip_all_conflict = TRUE;
}
} else if (response == 2 || response == 4) { /* merge/replace all / merge/replace*/
if (response == 2) {
if (is_merge) {
job->merge_all = TRUE;
} else {
job->replace_all = TRUE;
}
}
overwrite = TRUE;
goto retry;
} else {
g_assert_not_reached ();
}
}
else if (overwrite &&
IS_IO_ERROR (error, IS_DIRECTORY)) {
g_error_free (error);
if (remove_target_recursively (job, src, dest, dest)) {
goto retry;
}
}
/* Needs to recurse */
else if (IS_IO_ERROR (error, WOULD_RECURSE) ||
IS_IO_ERROR (error, WOULD_MERGE)) {
is_merge = error->code == G_IO_ERROR_WOULD_MERGE;
would_recurse = error->code == G_IO_ERROR_WOULD_RECURSE;
g_error_free (error);
if (overwrite && would_recurse) {
error = NULL;
/* Copying a dir onto file, first remove the file */
if (!g_file_delete (dest, job->cancellable, &error) &&
!IS_IO_ERROR (error, NOT_FOUND)) {
if (job->skip_all_error) {
g_error_free (error);
goto out;
}
if (copy_job->is_move) {
primary = f (_("Error while moving \"%B\"."), src);
} else {
primary = f (_("Error while copying \"%B\"."), src);
}
secondary = f (_("Could not remove the already existing file with the same name in %F."), dest_dir);
details = error->message;
/* setting TRUE on show_all here, as we could have
* another error on the same file later.
*/
response = run_warning (job,
primary,
secondary,
details,
TRUE,
GTK_STOCK_CANCEL, SKIP_ALL, SKIP,
NULL);
g_error_free (error);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (job);
} else if (response == 1) { /* skip all */
job->skip_all_error = TRUE;
} else if (response == 2) { /* skip */
/* do nothing */
} else {
g_assert_not_reached ();
}
goto out;
}
if (error) {
g_error_free (error);
error = NULL;
}
if (debuting_files) { /* Only remove metadata for toplevel items */
nautilus_file_changes_queue_schedule_metadata_remove (dest);
}
nautilus_file_changes_queue_file_removed (dest);
}
if (is_merge) {
/* On merge we now write in the target directory, which may not
be in the same directory as the source, even if the parent is
(if the merged directory is a mountpoint). This could cause
problems as we then don't transcode filenames.
We just set same_fs to FALSE which is safe but a bit slower. */
same_fs = FALSE;
}
if (!copy_move_directory (copy_job, src, &dest, same_fs,
would_recurse, dest_fs_type,
source_info, transfer_info,
debuting_files, skipped_file,
readonly_source_fs)) {
/* destination changed, since it was an invalid file name */
g_assert (*dest_fs_type != NULL);
handled_invalid_filename = TRUE;
goto retry;
}
g_object_unref (dest);
return;
}
else if (IS_IO_ERROR (error, CANCELLED)) {
g_error_free (error);
}
/* Other error */
else {
if (job->skip_all_error) {
g_error_free (error);
goto out;
}
primary = f (_("Error while copying \"%B\"."), src);
secondary = f (_("There was an error copying the file into %F."), dest_dir);
details = error->message;
response = run_warning (job,
primary,
secondary,
details,
(source_info->num_files - transfer_info->num_files) > 1,
GTK_STOCK_CANCEL, SKIP_ALL, SKIP,
NULL);
g_error_free (error);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (job);
} else if (response == 1) { /* skip all */
job->skip_all_error = TRUE;
} else if (response == 2) { /* skip */
/* do nothing */
} else {
g_assert_not_reached ();
}
}
out:
*skipped_file = TRUE; /* Or aborted, but same-same */
g_object_unref (dest);
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 227,469,512,264,489,660,000,000,000,000,000,000,000 | 422 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
copy_job (GIOSchedulerJob *io_job,
GCancellable *cancellable,
gpointer user_data)
{
CopyMoveJob *job;
CommonJob *common;
SourceInfo source_info;
TransferInfo transfer_info;
char *dest_fs_id;
GFile *dest;
job = user_data;
common = &job->common;
common->io_job = io_job;
dest_fs_id = NULL;
nautilus_progress_info_start (job->common.progress);
scan_sources (job->files,
&source_info,
common,
OP_KIND_COPY);
if (job_aborted (common)) {
goto aborted;
}
if (job->destination) {
dest = g_object_ref (job->destination);
} else {
/* Duplication, no dest,
* use source for free size, etc
*/
dest = g_file_get_parent (job->files->data);
}
verify_destination (&job->common,
dest,
&dest_fs_id,
source_info.num_bytes);
g_object_unref (dest);
if (job_aborted (common)) {
goto aborted;
}
g_timer_start (job->common.time);
memset (&transfer_info, 0, sizeof (transfer_info));
copy_files (job,
dest_fs_id,
&source_info, &transfer_info);
aborted:
g_free (dest_fs_id);
g_io_scheduler_job_send_to_mainloop_async (io_job,
copy_job_done,
job,
NULL);
return FALSE;
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 200,161,684,359,004,300,000,000,000,000,000,000,000 | 63 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
is_link_trusted (NautilusFile *file,
gboolean is_launcher)
{
gboolean res;
if (!is_launcher) {
return TRUE;
}
if (nautilus_file_can_execute (file)) {
return TRUE;
}
res = FALSE;
if (nautilus_file_is_local (file)) {
const char * const * data_dirs;
char *uri, *path;
int i;
data_dirs = g_get_system_data_dirs ();
path = NULL;
uri = nautilus_file_get_uri (file);
if (uri) {
path = g_filename_from_uri (uri, NULL, NULL);
g_free (uri);
}
for (i = 0; path != NULL && data_dirs[i] != NULL; i++) {
if (g_str_has_prefix (path, data_dirs[i])) {
res = TRUE;
break;
}
}
g_free (path);
}
return res;
} | 1 | [] | nautilus | a0f7bb5f2e9af8ecb463b13da834fa8559b0a481 | 264,597,378,473,483,760,000,000,000,000,000,000,000 | 42 | Use $XDG_DATA_HOME/.converted-launchers as marker for one-time desktop
2009-02-25 Alexander Larsson <alexl@redhat.com>
* src/nautilus-application.c:
Use $XDG_DATA_HOME/.converted-launchers as marker for
one-time desktop file trust operation.
* libnautilus-private/nautilus-file-utilities.[ch]:
Add nautilus_is_in_system_dir() to check if path is in
XDG_DATA_DIR or in ~/.gnome2.
* libnautilus-private/nautilus-directory-async.c:
(is_link_trusted):
Use new nautilus_is_in_system_dir() instead of open coding it.
* libnautilus-private/nautilus-file-operations.c:
When copying a desktop file from a trusted location to the desktop,
mark it as trusted.
svn path=/trunk/; revision=15018 |
nautilus_link_get_link_info_given_file_contents (const char *file_contents,
int link_file_size,
const char *file_uri,
char **uri,
char **name,
char **icon,
gboolean *is_launcher,
gboolean *is_foreign)
{
GKeyFile *key_file;
char *type;
char **only_show_in;
char **not_show_in;
if (!is_link_data (file_contents, link_file_size)) {
return;
}
key_file = g_key_file_new ();
if (!g_key_file_load_from_data (key_file,
file_contents,
link_file_size,
G_KEY_FILE_NONE,
NULL)) {
g_key_file_free (key_file);
return;
}
*uri = nautilus_link_get_link_uri_from_desktop (key_file, file_uri);
*name = nautilus_link_get_link_name_from_desktop (key_file);
*icon = nautilus_link_get_link_icon_from_desktop (key_file);
*is_launcher = FALSE;
type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
if (g_strcmp0 (type, "Application") == 0 &&
g_key_file_has_key (key_file, MAIN_GROUP, "Exec", NULL)) {
*is_launcher = TRUE;
}
g_free (type);
*is_foreign = FALSE;
only_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
"OnlyShowIn", NULL, NULL);
if (only_show_in && !string_array_contains (only_show_in, "GNOME")) {
*is_foreign = TRUE;
}
g_strfreev (only_show_in);
not_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
"NotShowIn", NULL, NULL);
if (not_show_in && string_array_contains (not_show_in, "GNOME")) {
*is_foreign = TRUE;
}
g_strfreev (not_show_in);
g_key_file_free (key_file);
} | 1 | [] | nautilus | 6d1d33567cea0590ed1ad00506718f6d591ba95f | 309,260,120,543,232,400,000,000,000,000,000,000,000 | 57 | Bug 573991 – Nautilus does not recognize some .desktop files as
2009-03-04 Alexander Larsson <alexl@redhat.com>
Bug 573991 – Nautilus does not recognize some .desktop files as launchers
* libnautilus-private/nautilus-link.c:
(nautilus_link_get_link_info_given_file_contents):
Don't try to sniff the contents, we'll handle that when parsing anyway.
And sniffing breaks if there are too much comments before the first group in
the desktop file.
svn path=/trunk/; revision=15052 |
is_link_data (const char *file_contents, int file_size)
{
char *mimetype;
gboolean res;
mimetype = g_content_type_guess (NULL, file_contents, file_size, NULL);
res = is_link_mime_type (mimetype);
g_free (mimetype);
return res;
} | 1 | [] | nautilus | 6d1d33567cea0590ed1ad00506718f6d591ba95f | 288,340,764,789,772,060,000,000,000,000,000,000,000 | 10 | Bug 573991 – Nautilus does not recognize some .desktop files as
2009-03-04 Alexander Larsson <alexl@redhat.com>
Bug 573991 – Nautilus does not recognize some .desktop files as launchers
* libnautilus-private/nautilus-link.c:
(nautilus_link_get_link_info_given_file_contents):
Don't try to sniff the contents, we'll handle that when parsing anyway.
And sniffing breaks if there are too much comments before the first group in
the desktop file.
svn path=/trunk/; revision=15052 |
static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov,
unsigned int nr_segs, size_t bytes, bool to_user)
{
struct iov_iter ii;
int page_idx = 0;
if (!bytes)
return 0;
iov_iter_init(&ii, iov, nr_segs, bytes, 0);
while (iov_iter_count(&ii)) {
struct page *page = pages[page_idx++];
size_t todo = min_t(size_t, PAGE_SIZE, iov_iter_count(&ii));
void *kaddr, *map;
kaddr = map = kmap(page);
while (todo) {
char __user *uaddr = ii.iov->iov_base + ii.iov_offset;
size_t iov_len = ii.iov->iov_len - ii.iov_offset;
size_t copy = min(todo, iov_len);
size_t left;
if (!to_user)
left = copy_from_user(kaddr, uaddr, copy);
else
left = copy_to_user(uaddr, kaddr, copy);
if (unlikely(left))
return -EFAULT;
iov_iter_advance(&ii, copy);
todo -= copy;
kaddr += copy;
}
kunmap(map);
}
return 0;
} | 1 | [] | linux-2.6 | 0bd87182d3ab18a32a8e9175d3f68754c58e3432 | 275,150,731,278,663,340,000,000,000,000,000,000,000 | 42 | fuse: fix kunmap in fuse_ioctl_copy_user
Looks like another victim of the confusing kmap() vs kmap_atomic() API
differences.
Reported-by: Todor Gyumyushev <yodor1@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: stable@kernel.org |
int main(int argc, char *argv[])
{
int opt;
char *line;
progname = basename(argv[0]);
#if POSIXLY_CORRECT
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#else
if (getenv(POSIXLY_CORRECT_STR))
posixly_correct = 1;
if (!posixly_correct)
cmd_line_options = CMD_LINE_OPTIONS;
else
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#endif
setlocale(LC_CTYPE, "");
setlocale(LC_MESSAGES, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
/* Align `#effective:' comments to column 40 for tty's */
if (!posixly_correct && isatty(fileno(stdout)))
print_options |= TEXT_SMART_INDENT;
while ((opt = getopt_long(argc, argv, cmd_line_options,
long_options, NULL)) != -1) {
switch (opt) {
case 'a': /* acl only */
if (posixly_correct)
goto synopsis;
opt_print_acl = 1;
break;
case 'd': /* default acl only */
opt_print_default_acl = 1;
break;
case 'c': /* no comments */
if (posixly_correct)
goto synopsis;
opt_comments = 0;
break;
case 'e': /* all #effective comments */
if (posixly_correct)
goto synopsis;
print_options |= TEXT_ALL_EFFECTIVE;
break;
case 'E': /* no #effective comments */
if (posixly_correct)
goto synopsis;
print_options &= ~(TEXT_SOME_EFFECTIVE |
TEXT_ALL_EFFECTIVE);
break;
case 'R': /* recursive */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_RECURSIVE;
break;
case 'L': /* follow all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_LOGICAL;
walk_flags &= ~WALK_TREE_PHYSICAL;
break;
case 'P': /* skip all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_PHYSICAL;
walk_flags &= ~WALK_TREE_LOGICAL;
break;
case 's': /* skip files with only base entries */
if (posixly_correct)
goto synopsis;
opt_skip_base = 1;
break;
case 'p':
if (posixly_correct)
goto synopsis;
opt_strip_leading_slash = 0;
break;
case 't':
if (posixly_correct)
goto synopsis;
opt_tabular = 1;
break;
case 'n': /* numeric */
opt_numeric = 1;
print_options |= TEXT_NUMERIC_IDS;
break;
case 'v': /* print version */
printf("%s " VERSION "\n", progname);
return 0;
case 'h': /* help */
help();
return 0;
case ':': /* option missing */
case '?': /* unknown option */
default:
goto synopsis;
}
}
if (!(opt_print_acl || opt_print_default_acl)) {
opt_print_acl = 1;
if (!posixly_correct)
opt_print_default_acl = 1;
}
if ((optind == argc) && !posixly_correct)
goto synopsis;
do {
if (optind == argc ||
strcmp(argv[optind], "-") == 0) {
while ((line = next_line(stdin)) != NULL) {
if (*line == '\0')
continue;
had_errors += walk_tree(line, walk_flags, 0,
do_print, NULL);
}
if (!feof(stdin)) {
fprintf(stderr, _("%s: Standard input: %s\n"),
progname, strerror(errno));
had_errors++;
}
} else
had_errors += walk_tree(argv[optind], walk_flags, 0,
do_print, NULL);
optind++;
} while (optind < argc);
return had_errors ? 1 : 0;
synopsis:
fprintf(stderr, _("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
fprintf(stderr, _("Try `%s --help' for more information.\n"),
progname);
return 2;
} | 1 | [] | acl | 63451a06b7484d220750ed8574d3ee84e156daf5 | 16,273,504,960,447,625,000,000,000,000,000,000,000 | 156 | Make sure that getfacl -R only calls stat(2) on symlinks when it needs to
This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790
"getfacl follows symlinks, even without -L". |
int unlzw(in, out)
int in, out; /* input and output file descriptors */
{
REG2 char_type *stackp;
REG3 code_int code;
REG4 int finchar;
REG5 code_int oldcode;
REG6 code_int incode;
REG7 long inbits;
REG8 long posbits;
REG9 int outpos;
/* REG10 int insize; (global) */
REG11 unsigned bitmask;
REG12 code_int free_ent;
REG13 code_int maxcode;
REG14 code_int maxmaxcode;
REG15 int n_bits;
REG16 int rsize;
#ifdef MAXSEG_64K
tab_prefix[0] = tab_prefix0;
tab_prefix[1] = tab_prefix1;
#endif
maxbits = get_byte();
block_mode = maxbits & BLOCK_MODE;
if ((maxbits & LZW_RESERVED) != 0) {
WARN((stderr, "\n%s: %s: warning, unknown flags 0x%x\n",
program_name, ifname, maxbits & LZW_RESERVED));
}
maxbits &= BIT_MASK;
maxmaxcode = MAXCODE(maxbits);
if (maxbits > BITS) {
fprintf(stderr,
"\n%s: %s: compressed with %d bits, can only handle %d bits\n",
program_name, ifname, maxbits, BITS);
exit_code = ERROR;
return ERROR;
}
rsize = insize;
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
bitmask = (1<<n_bits)-1;
oldcode = -1;
finchar = 0;
outpos = 0;
posbits = inptr<<3;
free_ent = ((block_mode) ? FIRST : 256);
clear_tab_prefixof(); /* Initialize the first 256 entries in the table. */
for (code = 255 ; code >= 0 ; --code) {
tab_suffixof(code) = (char_type)code;
}
do {
REG1 int i;
int e;
int o;
resetbuf:
e = insize-(o = (posbits>>3));
for (i = 0 ; i < e ; ++i) {
inbuf[i] = inbuf[i+o];
}
insize = e;
posbits = 0;
if (insize < INBUF_EXTRA) {
rsize = read_buffer (in, (char *) inbuf + insize, INBUFSIZ);
if (rsize == -1) {
read_error();
}
insize += rsize;
bytes_in += (off_t)rsize;
}
inbits = ((rsize != 0) ? ((long)insize - insize%n_bits)<<3 :
((long)insize<<3)-(n_bits-1));
while (inbits > posbits) {
if (free_ent > maxcode) {
posbits = ((posbits-1) +
((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
++n_bits;
if (n_bits == maxbits) {
maxcode = maxmaxcode;
} else {
maxcode = MAXCODE(n_bits)-1;
}
bitmask = (1<<n_bits)-1;
goto resetbuf;
}
input(inbuf,posbits,code,n_bits,bitmask);
Tracev((stderr, "%d ", code));
if (oldcode == -1) {
if (256 <= code)
gzip_error ("corrupt input.");
outbuf[outpos++] = (char_type)(finchar = (int)(oldcode=code));
continue;
}
if (code == CLEAR && block_mode) {
clear_tab_prefixof();
free_ent = FIRST - 1;
posbits = ((posbits-1) +
((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
bitmask = (1<<n_bits)-1;
goto resetbuf;
}
incode = code;
stackp = de_stack;
if (code >= free_ent) { /* Special case for KwKwK string. */
if (code > free_ent) {
#ifdef DEBUG
char_type *p;
posbits -= n_bits;
p = &inbuf[posbits>>3];
fprintf(stderr,
"code:%ld free_ent:%ld n_bits:%d insize:%u\n",
code, free_ent, n_bits, insize);
fprintf(stderr,
"posbits:%ld inbuf:%02X %02X %02X %02X %02X\n",
posbits, p[-1],p[0],p[1],p[2],p[3]);
#endif
if (!test && outpos > 0) {
write_buf(out, (char*)outbuf, outpos);
bytes_out += (off_t)outpos;
}
gzip_error (to_stdout
? "corrupt input."
: "corrupt input. Use zcat to recover some data.");
}
*--stackp = (char_type)finchar;
code = oldcode;
}
while ((cmp_code_int)code >= (cmp_code_int)256) {
/* Generate output characters in reverse order */
*--stackp = tab_suffixof(code);
code = tab_prefixof(code);
}
*--stackp = (char_type)(finchar = tab_suffixof(code));
/* And put them out in forward order */
{
REG1 int i;
if (outpos+(i = (de_stack-stackp)) >= OUTBUFSIZ) {
do {
if (i > OUTBUFSIZ-outpos) i = OUTBUFSIZ-outpos;
if (i > 0) {
memcpy(outbuf+outpos, stackp, i);
outpos += i;
}
if (outpos >= OUTBUFSIZ) {
if (!test) {
write_buf(out, (char*)outbuf, outpos);
bytes_out += (off_t)outpos;
}
outpos = 0;
}
stackp+= i;
} while ((i = (de_stack-stackp)) > 0);
} else {
memcpy(outbuf+outpos, stackp, i);
outpos += i;
}
}
if ((code = free_ent) < maxmaxcode) { /* Generate the new entry. */
tab_prefixof(code) = (unsigned short)oldcode;
tab_suffixof(code) = (char_type)finchar;
free_ent = code+1;
}
oldcode = incode; /* Remember previous code. */
}
} while (rsize != 0);
if (!test && outpos > 0) {
write_buf(out, (char*)outbuf, outpos);
bytes_out += (off_t)outpos;
}
return OK;
} | 1 | [
"CWE-189"
] | gzip | a3db5806d012082b9e25cc36d09f19cd736a468f | 125,645,676,816,388,480,000,000,000,000,000,000,000 | 189 | gzip -d: do not clobber stack for valid input on x86_64
* unlzw.c (unlzw): Avoid integer overflow.
Aki Helin reported the segfault along with an input to trigger the bug.
* NEWS (Bug fixes): Mention it. |
_hb_ot_layout_init (hb_face_t *face)
{
hb_ot_layout_t *layout = &face->ot_layout;
layout->gdef_blob = Sanitizer<GDEF>::sanitize (hb_face_get_table (face, HB_OT_TAG_GDEF));
layout->gdef = &Sanitizer<GDEF>::lock_instance (layout->gdef_blob);
layout->gsub_blob = Sanitizer<GSUB>::sanitize (hb_face_get_table (face, HB_OT_TAG_GSUB));
layout->gsub = &Sanitizer<GSUB>::lock_instance (layout->gsub_blob);
layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_get_table (face, HB_OT_TAG_GPOS));
layout->gpos = &Sanitizer<GPOS>::lock_instance (layout->gpos_blob);
} | 1 | [
"CWE-119"
] | pango | 797d46714d27f147277fdd5346648d838c68fb8c | 247,815,931,182,614,300,000,000,000,000,000,000,000 | 13 | [HB/GDEF] Fix bug in building synthetic GDEF table |
hb_ot_layout_build_glyph_classes (hb_face_t *face,
uint16_t num_total_glyphs,
hb_codepoint_t *glyphs,
unsigned char *klasses,
uint16_t count)
{
if (HB_OBJECT_IS_INERT (face))
return;
hb_ot_layout_t *layout = &face->ot_layout;
if (HB_UNLIKELY (!count || !glyphs || !klasses))
return;
if (layout->new_gdef.len == 0) {
layout->new_gdef.klasses = (unsigned char *) calloc (num_total_glyphs, sizeof (unsigned char));
layout->new_gdef.len = count;
}
for (unsigned int i = 0; i < count; i++)
_hb_ot_layout_set_glyph_class (face, glyphs[i], (hb_ot_layout_glyph_class_t) klasses[i]);
} | 1 | [
"CWE-119"
] | pango | 797d46714d27f147277fdd5346648d838c68fb8c | 13,171,715,166,689,818,000,000,000,000,000,000,000 | 22 | [HB/GDEF] Fix bug in building synthetic GDEF table |
static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
{
struct usbdevfs_urb *urb;
AsyncURB *aurb;
int ret, value, index;
/*
* Process certain standard device requests.
* These are infrequent and are processed synchronously.
*/
value = le16_to_cpu(s->ctrl.req.wValue);
index = le16_to_cpu(s->ctrl.req.wIndex);
dprintf("husb: ctrl type 0x%x req 0x%x val 0x%x index %u len %u\n",
s->ctrl.req.bRequestType, s->ctrl.req.bRequest, value, index,
s->ctrl.len);
if (s->ctrl.req.bRequestType == 0) {
switch (s->ctrl.req.bRequest) {
case USB_REQ_SET_ADDRESS:
return usb_host_set_address(s, value);
case USB_REQ_SET_CONFIGURATION:
return usb_host_set_config(s, value & 0xff);
}
}
if (s->ctrl.req.bRequestType == 1 &&
s->ctrl.req.bRequest == USB_REQ_SET_INTERFACE)
return usb_host_set_interface(s, index, value);
/* The rest are asynchronous */
aurb = async_alloc();
aurb->hdev = s;
aurb->packet = p;
/*
* Setup ctrl transfer.
*
* s->ctrl is layed out such that data buffer immediately follows
* 'req' struct which is exactly what usbdevfs expects.
*/
urb = &aurb->urb;
urb->type = USBDEVFS_URB_TYPE_CONTROL;
urb->endpoint = p->devep;
urb->buffer = &s->ctrl.req;
urb->buffer_length = 8 + s->ctrl.len;
urb->usercontext = s;
ret = ioctl(s->fd, USBDEVFS_SUBMITURB, urb);
dprintf("husb: submit ctrl. len %u aurb %p\n", urb->buffer_length, aurb);
if (ret < 0) {
dprintf("husb: submit failed. errno %d\n", errno);
async_free(aurb);
switch(errno) {
case ETIMEDOUT:
return USB_RET_NAK;
case EPIPE:
default:
return USB_RET_STALL;
}
}
usb_defer_packet(p, async_cancel, aurb);
return USB_RET_ASYNC;
} | 1 | [
"CWE-119"
] | qemu | babd03fde68093482528010a5435c14ce9128e3f | 312,416,163,750,000,940,000,000,000,000,000,000,000 | 73 | usb-linux.c: fix buffer overflow
In usb-linux.c:usb_host_handle_control, we pass a 1024-byte buffer and
length to the kernel. However, the length was provided by the caller
of dev->handle_packet, and is not checked, so the kernel might provide
too much data and overflow our buffer.
For example, hw/usb-uhci.c could set the length to 2047.
hw/usb-ohci.c looks like it might go up to 4096 or 8192.
This causes a qemu crash, as reported here:
http://www.mail-archive.com/kvm@vger.kernel.org/msg18447.html
This patch increases the usb-linux.c buffer size to 2048 to fix the
specific device reported, and adds a check to avoid the overflow in
any case.
Signed-off-by: Jim Paris <jim@jtan.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> |
gs_manager_create_window_for_monitor (GSManager *manager,
GdkScreen *screen,
int monitor)
{
GSWindow *window;
GdkRectangle rect;
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
gs_debug ("Creating window for monitor %d [%d,%d] (%dx%d)",
monitor, rect.x, rect.y, rect.width, rect.height);
window = gs_window_new (screen, monitor, manager->priv->lock_active);
gs_window_set_user_switch_enabled (window, manager->priv->user_switch_enabled);
gs_window_set_logout_enabled (window, manager->priv->logout_enabled);
gs_window_set_logout_timeout (window, manager->priv->logout_timeout);
gs_window_set_logout_command (window, manager->priv->logout_command);
gs_window_set_keyboard_enabled (window, manager->priv->keyboard_enabled);
gs_window_set_keyboard_command (window, manager->priv->keyboard_command);
gs_window_set_status_message (window, manager->priv->status_message);
connect_window_signals (manager, window);
manager->priv->windows = g_slist_append (manager->priv->windows, window);
} | 1 | [] | gnome-screensaver | 2f597ea9f1f363277fd4dfc109fa41bbc6225aca | 304,491,975,580,879,030,000,000,000,000,000,000,000 | 26 | Fix adding monitors
Make sure to show windows that are added. And fix an off by one bug. |
on_screen_monitors_changed (GdkScreen *screen,
GSManager *manager)
{
GSList *l;
int n_monitors;
int n_windows;
int i;
n_monitors = gdk_screen_get_n_monitors (screen);
n_windows = g_slist_length (manager->priv->windows);
gs_debug ("Monitors changed for screen %d: num=%d",
gdk_screen_get_number (screen),
n_monitors);
if (n_monitors > n_windows) {
/* add more windows */
for (i = n_windows; i < n_monitors; i++) {
gs_manager_create_window_for_monitor (manager, screen, i - 1);
}
} else {
/* remove the extra windows */
for (l = manager->priv->windows; l != NULL; l = l->next) {
GdkScreen *this_screen;
int this_monitor;
this_screen = gs_window_get_screen (GS_WINDOW (l->data));
this_monitor = gs_window_get_monitor (GS_WINDOW (l->data));
if (this_screen == screen && this_monitor >= n_monitors) {
manager_maybe_stop_job_for_window (manager, GS_WINDOW (l->data));
gs_window_destroy (GS_WINDOW (l->data));
manager->priv->windows = g_slist_delete_link (manager->priv->windows, l);
}
}
}
} | 1 | [] | gnome-screensaver | 2f597ea9f1f363277fd4dfc109fa41bbc6225aca | 105,982,173,161,305,000,000,000,000,000,000,000,000 | 36 | Fix adding monitors
Make sure to show windows that are added. And fix an off by one bug. |
gs_manager_finalize (GObject *object)
{
GSManager *manager;
g_return_if_fail (object != NULL);
g_return_if_fail (GS_IS_MANAGER (object));
manager = GS_MANAGER (object);
g_return_if_fail (manager->priv != NULL);
if (manager->priv->bg_notify_id != 0) {
gconf_client_remove_dir (manager->priv->client,
GNOME_BG_KEY_DIR,
NULL);
gconf_client_notify_remove (manager->priv->client,
manager->priv->bg_notify_id);
manager->priv->bg_notify_id = 0;
}
if (manager->priv->bg != NULL) {
g_object_unref (manager->priv->bg);
}
if (manager->priv->client != NULL) {
g_object_unref (manager->priv->client);
}
free_themes (manager);
g_free (manager->priv->logout_command);
g_free (manager->priv->keyboard_command);
g_free (manager->priv->away_message);
remove_unfade_idle (manager);
remove_timers (manager);
gs_grab_release (manager->priv->grab);
manager_stop_jobs (manager);
gs_manager_destroy_windows (manager);
manager->priv->active = FALSE;
manager->priv->activate_time = 0;
manager->priv->lock_enabled = FALSE;
g_object_unref (manager->priv->fade);
g_object_unref (manager->priv->grab);
g_object_unref (manager->priv->theme_manager);
G_OBJECT_CLASS (gs_manager_parent_class)->finalize (object);
} | 1 | [] | gnome-screensaver | f6d3defdc7080a540d7f8df15dc309a9364ae668 | 340,204,079,059,999,640,000,000,000,000,000,000,000 | 50 | Create or remove windows as number of monitors changes due to randr 1.2
2008-08-20 William Jon McCann <jmccann@redhat.com>
* src/gs-manager.c (gs_manager_create_window_for_monitor),
(on_screen_monitors_changed), (gs_manager_destroy_windows),
(gs_manager_finalize), (gs_manager_create_windows_for_screen):
Create or remove windows as number of monitors changes
due to randr 1.2 goodness.
svn path=/trunk/; revision=1483 |
on_screen_monitors_changed (GdkScreen *screen,
GSManager *manager)
{
gs_debug ("Monitors changed for screen %d: num=%d",
gdk_screen_get_number (screen),
gdk_screen_get_n_monitors (screen));
} | 1 | [] | gnome-screensaver | f6d3defdc7080a540d7f8df15dc309a9364ae668 | 325,565,446,186,664,230,000,000,000,000,000,000,000 | 7 | Create or remove windows as number of monitors changes due to randr 1.2
2008-08-20 William Jon McCann <jmccann@redhat.com>
* src/gs-manager.c (gs_manager_create_window_for_monitor),
(on_screen_monitors_changed), (gs_manager_destroy_windows),
(gs_manager_finalize), (gs_manager_create_windows_for_screen):
Create or remove windows as number of monitors changes
due to randr 1.2 goodness.
svn path=/trunk/; revision=1483 |
gs_manager_create_windows_for_screen (GSManager *manager,
GdkScreen *screen)
{
GSWindow *window;
int n_monitors;
int i;
g_return_if_fail (manager != NULL);
g_return_if_fail (GS_IS_MANAGER (manager));
g_return_if_fail (GDK_IS_SCREEN (screen));
g_object_ref (manager);
g_object_ref (screen);
n_monitors = gdk_screen_get_n_monitors (screen);
gs_debug ("Creating %d windows for screen %d", n_monitors, gdk_screen_get_number (screen));
for (i = 0; i < n_monitors; i++) {
window = gs_window_new (screen, i, manager->priv->lock_active);
gs_window_set_user_switch_enabled (window, manager->priv->user_switch_enabled);
gs_window_set_logout_enabled (window, manager->priv->logout_enabled);
gs_window_set_logout_timeout (window, manager->priv->logout_timeout);
gs_window_set_logout_command (window, manager->priv->logout_command);
gs_window_set_keyboard_enabled (window, manager->priv->keyboard_enabled);
gs_window_set_keyboard_command (window, manager->priv->keyboard_command);
gs_window_set_away_message (window, manager->priv->away_message);
connect_window_signals (manager, window);
manager->priv->windows = g_slist_append (manager->priv->windows, window);
}
g_object_unref (screen);
g_object_unref (manager);
} | 1 | [] | gnome-screensaver | f6d3defdc7080a540d7f8df15dc309a9364ae668 | 143,321,559,131,040,370,000,000,000,000,000,000,000 | 37 | Create or remove windows as number of monitors changes due to randr 1.2
2008-08-20 William Jon McCann <jmccann@redhat.com>
* src/gs-manager.c (gs_manager_create_window_for_monitor),
(on_screen_monitors_changed), (gs_manager_destroy_windows),
(gs_manager_finalize), (gs_manager_create_windows_for_screen):
Create or remove windows as number of monitors changes
due to randr 1.2 goodness.
svn path=/trunk/; revision=1483 |
gs_manager_destroy_windows (GSManager *manager)
{
GdkDisplay *display;
GSList *l;
int n_screens;
int i;
g_return_if_fail (manager != NULL);
g_return_if_fail (GS_IS_MANAGER (manager));
if (manager->priv->windows == NULL) {
return;
}
display = gdk_display_get_default ();
n_screens = gdk_display_get_n_screens (display);
for (i = 0; i < n_screens; i++) {
g_signal_handlers_disconnect_by_func (gdk_display_get_screen (display, i),
on_screen_monitors_changed,
manager);
}
for (l = manager->priv->windows; l; l = l->next) {
gs_window_destroy (l->data);
}
g_slist_free (manager->priv->windows);
manager->priv->windows = NULL;
} | 1 | [] | gnome-screensaver | f6d3defdc7080a540d7f8df15dc309a9364ae668 | 123,569,059,232,976,350,000,000,000,000,000,000,000 | 30 | Create or remove windows as number of monitors changes due to randr 1.2
2008-08-20 William Jon McCann <jmccann@redhat.com>
* src/gs-manager.c (gs_manager_create_window_for_monitor),
(on_screen_monitors_changed), (gs_manager_destroy_windows),
(gs_manager_finalize), (gs_manager_create_windows_for_screen):
Create or remove windows as number of monitors changes
due to randr 1.2 goodness.
svn path=/trunk/; revision=1483 |
auto_configure_outputs (GsdXrandrManager *manager, guint32 timestamp)
{
/* FMQ: implement */
} | 1 | [] | gnome-settings-daemon | be513b3c7d80d0b7013d79ce46d7eeca929705cc | 80,906,546,337,861,210,000,000,000,000,000,000,000 | 4 | Implement autoconfiguration of the outputs
This is similar in spirit to 'xrandr --auto', but we disfavor selecting clone modes.
Instead, we lay out the outputs left-to-right.
Signed-off-by: Federico Mena Quintero <federico@novell.com> |
on_screen_monitors_changed (GdkScreen *screen,
GSManager *manager)
{
GSList *l;
int n_monitors;
int n_windows;
int i;
n_monitors = gdk_screen_get_n_monitors (screen);
n_windows = g_slist_length (manager->priv->windows);
gs_debug ("Monitors changed for screen %d: num=%d",
gdk_screen_get_number (screen),
n_monitors);
if (n_monitors > n_windows) {
/* add more windows */
for (i = n_windows; i < n_monitors; i++) {
gs_manager_create_window_for_monitor (manager, screen, i);
}
} else {
/* remove the extra windows */
l = manager->priv->windows;
while (l != NULL) {
GdkScreen *this_screen;
int this_monitor;
GSList *next = l->next;
this_screen = gs_window_get_screen (GS_WINDOW (l->data));
this_monitor = gs_window_get_monitor (GS_WINDOW (l->data));
if (this_screen == screen && this_monitor >= n_monitors) {
manager_maybe_stop_job_for_window (manager, GS_WINDOW (l->data));
g_hash_table_remove (manager->priv->jobs, l->data);
gs_window_destroy (GS_WINDOW (l->data));
manager->priv->windows = g_slist_delete_link (manager->priv->windows, l);
}
l = next;
}
}
} | 1 | [] | gnome-screensaver | a5f66339be6719c2b8fc478a1d5fc6545297d950 | 250,530,700,843,920,860,000,000,000,000,000,000,000 | 40 | Ensure keyboard grab and unlock dialog exist after monitor removal
gnome-screensaver currently doesn't deal with monitors getting
removed properly. If the unlock dialog is on the removed monitor
then the unlock dialog and its associated keyboard grab are not
moved to an existing monitor when the monitor removal is processed.
This means that users can gain access to the locked system by placing
the mouse pointer on an external monitor and then disconnect the
external monitor.
CVE-2010-0414
https://bugzilla.gnome.org/show_bug.cgi?id=609337 |
gs_window_destroy (GSWindow *window)
{
g_return_if_fail (GS_IS_WINDOW (window));
gtk_widget_destroy (GTK_WIDGET (window));
} | 1 | [] | gnome-screensaver | a5f66339be6719c2b8fc478a1d5fc6545297d950 | 2,440,459,080,582,544,200,000,000,000,000,000,000 | 6 | Ensure keyboard grab and unlock dialog exist after monitor removal
gnome-screensaver currently doesn't deal with monitors getting
removed properly. If the unlock dialog is on the removed monitor
then the unlock dialog and its associated keyboard grab are not
moved to an existing monitor when the monitor removal is processed.
This means that users can gain access to the locked system by placing
the mouse pointer on an external monitor and then disconnect the
external monitor.
CVE-2010-0414
https://bugzilla.gnome.org/show_bug.cgi?id=609337 |
static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
struct smb_request *req,
const char *pdata,
int total_data,
const struct smb_filename *smb_fname)
{
char *link_target = NULL;
const char *newname = smb_fname->base_name;
NTSTATUS status = NT_STATUS_OK;
TALLOC_CTX *ctx = talloc_tos();
/* Set a symbolic link. */
/* Don't allow this if follow links is false. */
if (total_data == 0) {
return NT_STATUS_INVALID_PARAMETER;
}
if (!lp_symlinks(SNUM(conn))) {
return NT_STATUS_ACCESS_DENIED;
}
srvstr_pull_talloc(ctx, pdata, req->flags2, &link_target, pdata,
total_data, STR_TERMINATE);
if (!link_target) {
return NT_STATUS_INVALID_PARAMETER;
}
/* !widelinks forces the target path to be within the share. */
/* This means we can interpret the target as a pathname. */
if (!lp_widelinks(SNUM(conn))) {
char *rel_name = NULL;
char *last_dirp = NULL;
if (*link_target == '/') {
/* No absolute paths allowed. */
return NT_STATUS_ACCESS_DENIED;
}
rel_name = talloc_strdup(ctx,newname);
if (!rel_name) {
return NT_STATUS_NO_MEMORY;
}
last_dirp = strrchr_m(rel_name, '/');
if (last_dirp) {
last_dirp[1] = '\0';
} else {
rel_name = talloc_strdup(ctx,"./");
if (!rel_name) {
return NT_STATUS_NO_MEMORY;
}
}
rel_name = talloc_asprintf_append(rel_name,
"%s",
link_target);
if (!rel_name) {
return NT_STATUS_NO_MEMORY;
}
status = check_name(conn, rel_name);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
newname, link_target ));
if (SMB_VFS_SYMLINK(conn,link_target,newname) != 0) {
return map_nt_error_from_unix(errno);
}
return NT_STATUS_OK;
} | 1 | [
"CWE-22"
] | samba | bd269443e311d96ef495a9db47d1b95eb83bb8f4 | 50,610,553,973,009,060,000,000,000,000,000,000,000 | 74 | Fix bug 7104 - "wide links" and "unix extensions" are incompatible.
Change parameter "wide links" to default to "no".
Ensure "wide links = no" if "unix extensions = yes" on a share.
Fix man pages to refect this.
Remove "within share" checks for a UNIX symlink set - even if
widelinks = no. The server will not follow that link anyway.
Correct DEBUG message in check_reduced_name() to add missing "\n"
so it's really clear when a path is being denied as it's outside
the enclosing share path.
Jeremy. |
connection_struct *make_connection_snum(struct smbd_server_connection *sconn,
int snum, user_struct *vuser,
DATA_BLOB password,
const char *pdev,
NTSTATUS *pstatus)
{
connection_struct *conn;
struct smb_filename *smb_fname_cpath = NULL;
fstring dev;
int ret;
char addr[INET6_ADDRSTRLEN];
bool on_err_call_dis_hook = false;
NTSTATUS status;
fstrcpy(dev, pdev);
if (NT_STATUS_IS_ERR(*pstatus = share_sanity_checks(snum, dev))) {
return NULL;
}
conn = conn_new(sconn);
if (!conn) {
DEBUG(0,("Couldn't find free connection.\n"));
*pstatus = NT_STATUS_INSUFFICIENT_RESOURCES;
return NULL;
}
conn->params->service = snum;
status = create_connection_server_info(sconn,
conn, snum, vuser ? vuser->server_info : NULL, password,
&conn->server_info);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("create_connection_server_info failed: %s\n",
nt_errstr(status)));
*pstatus = status;
conn_free(conn);
return NULL;
}
if ((lp_guest_only(snum)) || (lp_security() == SEC_SHARE)) {
conn->force_user = true;
}
add_session_user(sconn, conn->server_info->unix_name);
safe_strcpy(conn->client_address,
client_addr(get_client_fd(),addr,sizeof(addr)),
sizeof(conn->client_address)-1);
conn->num_files_open = 0;
conn->lastused = conn->lastused_count = time(NULL);
conn->used = True;
conn->printer = (strncmp(dev,"LPT",3) == 0);
conn->ipc = ( (strncmp(dev,"IPC",3) == 0) ||
( lp_enable_asu_support() && strequal(dev,"ADMIN$")) );
/* Case options for the share. */
if (lp_casesensitive(snum) == Auto) {
/* We will be setting this per packet. Set to be case
* insensitive for now. */
conn->case_sensitive = False;
} else {
conn->case_sensitive = (bool)lp_casesensitive(snum);
}
conn->case_preserve = lp_preservecase(snum);
conn->short_case_preserve = lp_shortpreservecase(snum);
conn->encrypt_level = lp_smb_encrypt(snum);
conn->veto_list = NULL;
conn->hide_list = NULL;
conn->veto_oplock_list = NULL;
conn->aio_write_behind_list = NULL;
conn->read_only = lp_readonly(SNUM(conn));
conn->admin_user = False;
if (*lp_force_user(snum)) {
/*
* Replace conn->server_info with a completely faked up one
* from the username we are forced into :-)
*/
char *fuser;
struct auth_serversupplied_info *forced_serverinfo;
fuser = talloc_string_sub(conn, lp_force_user(snum), "%S",
lp_servicename(snum));
if (fuser == NULL) {
conn_free(conn);
*pstatus = NT_STATUS_NO_MEMORY;
return NULL;
}
status = make_serverinfo_from_username(
conn, fuser, conn->server_info->guest,
&forced_serverinfo);
if (!NT_STATUS_IS_OK(status)) {
conn_free(conn);
*pstatus = status;
return NULL;
}
TALLOC_FREE(conn->server_info);
conn->server_info = forced_serverinfo;
conn->force_user = True;
DEBUG(3,("Forced user %s\n", fuser));
}
/*
* If force group is true, then override
* any groupid stored for the connecting user.
*/
if (*lp_force_group(snum)) {
status = find_forced_group(
conn->force_user, snum, conn->server_info->unix_name,
&conn->server_info->ptok->user_sids[1],
&conn->server_info->utok.gid);
if (!NT_STATUS_IS_OK(status)) {
conn_free(conn);
*pstatus = status;
return NULL;
}
/*
* We need to cache this gid, to use within
* change_to_user() separately from the conn->server_info
* struct. We only use conn->server_info directly if
* "force_user" was set.
*/
conn->force_group_gid = conn->server_info->utok.gid;
}
conn->vuid = (vuser != NULL) ? vuser->vuid : UID_FIELD_INVALID;
{
char *s = talloc_sub_advanced(talloc_tos(),
lp_servicename(SNUM(conn)),
conn->server_info->unix_name,
conn->connectpath,
conn->server_info->utok.gid,
conn->server_info->sanitized_username,
pdb_get_domain(conn->server_info->sam_account),
lp_pathname(snum));
if (!s) {
conn_free(conn);
*pstatus = NT_STATUS_NO_MEMORY;
return NULL;
}
if (!set_conn_connectpath(conn,s)) {
TALLOC_FREE(s);
conn_free(conn);
*pstatus = NT_STATUS_NO_MEMORY;
return NULL;
}
DEBUG(3,("Connect path is '%s' for service [%s]\n",s,
lp_servicename(snum)));
TALLOC_FREE(s);
}
/*
* New code to check if there's a share security descripter
* added from NT server manager. This is done after the
* smb.conf checks are done as we need a uid and token. JRA.
*
*/
{
bool can_write = False;
can_write = share_access_check(conn->server_info->ptok,
lp_servicename(snum),
FILE_WRITE_DATA);
if (!can_write) {
if (!share_access_check(conn->server_info->ptok,
lp_servicename(snum),
FILE_READ_DATA)) {
/* No access, read or write. */
DEBUG(0,("make_connection: connection to %s "
"denied due to security "
"descriptor.\n",
lp_servicename(snum)));
conn_free(conn);
*pstatus = NT_STATUS_ACCESS_DENIED;
return NULL;
} else {
conn->read_only = True;
}
}
}
/* Initialise VFS function pointers */
if (!smbd_vfs_init(conn)) {
DEBUG(0, ("vfs_init failed for service %s\n",
lp_servicename(snum)));
conn_free(conn);
*pstatus = NT_STATUS_BAD_NETWORK_NAME;
return NULL;
}
/*
* If widelinks are disallowed we need to canonicalise the connect
* path here to ensure we don't have any symlinks in the
* connectpath. We will be checking all paths on this connection are
* below this directory. We must do this after the VFS init as we
* depend on the realpath() pointer in the vfs table. JRA.
*/
if (!lp_widelinks(snum)) {
if (!canonicalize_connect_path(conn)) {
DEBUG(0, ("canonicalize_connect_path failed "
"for service %s, path %s\n",
lp_servicename(snum),
conn->connectpath));
conn_free(conn);
*pstatus = NT_STATUS_BAD_NETWORK_NAME;
return NULL;
}
}
if ((!conn->printer) && (!conn->ipc)) {
conn->notify_ctx = notify_init(conn, server_id_self(),
smbd_messaging_context(),
smbd_event_context(),
conn);
}
/* ROOT Activities: */
/*
* Enforce the max connections parameter.
*/
if ((lp_max_connections(snum) > 0)
&& (count_current_connections(lp_servicename(SNUM(conn)), True) >=
lp_max_connections(snum))) {
DEBUG(1, ("Max connections (%d) exceeded for %s\n",
lp_max_connections(snum), lp_servicename(snum)));
conn_free(conn);
*pstatus = NT_STATUS_INSUFFICIENT_RESOURCES;
return NULL;
}
/*
* Get us an entry in the connections db
*/
if (!claim_connection(conn, lp_servicename(snum), 0)) {
DEBUG(1, ("Could not store connections entry\n"));
conn_free(conn);
*pstatus = NT_STATUS_INTERNAL_DB_ERROR;
return NULL;
}
/* Preexecs are done here as they might make the dir we are to ChDir
* to below */
/* execute any "root preexec = " line */
if (*lp_rootpreexec(snum)) {
char *cmd = talloc_sub_advanced(talloc_tos(),
lp_servicename(SNUM(conn)),
conn->server_info->unix_name,
conn->connectpath,
conn->server_info->utok.gid,
conn->server_info->sanitized_username,
pdb_get_domain(conn->server_info->sam_account),
lp_rootpreexec(snum));
DEBUG(5,("cmd=%s\n",cmd));
ret = smbrun(cmd,NULL);
TALLOC_FREE(cmd);
if (ret != 0 && lp_rootpreexec_close(snum)) {
DEBUG(1,("root preexec gave %d - failing "
"connection\n", ret));
yield_connection(conn, lp_servicename(snum));
conn_free(conn);
*pstatus = NT_STATUS_ACCESS_DENIED;
return NULL;
}
}
/* USER Activites: */
if (!change_to_user(conn, conn->vuid)) {
/* No point continuing if they fail the basic checks */
DEBUG(0,("Can't become connected user!\n"));
yield_connection(conn, lp_servicename(snum));
conn_free(conn);
*pstatus = NT_STATUS_LOGON_FAILURE;
return NULL;
}
/* Remember that a different vuid can connect later without these
* checks... */
/* Preexecs are done here as they might make the dir we are to ChDir
* to below */
/* execute any "preexec = " line */
if (*lp_preexec(snum)) {
char *cmd = talloc_sub_advanced(talloc_tos(),
lp_servicename(SNUM(conn)),
conn->server_info->unix_name,
conn->connectpath,
conn->server_info->utok.gid,
conn->server_info->sanitized_username,
pdb_get_domain(conn->server_info->sam_account),
lp_preexec(snum));
ret = smbrun(cmd,NULL);
TALLOC_FREE(cmd);
if (ret != 0 && lp_preexec_close(snum)) {
DEBUG(1,("preexec gave %d - failing connection\n",
ret));
*pstatus = NT_STATUS_ACCESS_DENIED;
goto err_root_exit;
}
}
#ifdef WITH_FAKE_KASERVER
if (lp_afs_share(snum)) {
afs_login(conn);
}
#endif
/* Add veto/hide lists */
if (!IS_IPC(conn) && !IS_PRINT(conn)) {
set_namearray( &conn->veto_list, lp_veto_files(snum));
set_namearray( &conn->hide_list, lp_hide_files(snum));
set_namearray( &conn->veto_oplock_list, lp_veto_oplocks(snum));
set_namearray( &conn->aio_write_behind_list,
lp_aio_write_behind(snum));
}
/* Invoke VFS make connection hook - do this before the VFS_STAT call
to allow any filesystems needing user credentials to initialize
themselves. */
if (SMB_VFS_CONNECT(conn, lp_servicename(snum),
conn->server_info->unix_name) < 0) {
DEBUG(0,("make_connection: VFS make connection failed!\n"));
*pstatus = NT_STATUS_UNSUCCESSFUL;
goto err_root_exit;
}
/* Any error exit after here needs to call the disconnect hook. */
on_err_call_dis_hook = true;
status = create_synthetic_smb_fname(talloc_tos(), conn->connectpath,
NULL, NULL, &smb_fname_cpath);
if (!NT_STATUS_IS_OK(status)) {
*pstatus = status;
goto err_root_exit;
}
/* win2000 does not check the permissions on the directory
during the tree connect, instead relying on permission
check during individual operations. To match this behaviour
I have disabled this chdir check (tridge) */
/* the alternative is just to check the directory exists */
if ((ret = SMB_VFS_STAT(conn, smb_fname_cpath)) != 0 ||
!S_ISDIR(smb_fname_cpath->st.st_ex_mode)) {
if (ret == 0 && !S_ISDIR(smb_fname_cpath->st.st_ex_mode)) {
DEBUG(0,("'%s' is not a directory, when connecting to "
"[%s]\n", conn->connectpath,
lp_servicename(snum)));
} else {
DEBUG(0,("'%s' does not exist or permission denied "
"when connecting to [%s] Error was %s\n",
conn->connectpath, lp_servicename(snum),
strerror(errno) ));
}
*pstatus = NT_STATUS_BAD_NETWORK_NAME;
goto err_root_exit;
}
string_set(&conn->origpath,conn->connectpath);
#if SOFTLINK_OPTIMISATION
/* resolve any soft links early if possible */
if (vfs_ChDir(conn,conn->connectpath) == 0) {
TALLOC_CTX *ctx = talloc_tos();
char *s = vfs_GetWd(ctx,s);
if (!s) {
*status = map_nt_error_from_unix(errno);
goto err_root_exit;
}
if (!set_conn_connectpath(conn,s)) {
*status = NT_STATUS_NO_MEMORY;
goto err_root_exit;
}
vfs_ChDir(conn,conn->connectpath);
}
#endif
/* Figure out the characteristics of the underlying filesystem. This
* assumes that all the filesystem mounted withing a share path have
* the same characteristics, which is likely but not guaranteed.
*/
conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn, &conn->ts_res);
/*
* Print out the 'connected as' stuff here as we need
* to know the effective uid and gid we will be using
* (at least initially).
*/
if( DEBUGLVL( IS_IPC(conn) ? 3 : 1 ) ) {
dbgtext( "%s (%s) ", get_remote_machine_name(),
conn->client_address );
dbgtext( "%s", srv_is_signing_active(smbd_server_conn) ? "signed " : "");
dbgtext( "connect to service %s ", lp_servicename(snum) );
dbgtext( "initially as user %s ",
conn->server_info->unix_name );
dbgtext( "(uid=%d, gid=%d) ", (int)geteuid(), (int)getegid() );
dbgtext( "(pid %d)\n", (int)sys_getpid() );
}
/* we've finished with the user stuff - go back to root */
change_to_root_user();
return(conn);
err_root_exit:
TALLOC_FREE(smb_fname_cpath);
change_to_root_user();
if (on_err_call_dis_hook) {
/* Call VFS disconnect hook */
SMB_VFS_DISCONNECT(conn);
}
yield_connection(conn, lp_servicename(snum));
conn_free(conn);
return NULL;
} | 1 | [
"CWE-22"
] | samba | bd269443e311d96ef495a9db47d1b95eb83bb8f4 | 322,712,926,393,091,500,000,000,000,000,000,000,000 | 437 | Fix bug 7104 - "wide links" and "unix extensions" are incompatible.
Change parameter "wide links" to default to "no".
Ensure "wide links = no" if "unix extensions = yes" on a share.
Fix man pages to refect this.
Remove "within share" checks for a UNIX symlink set - even if
widelinks = no. The server will not follow that link anyway.
Correct DEBUG message in check_reduced_name() to add missing "\n"
so it's really clear when a path is being denied as it's outside
the enclosing share path.
Jeremy. |
NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
{
#ifdef REALPATH_TAKES_NULL
bool free_resolved_name = True;
#else
char resolved_name_buf[PATH_MAX+1];
bool free_resolved_name = False;
#endif
char *resolved_name = NULL;
char *p = NULL;
DEBUG(3,("check_reduced_name [%s] [%s]\n", fname, conn->connectpath));
#ifdef REALPATH_TAKES_NULL
resolved_name = SMB_VFS_REALPATH(conn,fname,NULL);
#else
resolved_name = SMB_VFS_REALPATH(conn,fname,resolved_name_buf);
#endif
if (!resolved_name) {
switch (errno) {
case ENOTDIR:
DEBUG(3,("check_reduced_name: Component not a "
"directory in getting realpath for "
"%s\n", fname));
return NT_STATUS_OBJECT_PATH_NOT_FOUND;
case ENOENT:
{
TALLOC_CTX *ctx = talloc_tos();
char *tmp_fname = NULL;
char *last_component = NULL;
/* Last component didn't exist. Remove it and try and canonicalise the directory. */
tmp_fname = talloc_strdup(ctx, fname);
if (!tmp_fname) {
return NT_STATUS_NO_MEMORY;
}
p = strrchr_m(tmp_fname, '/');
if (p) {
*p++ = '\0';
last_component = p;
} else {
last_component = tmp_fname;
tmp_fname = talloc_strdup(ctx,
".");
if (!tmp_fname) {
return NT_STATUS_NO_MEMORY;
}
}
#ifdef REALPATH_TAKES_NULL
resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,NULL);
#else
resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,resolved_name_buf);
#endif
if (!resolved_name) {
NTSTATUS status = map_nt_error_from_unix(errno);
if (errno == ENOENT || errno == ENOTDIR) {
status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
}
DEBUG(3,("check_reduce_named: "
"couldn't get realpath for "
"%s (%s)\n",
fname,
nt_errstr(status)));
return status;
}
tmp_fname = talloc_asprintf(ctx,
"%s/%s",
resolved_name,
last_component);
if (!tmp_fname) {
return NT_STATUS_NO_MEMORY;
}
#ifdef REALPATH_TAKES_NULL
SAFE_FREE(resolved_name);
resolved_name = SMB_STRDUP(tmp_fname);
if (!resolved_name) {
DEBUG(0, ("check_reduced_name: malloc "
"fail for %s\n", tmp_fname));
return NT_STATUS_NO_MEMORY;
}
#else
safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
resolved_name = resolved_name_buf;
#endif
break;
}
default:
DEBUG(1,("check_reduced_name: couldn't get "
"realpath for %s\n", fname));
return map_nt_error_from_unix(errno);
}
}
DEBUG(10,("check_reduced_name realpath [%s] -> [%s]\n", fname,
resolved_name));
if (*resolved_name != '/') {
DEBUG(0,("check_reduced_name: realpath doesn't return "
"absolute paths !\n"));
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
return NT_STATUS_OBJECT_NAME_INVALID;
}
/* Check for widelinks allowed. */
if (!lp_widelinks(SNUM(conn))) {
const char *conn_rootdir;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
DEBUG(2, ("check_reduced_name: Could not get "
"conn_rootdir\n"));
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
return NT_STATUS_ACCESS_DENIED;
}
if (strncmp(conn_rootdir, resolved_name,
strlen(conn_rootdir)) != 0) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path", fname));
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
return NT_STATUS_ACCESS_DENIED;
}
}
/* Check if we are allowing users to follow symlinks */
/* Patch from David Clerc <David.Clerc@cui.unige.ch>
University of Geneva */
#ifdef S_ISLNK
if (!lp_symlinks(SNUM(conn))) {
struct smb_filename *smb_fname = NULL;
NTSTATUS status;
status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
NULL, &smb_fname);
if (!NT_STATUS_IS_OK(status)) {
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
return status;
}
if ( (SMB_VFS_LSTAT(conn, smb_fname) != -1) &&
(S_ISLNK(smb_fname->st.st_ex_mode)) ) {
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
DEBUG(3,("check_reduced_name: denied: file path name "
"%s is a symlink\n",resolved_name));
TALLOC_FREE(smb_fname);
return NT_STATUS_ACCESS_DENIED;
}
TALLOC_FREE(smb_fname);
}
#endif
DEBUG(3,("check_reduced_name: %s reduced to %s\n", fname,
resolved_name));
if (free_resolved_name) {
SAFE_FREE(resolved_name);
}
return NT_STATUS_OK;
} | 1 | [
"CWE-22"
] | samba | bd269443e311d96ef495a9db47d1b95eb83bb8f4 | 58,312,061,691,157,570,000,000,000,000,000,000,000 | 174 | Fix bug 7104 - "wide links" and "unix extensions" are incompatible.
Change parameter "wide links" to default to "no".
Ensure "wide links = no" if "unix extensions = yes" on a share.
Fix man pages to refect this.
Remove "within share" checks for a UNIX symlink set - even if
widelinks = no. The server will not follow that link anyway.
Correct DEBUG message in check_reduced_name() to add missing "\n"
so it's really clear when a path is being denied as it's outside
the enclosing share path.
Jeremy. |
on_screen_monitors_changed (GdkScreen *screen,
GSManager *manager)
{
GSList *l;
int n_monitors;
int n_windows;
int i;
n_monitors = gdk_screen_get_n_monitors (screen);
n_windows = g_slist_length (manager->priv->windows);
gs_debug ("Monitors changed for screen %d: num=%d",
gdk_screen_get_number (screen),
n_monitors);
if (n_monitors > n_windows) {
/* add more windows */
for (i = n_windows; i < n_monitors; i++) {
gs_manager_create_window_for_monitor (manager, screen, i);
}
} else {
gdk_x11_grab_server ();
/* remove the extra windows */
l = manager->priv->windows;
while (l != NULL) {
GdkScreen *this_screen;
int this_monitor;
GSList *next = l->next;
this_screen = gs_window_get_screen (GS_WINDOW (l->data));
this_monitor = gs_window_get_monitor (GS_WINDOW (l->data));
if (this_screen == screen && this_monitor >= n_monitors) {
manager_maybe_stop_job_for_window (manager, GS_WINDOW (l->data));
g_hash_table_remove (manager->priv->jobs, l->data);
gs_window_destroy (GS_WINDOW (l->data));
manager->priv->windows = g_slist_delete_link (manager->priv->windows, l);
}
l = next;
}
/* make sure there is a lock dialog on a connected monitor,
* and that the keyboard is still properly grabbed after all
* the windows above got destroyed*/
if (n_windows > n_monitors) {
gs_manager_request_unlock (manager);
}
gdk_flush ();
gdk_x11_ungrab_server ();
}
} | 1 | [] | gnome-screensaver | d4dcbd65a2df3c093c4e3a74bbbc75383eb9eadb | 235,433,697,533,199,930,000,000,000,000,000,000,000 | 53 | Update which monitor the unlock dialog is on when layout changes
Before we were moving the grabs but not the unlock dialog.
Everything needs to be in lock step, otherwise:
1) The unlock dialog won't get focus and will fail to work generally
2) Assumptions in the code about the two being in lock-step will
prove incorrect leading to the grabs getting dropped entirely.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789
CVE-2010-0422 |
gs_window_destroy (GSWindow *window)
{
g_return_if_fail (GS_IS_WINDOW (window));
if (window->priv->lock_pid > 0) {
gs_window_dialog_finish (window);
}
remove_popup_dialog_idle (window);
remove_command_watches (window);
remove_watchdog_timer (window);
if (window->priv->lock_box != NULL) {
gtk_container_remove (GTK_CONTAINER (window->priv->vbox), GTK_WIDGET (window->priv->lock_box));
window->priv->lock_box = NULL;
g_signal_emit (window, signals [DIALOG_DOWN], 0);
}
gtk_widget_destroy (GTK_WIDGET (window));
} | 1 | [] | gnome-screensaver | 271ae93d7b140b8ba40d77f9e4ce894e5fd1b554 | 204,978,094,285,079,640,000,000,000,000,000,000,000 | 21 | Make gs_window_cancel_unlock_request synchronous
This way we know the cancel has finished before moving
on in the code.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
gs_window_cancel_unlock_request (GSWindow *window)
{
/* FIXME: This is a bit of a hammer approach...
* Maybe we should send a delete-event to
* the plug?
*/
g_return_if_fail (GS_IS_WINDOW (window));
if (window->priv->lock_socket == NULL) {
return;
}
if (window->priv->lock_pid > 0) {
kill (window->priv->lock_pid, SIGTERM);
}
} | 1 | [] | gnome-screensaver | 271ae93d7b140b8ba40d77f9e4ce894e5fd1b554 | 240,512,421,900,230,300,000,000,000,000,000,000,000 | 16 | Make gs_window_cancel_unlock_request synchronous
This way we know the cancel has finished before moving
on in the code.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
gs_grab_get_mouse (GSGrab *grab,
GdkWindow *window,
GdkScreen *screen,
gboolean hide_cursor)
{
GdkGrabStatus status;
GdkCursor *cursor;
g_return_val_if_fail (window != NULL, FALSE);
g_return_val_if_fail (screen != NULL, FALSE);
cursor = get_cursor ();
gs_debug ("Grabbing mouse widget=%X", (guint32) GDK_WINDOW_XID (window));
status = gdk_pointer_grab (window, TRUE, 0, NULL,
(hide_cursor ? cursor : NULL),
GDK_CURRENT_TIME);
if (status == GDK_GRAB_SUCCESS) {
grab->priv->mouse_grab_window = window;
grab->priv->mouse_grab_screen = screen;
grab->priv->mouse_hide_cursor = hide_cursor;
}
gdk_cursor_unref (cursor);
return status;
} | 1 | [] | gnome-screensaver | f93a22c175090cf02e80bc3ee676b53f1251f685 | 138,739,027,667,141,330,000,000,000,000,000,000,000 | 28 | Nullify grab window variables when windows are destroyed
If we don't do this then there is a time period where the
grab window variables contain dangling pointers which can
cause crashes.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
gs_grab_keyboard_reset (GSGrab *grab)
{
grab->priv->keyboard_grab_window = NULL;
grab->priv->keyboard_grab_screen = NULL;
} | 1 | [] | gnome-screensaver | f93a22c175090cf02e80bc3ee676b53f1251f685 | 157,438,576,911,378,710,000,000,000,000,000,000,000 | 5 | Nullify grab window variables when windows are destroyed
If we don't do this then there is a time period where the
grab window variables contain dangling pointers which can
cause crashes.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
gs_grab_get_keyboard (GSGrab *grab,
GdkWindow *window,
GdkScreen *screen)
{
GdkGrabStatus status;
g_return_val_if_fail (window != NULL, FALSE);
g_return_val_if_fail (screen != NULL, FALSE);
gs_debug ("Grabbing keyboard widget=%X", (guint32) GDK_WINDOW_XID (window));
status = gdk_keyboard_grab (window, FALSE, GDK_CURRENT_TIME);
if (status == GDK_GRAB_SUCCESS) {
grab->priv->keyboard_grab_window = window;
grab->priv->keyboard_grab_screen = screen;
} else {
gs_debug ("Couldn't grab keyboard! (%s)", grab_string (status));
}
return status;
} | 1 | [] | gnome-screensaver | f93a22c175090cf02e80bc3ee676b53f1251f685 | 326,224,807,181,770,500,000,000,000,000,000,000,000 | 21 | Nullify grab window variables when windows are destroyed
If we don't do this then there is a time period where the
grab window variables contain dangling pointers which can
cause crashes.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
gs_grab_mouse_reset (GSGrab *grab)
{
grab->priv->mouse_grab_window = NULL;
grab->priv->mouse_grab_screen = NULL;
} | 1 | [] | gnome-screensaver | f93a22c175090cf02e80bc3ee676b53f1251f685 | 592,836,106,538,194,600,000,000,000,000,000,000 | 5 | Nullify grab window variables when windows are destroyed
If we don't do this then there is a time period where the
grab window variables contain dangling pointers which can
cause crashes.
Part of fix for
https://bugzilla.gnome.org/show_bug.cgi?id=609789 |
listener_ref_entry_has_connection (gpointer key,
gpointer value,
gpointer user_data)
{
GSListenerRefEntry *entry;
const char *connection;
gboolean matches;
entry = (GSListenerRefEntry *)value;
connection = (const char *) user_data;
matches = FALSE;
if (connection != NULL && entry->connection != NULL) {
matches = (strcmp (connection, entry->connection) == 0);
if (matches) {
gs_debug ("removing %s from %s for reason '%s' on connection %s",
get_name_for_entry_type (entry->entry_type),
entry->application,
entry->reason,
entry->connection);
}
}
return matches;
} | 1 | [] | gnome-screensaver | 284c9924969a49dbf2d5fae1d680d3310c4df4a3 | 73,300,824,911,810,030,000,000,000,000,000,000,000 | 25 | Remove session inhibitors if the originator falls of the bus
This fixes a problem where totem leaves inhibitors behind, see
bug 600488. |
listener_ref_entry_remove_for_connection (GSListener *listener,
int entry_type,
const char *connection)
{
gboolean removed;
guint n_removed;
GHashTable *hash;
hash = get_hash_for_entry_type (listener, entry_type);
removed = FALSE;
n_removed = g_hash_table_foreach_remove (hash, listener_ref_entry_has_connection, (gpointer)connection);
removed = (n_removed > 0);
return removed;
} | 1 | [] | gnome-screensaver | 284c9924969a49dbf2d5fae1d680d3310c4df4a3 | 261,259,337,663,707,600,000,000,000,000,000,000,000 | 17 | Remove session inhibitors if the originator falls of the bus
This fixes a problem where totem leaves inhibitors behind, see
bug 600488. |
lock_command_watch (GIOChannel *source,
GIOCondition condition,
GSWindow *window)
{
gboolean finished = FALSE;
g_return_val_if_fail (GS_IS_WINDOW (window), FALSE);
if (condition & G_IO_IN) {
GIOStatus status;
GError *error = NULL;
char *line;
line = NULL;
status = g_io_channel_read_line (source, &line, NULL, NULL, &error);
switch (status) {
case G_IO_STATUS_NORMAL:
gs_debug ("command output: %s", line);
if (strstr (line, "WINDOW ID=") != NULL) {
guint32 id;
char c;
if (1 == sscanf (line, " WINDOW ID= %" G_GUINT32_FORMAT " %c", &id, &c)) {
create_lock_socket (window, id);
}
} else if (strstr (line, "NOTICE=") != NULL) {
if (strstr (line, "NOTICE=AUTH FAILED") != NULL) {
shake_dialog (window);
}
} else if (strstr (line, "RESPONSE=") != NULL) {
if (strstr (line, "RESPONSE=OK") != NULL) {
gs_debug ("Got OK response");
window->priv->dialog_response = DIALOG_RESPONSE_OK;
} else {
gs_debug ("Got CANCEL response");
window->priv->dialog_response = DIALOG_RESPONSE_CANCEL;
}
finished = TRUE;
}
break;
case G_IO_STATUS_EOF:
finished = TRUE;
break;
case G_IO_STATUS_ERROR:
finished = TRUE;
gs_debug ("Error reading from child: %s\n", error->message);
g_error_free (error);
return FALSE;
case G_IO_STATUS_AGAIN:
default:
break;
}
g_free (line);
} else if (condition & G_IO_HUP) {
finished = TRUE;
}
if (finished) {
gs_window_dialog_finish (window);
if (window->priv->dialog_response == DIALOG_RESPONSE_OK) {
add_emit_deactivated_idle (window);
}
gtk_widget_show (window->priv->drawing_area);
gs_window_clear (window);
set_invisible_cursor (GTK_WIDGET (window)->window, TRUE);
g_signal_emit (window, signals [DIALOG_DOWN], 0);
/* reset the pointer positions */
window->priv->last_x = -1;
window->priv->last_y = -1;
window->priv->lock_watch_id = 0;
return FALSE;
}
return TRUE;
} | 1 | [
"CWE-362"
] | gnome-screensaver | ab08cc93f2dc6223c8c00bfa1ca4f2d89069dbe0 | 241,026,682,006,305,570,000,000,000,000,000,000,000 | 83 | Work around x errors by asking dialog to die on cancel
Basically, what is happening is that gnome-screensaver-dialog exits after the
5th failed attempt at unlocking the screen, but before the shake animation
finishes. If the timing is slightly unlucky, this results in gnome-screensaver
accessing X resources that have already been destroyed (I ran it through
xtrace, and that showed this happening)
My patch fixes this by making gnome-screensaver-dialog request to
gnome-screensaver that it be terminated after the 5th failed attempt (rather
than exitting straight away, although there is a fallback timeout too).
gnome-screensaver then terminates the dialog after it is finished with the
shake animation, to avoid the race condition that is currently making it crash. |
popup_dialog_idle (GSWindow *window)
{
gboolean result;
char *tmp;
GString *command;
gs_debug ("Popping up dialog");
tmp = g_build_filename (LIBEXECDIR, "gnome-screensaver-dialog", NULL);
command = g_string_new (tmp);
g_free (tmp);
if (is_logout_enabled (window)) {
command = g_string_append (command, " --enable-logout");
g_string_append_printf (command, " --logout-command='%s'", window->priv->logout_command);
}
if (window->priv->status_message) {
char *quoted;
quoted = g_shell_quote (window->priv->status_message);
g_string_append_printf (command, " --status-message=%s", quoted);
g_free (quoted);
}
if (is_user_switch_enabled (window)) {
command = g_string_append (command, " --enable-switch");
}
if (gs_debug_enabled ()) {
command = g_string_append (command, " --verbose");
}
gtk_widget_hide (window->priv->drawing_area);
gs_window_clear_to_background_pixmap (window);
set_invisible_cursor (GTK_WIDGET (window)->window, FALSE);
result = spawn_on_window (window,
command->str,
&window->priv->lock_pid,
(GIOFunc)lock_command_watch,
window,
&window->priv->lock_watch_id);
if (! result) {
gs_debug ("Could not start command: %s", command->str);
}
g_string_free (command, TRUE);
window->priv->popup_dialog_idle_id = 0;
return FALSE;
} | 1 | [
"CWE-362"
] | gnome-screensaver | ab08cc93f2dc6223c8c00bfa1ca4f2d89069dbe0 | 130,513,780,586,757,320,000,000,000,000,000,000,000 | 55 | Work around x errors by asking dialog to die on cancel
Basically, what is happening is that gnome-screensaver-dialog exits after the
5th failed attempt at unlocking the screen, but before the shake animation
finishes. If the timing is slightly unlucky, this results in gnome-screensaver
accessing X resources that have already been destroyed (I ran it through
xtrace, and that showed this happening)
My patch fixes this by making gnome-screensaver-dialog request to
gnome-screensaver that it be terminated after the 5th failed attempt (rather
than exitting straight away, although there is a fallback timeout too).
gnome-screensaver then terminates the dialog after it is finished with the
shake animation, to avoid the race condition that is currently making it crash. |
shake_dialog (GSWindow *window)
{
int i;
guint left;
guint right;
for (i = 0; i < 9; i++) {
if (i % 2 == 0) {
left = 30;
right = 0;
} else {
left = 0;
right = 30;
}
if (! window->priv->lock_box) {
break;
}
gtk_alignment_set_padding (GTK_ALIGNMENT (window->priv->lock_box),
0, 0,
left,
right);
while (gtk_events_pending ()) {
gtk_main_iteration ();
}
g_usleep (10000);
}
} | 1 | [
"CWE-362"
] | gnome-screensaver | ab08cc93f2dc6223c8c00bfa1ca4f2d89069dbe0 | 249,706,257,296,498,300,000,000,000,000,000,000,000 | 31 | Work around x errors by asking dialog to die on cancel
Basically, what is happening is that gnome-screensaver-dialog exits after the
5th failed attempt at unlocking the screen, but before the shake animation
finishes. If the timing is slightly unlucky, this results in gnome-screensaver
accessing X resources that have already been destroyed (I ran it through
xtrace, and that showed this happening)
My patch fixes this by making gnome-screensaver-dialog request to
gnome-screensaver that it be terminated after the 5th failed attempt (rather
than exitting straight away, although there is a fallback timeout too).
gnome-screensaver then terminates the dialog after it is finished with the
shake animation, to avoid the race condition that is currently making it crash. |
auth_check_idle (GSLockPlug *plug)
{
gboolean res;
gboolean again;
static guint loop_counter = 0;
again = TRUE;
res = do_auth_check (plug);
if (res) {
again = FALSE;
g_idle_add ((GSourceFunc)quit_response_ok, NULL);
} else {
loop_counter++;
if (loop_counter < MAX_FAILURES) {
gs_debug ("Authentication failed, retrying (%u)", loop_counter);
g_timeout_add (3000, (GSourceFunc)reset_idle_cb, plug);
} else {
gs_debug ("Authentication failed, quitting (max failures)");
again = FALSE;
gtk_main_quit ();
}
}
return again;
} | 1 | [
"CWE-362"
] | gnome-screensaver | ab08cc93f2dc6223c8c00bfa1ca4f2d89069dbe0 | 140,846,670,974,514,850,000,000,000,000,000,000,000 | 27 | Work around x errors by asking dialog to die on cancel
Basically, what is happening is that gnome-screensaver-dialog exits after the
5th failed attempt at unlocking the screen, but before the shake animation
finishes. If the timing is slightly unlucky, this results in gnome-screensaver
accessing X resources that have already been destroyed (I ran it through
xtrace, and that showed this happening)
My patch fixes this by making gnome-screensaver-dialog request to
gnome-screensaver that it be terminated after the 5th failed attempt (rather
than exitting straight away, although there is a fallback timeout too).
gnome-screensaver then terminates the dialog after it is finished with the
shake animation, to avoid the race condition that is currently making it crash. |
static int futex_lock_pi(u32 __user *uaddr, int fshared,
int detect, ktime_t *time, int trylock)
{
struct hrtimer_sleeper timeout, *to = NULL;
struct futex_hash_bucket *hb;
struct futex_q q;
int res, ret;
if (refill_pi_state_cache())
return -ENOMEM;
if (time) {
to = &timeout;
hrtimer_init_on_stack(&to->timer, CLOCK_REALTIME,
HRTIMER_MODE_ABS);
hrtimer_init_sleeper(to, current);
hrtimer_set_expires(&to->timer, *time);
}
q.pi_state = NULL;
q.rt_waiter = NULL;
q.requeue_pi_key = NULL;
retry:
q.key = FUTEX_KEY_INIT;
ret = get_futex_key(uaddr, fshared, &q.key);
if (unlikely(ret != 0))
goto out;
retry_private:
hb = queue_lock(&q);
ret = futex_lock_pi_atomic(uaddr, hb, &q.key, &q.pi_state, current, 0);
if (unlikely(ret)) {
switch (ret) {
case 1:
/* We got the lock. */
ret = 0;
goto out_unlock_put_key;
case -EFAULT:
goto uaddr_faulted;
case -EAGAIN:
/*
* Task is exiting and we just wait for the
* exit to complete.
*/
queue_unlock(&q, hb);
put_futex_key(fshared, &q.key);
cond_resched();
goto retry;
default:
goto out_unlock_put_key;
}
}
/*
* Only actually queue now that the atomic ops are done:
*/
queue_me(&q, hb);
WARN_ON(!q.pi_state);
/*
* Block on the PI mutex:
*/
if (!trylock)
ret = rt_mutex_timed_lock(&q.pi_state->pi_mutex, to, 1);
else {
ret = rt_mutex_trylock(&q.pi_state->pi_mutex);
/* Fixup the trylock return value: */
ret = ret ? 0 : -EWOULDBLOCK;
}
spin_lock(q.lock_ptr);
/*
* Fixup the pi_state owner and possibly acquire the lock if we
* haven't already.
*/
res = fixup_owner(uaddr, fshared, &q, !ret);
/*
* If fixup_owner() returned an error, proprogate that. If it acquired
* the lock, clear our -ETIMEDOUT or -EINTR.
*/
if (res)
ret = (res < 0) ? res : 0;
/*
* If fixup_owner() faulted and was unable to handle the fault, unlock
* it and return the fault to userspace.
*/
if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current))
rt_mutex_unlock(&q.pi_state->pi_mutex);
/* Unqueue and drop the lock */
unqueue_me_pi(&q);
goto out;
out_unlock_put_key:
queue_unlock(&q, hb);
out_put_key:
put_futex_key(fshared, &q.key);
out:
if (to)
destroy_hrtimer_on_stack(&to->timer);
return ret != -EINTR ? ret : -ERESTARTNOINTR;
uaddr_faulted:
queue_unlock(&q, hb);
ret = fault_in_user_writeable(uaddr);
if (ret)
goto out_put_key;
if (!fshared)
goto retry_private;
put_futex_key(fshared, &q.key);
goto retry;
} | 1 | [] | linux-2.6 | 5ecb01cfdf96c5f465192bdb2a4fd4a61a24c6cc | 229,495,631,557,006,200,000,000,000,000,000,000,000 | 119 | futex_lock_pi() key refcnt fix
This fixes a futex key reference count bug in futex_lock_pi(),
where a key's reference count is incremented twice but decremented
only once, causing the backing object to not be released.
If the futex is created in a temporary file in an ext3 file system,
this bug causes the file's inode to become an "undead" orphan,
which causes an oops from a BUG_ON() in ext3_put_super() when the
file system is unmounted. glibc's test suite is known to trigger this,
see <http://bugzilla.kernel.org/show_bug.cgi?id=14256>.
The bug is a regression from 2.6.28-git3, namely Peter Zijlstra's
38d47c1b7075bd7ec3881141bb3629da58f88dab "[PATCH] futex: rely on
get_user_pages() for shared futexes". That commit made get_futex_key()
also increment the reference count of the futex key, and updated its
callers to decrement the key's reference count before returning.
Unfortunately the normal exit path in futex_lock_pi() wasn't corrected:
the reference count is incremented by get_futex_key() and queue_lock(),
but the normal exit path only decrements once, via unqueue_me_pi().
The fix is to put_futex_key() after unqueue_me_pi(), since 2.6.31
this is easily done by 'goto out_put_key' rather than 'goto out'.
Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Darren Hart <dvhltc@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: <stable@kernel.org> |
static int encode_to_private_key_info(gnutls_x509_privkey_t pkey,
gnutls_datum_t * der,
ASN1_TYPE * pkey_info)
{
int result;
size_t size;
opaque *data = NULL;
opaque null = 0;
if (pkey->pk_algorithm != GNUTLS_PK_RSA) {
gnutls_assert();
return GNUTLS_E_UNIMPLEMENTED_FEATURE;
}
if ((result =
asn1_create_element(_gnutls_get_pkix(),
"PKIX1.pkcs-8-PrivateKeyInfo",
pkey_info)) != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* Write the version.
*/
result = asn1_write_value(*pkey_info, "version", &null, 1);
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* write the privateKeyAlgorithm
* fields. (OID+NULL data)
*/
result =
asn1_write_value(*pkey_info, "privateKeyAlgorithm.algorithm",
PKIX1_RSA_OID, 1);
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
result =
asn1_write_value(*pkey_info, "privateKeyAlgorithm.parameters",
NULL, 0);
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* Write the raw private key
*/
size = 0;
result =
gnutls_x509_privkey_export(pkey, GNUTLS_X509_FMT_DER, NULL, &size);
if (result != GNUTLS_E_SHORT_MEMORY_BUFFER) {
gnutls_assert();
goto error;
}
data = gnutls_alloca(size);
if (data == NULL) {
gnutls_assert();
result = GNUTLS_E_MEMORY_ERROR;
goto error;
}
result =
gnutls_x509_privkey_export(pkey, GNUTLS_X509_FMT_DER, data, &size);
if (result < 0) {
gnutls_assert();
goto error;
}
result = asn1_write_value(*pkey_info, "privateKey", data, size);
gnutls_afree(data);
data = NULL;
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* Append an empty Attributes field.
*/
result = asn1_write_value(*pkey_info, "attributes", NULL, 0);
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* DER Encode the generated private key info.
*/
size = 0;
result = asn1_der_coding(*pkey_info, "", NULL, &size, NULL);
if (result != ASN1_MEM_ERROR) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
/* allocate data for the der
*/
der->size = size;
der->data = gnutls_malloc(size);
if (der->data == NULL) {
gnutls_assert();
return GNUTLS_E_MEMORY_ERROR;
}
result = asn1_der_coding(*pkey_info, "", der->data, &size, NULL);
if (result != ASN1_SUCCESS) {
gnutls_assert();
result = _gnutls_asn2err(result);
goto error;
}
return 0;
error:
asn1_delete_structure(pkey_info);
if (data != NULL) {
gnutls_afree(data);
}
return result;
} | 1 | [] | gnutls | 112d537da5f3500f14316db26d18c37d678a5e0e | 147,219,100,289,513,080,000,000,000,000,000,000,000 | 134 | some changes for 64bit machines. |
int gnutls_x509_crt_get_serial(gnutls_x509_crt_t cert, void *result,
size_t * result_size)
{
int ret;
if (cert == NULL) {
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
}
if ((ret =
asn1_read_value(cert->cert, "tbsCertificate.serialNumber", result,
result_size)) < 0) {
gnutls_assert();
return _gnutls_asn2err(ret);
}
return 0;
} | 1 | [] | gnutls | 112d537da5f3500f14316db26d18c37d678a5e0e | 196,126,434,502,391,000,000,000,000,000,000,000,000 | 19 | some changes for 64bit machines. |
_gnutls_asn1_get_structure_xml(ASN1_TYPE structure,
gnutls_datum_t * res, int detail)
{
node_asn *p, *root;
int k, indent = 0, len, len2, len3;
opaque tmp[1024];
char nname[256];
int ret;
gnutls_string str;
if (res == NULL || structure == NULL) {
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
}
_gnutls_string_init(&str, malloc, realloc, free);
STR_APPEND(XML_HEADER);
indent = 1;
root = _asn1_find_node(structure, "");
if (root == NULL) {
gnutls_assert();
_gnutls_string_clear(&str);
return GNUTLS_E_INTERNAL_ERROR;
}
if (detail == GNUTLS_XML_SHOW_ALL)
ret = asn1_expand_any_defined_by(_gnutls_get_pkix(), &structure);
/* we don't need to check the error value
* here.
*/
if (detail == GNUTLS_XML_SHOW_ALL) {
ret = _gnutls_x509_expand_extensions(&structure);
if (ret < 0) {
gnutls_assert();
return ret;
}
}
p = root;
while (p) {
if (is_node_printable(p)) {
for (k = 0; k < indent; k++)
APPEND(" ", 1);
if ((ret = normalize_name(p, nname, sizeof(nname))) < 0) {
_gnutls_string_clear(&str);
gnutls_assert();
return ret;
}
APPEND("<", 1);
STR_APPEND(nname);
}
if (is_node_printable(p)) {
switch (type_field(p->type)) {
case TYPE_DEFAULT:
STR_APPEND(" type=\"DEFAULT\"");
break;
case TYPE_NULL:
STR_APPEND(" type=\"NULL\"");
break;
case TYPE_IDENTIFIER:
STR_APPEND(" type=\"IDENTIFIER\"");
break;
case TYPE_INTEGER:
STR_APPEND(" type=\"INTEGER\"");
STR_APPEND(" encoding=\"HEX\"");
break;
case TYPE_ENUMERATED:
STR_APPEND(" type=\"ENUMERATED\"");
STR_APPEND(" encoding=\"HEX\"");
break;
case TYPE_TIME:
STR_APPEND(" type=\"TIME\"");
break;
case TYPE_BOOLEAN:
STR_APPEND(" type=\"BOOLEAN\"");
break;
case TYPE_SEQUENCE:
STR_APPEND(" type=\"SEQUENCE\"");
break;
case TYPE_BIT_STRING:
STR_APPEND(" type=\"BIT STRING\"");
STR_APPEND(" encoding=\"HEX\"");
break;
case TYPE_OCTET_STRING:
STR_APPEND(" type=\"OCTET STRING\"");
STR_APPEND(" encoding=\"HEX\"");
break;
case TYPE_SEQUENCE_OF:
STR_APPEND(" type=\"SEQUENCE OF\"");
break;
case TYPE_OBJECT_ID:
STR_APPEND(" type=\"OBJECT ID\"");
break;
case TYPE_ANY:
STR_APPEND(" type=\"ANY\"");
if (!p->down)
STR_APPEND(" encoding=\"HEX\"");
break;
case TYPE_CONSTANT:{
ASN1_TYPE up = _asn1_find_up(p);
if (up && type_field(up->type) == TYPE_ANY &&
up->left && up->left->value &&
up->type & CONST_DEFINED_BY &&
type_field(up->left->type) == TYPE_OBJECT_ID) {
if (_gnutls_x509_oid_data_printable
(up->left->value) == 0) {
STR_APPEND(" encoding=\"HEX\"");
}
}
}
break;
case TYPE_SET:
STR_APPEND(" type=\"SET\"");
break;
case TYPE_SET_OF:
STR_APPEND(" type=\"SET OF\"");
break;
case TYPE_CHOICE:
STR_APPEND(" type=\"CHOICE\"");
break;
case TYPE_DEFINITIONS:
STR_APPEND(" type=\"DEFINITIONS\"");
break;
default:
break;
}
}
if (p->type == TYPE_BIT_STRING) {
len2 = -1;
len = _asn1_get_length_der(p->value, &len2);
snprintf(tmp, sizeof(tmp), " length=\"%i\"",
(len - 1) * 8 - (p->value[len2]));
STR_APPEND(tmp);
}
if (is_node_printable(p))
STR_APPEND(">");
if (is_node_printable(p)) {
const unsigned char *value;
if (p->value == NULL)
value = find_default_value(p);
else
value = p->value;
switch (type_field(p->type)) {
case TYPE_DEFAULT:
if (value)
STR_APPEND(value);
break;
case TYPE_IDENTIFIER:
if (value)
STR_APPEND(value);
break;
case TYPE_INTEGER:
if (value) {
len2 = -1;
len = _asn1_get_length_der(value, &len2);
for (k = 0; k < len; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (value)[k + len2]);
STR_APPEND(tmp);
}
}
break;
case TYPE_ENUMERATED:
if (value) {
len2 = -1;
len = _asn1_get_length_der(value, &len2);
for (k = 0; k < len; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (value)[k + len2]);
STR_APPEND(tmp);
}
}
break;
case TYPE_TIME:
if (value)
STR_APPEND(value);
break;
case TYPE_BOOLEAN:
if (value) {
if (value[0] == 'T') {
STR_APPEND("TRUE");
} else if (value[0] == 'F') {
STR_APPEND("FALSE");
}
}
break;
case TYPE_BIT_STRING:
if (value) {
len2 = -1;
len = _asn1_get_length_der(value, &len2);
for (k = 1; k < len; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (value)[k + len2]);
STR_APPEND(tmp);
}
}
break;
case TYPE_OCTET_STRING:
if (value) {
len2 = -1;
len = _asn1_get_length_der(value, &len2);
for (k = 0; k < len; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (value)[k + len2]);
STR_APPEND(tmp);
}
}
break;
case TYPE_OBJECT_ID:
if (value)
STR_APPEND(value);
break;
case TYPE_ANY:
if (!p->down) {
if (value) {
len3 = -1;
len2 = _asn1_get_length_der(value, &len3);
for (k = 0; k < len2; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (value)[k + len3]);
STR_APPEND(tmp);
}
}
}
break;
case TYPE_CONSTANT:{
ASN1_TYPE up = _asn1_find_up(p);
if (up && type_field(up->type) == TYPE_ANY &&
up->left && up->left->value &&
up->type & CONST_DEFINED_BY &&
type_field(up->left->type) == TYPE_OBJECT_ID) {
len2 = _asn1_get_length_der(up->value, &len3);
if (len2 > 0 && strcmp(p->name, "type") == 0) {
int len = sizeof(tmp);
ret =
_gnutls_x509_oid_data2string(up->left->
value,
up->value +
len3, len2,
tmp, &len);
if (ret >= 0) {
STR_APPEND(tmp);
}
} else {
for (k = 0; k < len2; k++) {
snprintf(tmp, sizeof(tmp),
"%02X", (up->value)[k + len3]);
STR_APPEND(tmp);
}
}
} else {
if (value)
STR_APPEND(value);
}
}
break;
case TYPE_SET:
case TYPE_SET_OF:
case TYPE_CHOICE:
case TYPE_DEFINITIONS:
case TYPE_SEQUENCE_OF:
case TYPE_SEQUENCE:
case TYPE_NULL:
break;
default:
break;
}
}
if (p->down && is_node_printable(p)) {
ASN1_TYPE x;
p = p->down;
indent += 2;
x = p;
do {
if (is_node_printable(x)) {
STR_APPEND("\n");
break;
}
x = x->right;
} while (x != NULL);
} else if (p == root) {
if (is_node_printable(p)) {
if ((ret = normalize_name(p, nname, sizeof(nname))) < 0) {
_gnutls_string_clear(&str);
gnutls_assert();
return ret;
}
APPEND("</", 2);
STR_APPEND(nname);
APPEND(">\n", 2);
}
p = NULL;
break;
} else {
if (is_node_printable(p)) {
if ((ret = normalize_name(p, nname, sizeof(nname))) < 0) {
_gnutls_string_clear(&str);
gnutls_assert();
return ret;
}
APPEND("</", 2);
STR_APPEND(nname);
APPEND(">\n", 2);
}
if (p->right)
p = p->right;
else {
while (1) {
ASN1_TYPE old_p;
old_p = p;
p = _asn1_find_up(p);
indent -= 2;
if (is_node_printable(p)) {
if (!is_leaf(p)) /* XXX */
for (k = 0; k < indent; k++)
STR_APPEND(" ");
if ((ret =
normalize_name(p, nname,
sizeof(nname))) < 0) {
_gnutls_string_clear(&str);
gnutls_assert();
return ret;
}
APPEND("</", 2);
STR_APPEND(nname);
APPEND(">\n", 2);
}
if (p == root) {
p = NULL;
break;
}
if (p->right) {
p = p->right;
break;
}
}
}
}
}
STR_APPEND(XML_FOOTER);
APPEND("\n\0", 2);
*res = _gnutls_string2datum(&str);
res->size -= 1; /* null is not included in size */
return 0;
} | 1 | [] | gnutls | 112d537da5f3500f14316db26d18c37d678a5e0e | 186,047,149,305,633,670,000,000,000,000,000,000,000 | 383 | some changes for 64bit machines. |
int mszip_decompress(struct mszip_stream *zip, off_t out_bytes) {
/* for the bit buffer */
register unsigned int bit_buffer;
register int bits_left;
unsigned char *i_ptr, *i_end;
int i, ret, state, error;
/* easy answers */
if (!zip || (out_bytes < 0)) return CL_ENULLARG;
if (zip->error) return zip->error;
/* flush out any stored-up bytes before we begin */
i = zip->o_end - zip->o_ptr;
if ((off_t) i > out_bytes) i = (int) out_bytes;
if (i) {
if (zip->wflag && (ret = mspack_write(zip->ofd, zip->o_ptr, i, zip->file)) != CL_SUCCESS) {
return zip->error = ret;
}
zip->o_ptr += i;
out_bytes -= i;
}
if (out_bytes == 0) return CL_SUCCESS;
while (out_bytes > 0) {
/* unpack another block */
MSZIP_RESTORE_BITS;
/* skip to next read 'CK' header */
i = bits_left & 7; MSZIP_REMOVE_BITS(i); /* align to bytestream */
state = 0;
do {
MSZIP_READ_BITS(i, 8);
if (i == 'C') state = 1;
else if ((state == 1) && (i == 'K')) state = 2;
else state = 0;
} while (state != 2);
/* inflate a block, repair and realign if necessary */
zip->window_posn = 0;
zip->bytes_output = 0;
MSZIP_STORE_BITS;
if ((error = mszip_inflate(zip))) {
cli_dbgmsg("mszip_decompress: inflate error %d\n", error);
if (zip->repair_mode) {
cli_dbgmsg("mszip_decompress: MSZIP error, %u bytes of data lost\n",
MSZIP_FRAME_SIZE - zip->bytes_output);
for (i = zip->bytes_output; i < MSZIP_FRAME_SIZE; i++) {
zip->window[i] = '\0';
}
zip->bytes_output = MSZIP_FRAME_SIZE;
}
else {
return zip->error = (error > 0) ? error : CL_EFORMAT;
}
}
zip->o_ptr = &zip->window[0];
zip->o_end = &zip->o_ptr[zip->bytes_output];
/* write a frame */
i = (out_bytes < (off_t)zip->bytes_output) ?
(int)out_bytes : zip->bytes_output;
if (zip->wflag && (ret = mspack_write(zip->ofd, zip->o_ptr, i, zip->file)) != CL_SUCCESS) {
return zip->error = ret;
}
/* mspack errors (i.e. read errors) are fatal and can't be recovered */
if ((error > 0) && zip->repair_mode) return error;
zip->o_ptr += i;
out_bytes -= i;
}
if (out_bytes) {
cli_dbgmsg("mszip_decompress: bytes left to output\n");
return zip->error = CL_EFORMAT;
}
return CL_SUCCESS;
} | 1 | [] | clamav-devel | 158c35e81a25ea5fda55a2a7f62ea9fec2e883d9 | 286,001,574,084,344,600,000,000,000,000,000,000,000 | 79 | libclamav/mspack.c: improve unpacking of malformed cabinets (bb#1826) |
int lzx_decompress(struct lzx_stream *lzx, off_t out_bytes) {
/* bitstream reading and huffman variables */
register unsigned int bit_buffer;
register int bits_left, i=0;
register unsigned short sym;
unsigned char *i_ptr, *i_end;
int match_length, length_footer, extra, verbatim_bits, bytes_todo;
int this_run, main_element, aligned_bits, j, ret;
unsigned char *window, *runsrc, *rundest, buf[12];
unsigned int frame_size=0, end_frame, match_offset, window_posn;
unsigned int R0, R1, R2;
/* easy answers */
if (!lzx || (out_bytes < 0)) return CL_ENULLARG;
if (lzx->error) return lzx->error;
/* flush out any stored-up bytes before we begin */
i = lzx->o_end - lzx->o_ptr;
if ((off_t) i > out_bytes) i = (int) out_bytes;
if (i) {
if (lzx->wflag && (ret = mspack_write(lzx->ofd, lzx->o_ptr, i, lzx->file)) != CL_SUCCESS) {
return lzx->error = ret;
}
lzx->o_ptr += i;
lzx->offset += i;
out_bytes -= i;
}
if (out_bytes == 0) return CL_SUCCESS;
/* restore local state */
LZX_RESTORE_BITS;
window = lzx->window;
window_posn = lzx->window_posn;
R0 = lzx->R0;
R1 = lzx->R1;
R2 = lzx->R2;
end_frame = (unsigned int)((lzx->offset + out_bytes) / LZX_FRAME_SIZE) + 1;
while (lzx->frame < end_frame) {
/* have we reached the reset interval? (if there is one?) */
if (lzx->reset_interval && ((lzx->frame % lzx->reset_interval) == 0)) {
if (lzx->block_remaining) {
cli_dbgmsg("lzx_decompress: %d bytes remaining at reset interval\n", lzx->block_remaining);
return lzx->error = CL_EFORMAT;
}
/* re-read the intel header and reset the huffman lengths */
lzx_reset_state(lzx);
}
/* read header if necessary */
if (!lzx->header_read) {
/* read 1 bit. if bit=0, intel filesize = 0.
* if bit=1, read intel filesize (32 bits) */
j = 0; LZX_READ_BITS(i, 1); if (i) { LZX_READ_BITS(i, 16); LZX_READ_BITS(j, 16); }
lzx->intel_filesize = (i << 16) | j;
lzx->header_read = 1;
}
/* calculate size of frame: all frames are 32k except the final frame
* which is 32kb or less. this can only be calculated when lzx->length
* has been filled in. */
frame_size = LZX_FRAME_SIZE;
if (lzx->length && (lzx->length - lzx->offset) < (off_t)frame_size) {
frame_size = lzx->length - lzx->offset;
}
/* decode until one more frame is available */
bytes_todo = lzx->frame_posn + frame_size - window_posn;
while (bytes_todo > 0) {
/* initialise new block, if one is needed */
if (lzx->block_remaining == 0) {
/* realign if previous block was an odd-sized UNCOMPRESSED block */
if ((lzx->block_type == LZX_BLOCKTYPE_UNCOMPRESSED) &&
(lzx->block_length & 1))
{
if (i_ptr == i_end) {
if (lzx_read_input(lzx)) return lzx->error;
i_ptr = lzx->i_ptr;
i_end = lzx->i_end;
}
i_ptr++;
}
/* read block type (3 bits) and block length (24 bits) */
LZX_READ_BITS(lzx->block_type, 3);
LZX_READ_BITS(i, 16); LZX_READ_BITS(j, 8);
lzx->block_remaining = lzx->block_length = (i << 8) | j;
/* read individual block headers */
switch (lzx->block_type) {
case LZX_BLOCKTYPE_ALIGNED:
/* read lengths of and build aligned huffman decoding tree */
for (i = 0; i < 8; i++) { LZX_READ_BITS(j, 3); lzx->ALIGNED_len[i] = j; }
LZX_BUILD_TABLE(ALIGNED);
/* no break -- rest of aligned header is same as verbatim */
case LZX_BLOCKTYPE_VERBATIM:
/* read lengths of and build main huffman decoding tree */
LZX_READ_LENGTHS(MAINTREE, 0, 256);
LZX_READ_LENGTHS(MAINTREE, 256, LZX_NUM_CHARS + (lzx->posn_slots << 3));
LZX_BUILD_TABLE(MAINTREE);
/* if the literal 0xE8 is anywhere in the block... */
if (lzx->MAINTREE_len[0xE8] != 0) lzx->intel_started = 1;
/* read lengths of and build lengths huffman decoding tree */
LZX_READ_LENGTHS(LENGTH, 0, LZX_NUM_SECONDARY_LENGTHS);
LZX_BUILD_TABLE(LENGTH);
break;
case LZX_BLOCKTYPE_UNCOMPRESSED:
/* because we can't assume otherwise */
lzx->intel_started = 1;
/* read 1-16 (not 0-15) bits to align to bytes */
LZX_ENSURE_BITS(16);
if (bits_left > 16) i_ptr -= 2;
bits_left = 0; bit_buffer = 0;
/* read 12 bytes of stored R0 / R1 / R2 values */
for (rundest = &buf[0], i = 0; i < 12; i++) {
if (i_ptr == i_end) {
if (lzx_read_input(lzx)) return lzx->error;
i_ptr = lzx->i_ptr;
i_end = lzx->i_end;
}
*rundest++ = *i_ptr++;
}
R0 = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
R1 = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
R2 = buf[8] | (buf[9] << 8) | (buf[10] << 16) | (buf[11] << 24);
break;
default:
cli_dbgmsg("lzx_decompress: bad block type (0x%x)\n", lzx->block_type);
return lzx->error = CL_EFORMAT;
}
}
/* decode more of the block:
* run = min(what's available, what's needed) */
this_run = lzx->block_remaining;
if (this_run > bytes_todo) this_run = bytes_todo;
/* assume we decode exactly this_run bytes, for now */
bytes_todo -= this_run;
lzx->block_remaining -= this_run;
/* decode at least this_run bytes */
switch (lzx->block_type) {
case LZX_BLOCKTYPE_VERBATIM:
while (this_run > 0) {
LZX_READ_HUFFSYM(MAINTREE, main_element);
if (main_element < LZX_NUM_CHARS) {
/* literal: 0 to LZX_NUM_CHARS-1 */
window[window_posn++] = main_element;
this_run--;
}
else {
/* match: LZX_NUM_CHARS + ((slot<<3) | length_header (3 bits)) */
main_element -= LZX_NUM_CHARS;
/* get match length */
match_length = main_element & LZX_NUM_PRIMARY_LENGTHS;
if (match_length == LZX_NUM_PRIMARY_LENGTHS) {
LZX_READ_HUFFSYM(LENGTH, length_footer);
match_length += length_footer;
}
match_length += LZX_MIN_MATCH;
/* get match offset */
switch ((match_offset = (main_element >> 3))) {
case 0: match_offset = R0; break;
case 1: match_offset = R1; R1=R0; R0 = match_offset; break;
case 2: match_offset = R2; R2=R0; R0 = match_offset; break;
case 3: match_offset = 1; R2=R1; R1=R0; R0 = match_offset; break;
default:
extra = lzx->extra_bits[match_offset];
LZX_READ_BITS(verbatim_bits, extra);
match_offset = lzx->position_base[match_offset] - 2 + verbatim_bits;
R2 = R1; R1 = R0; R0 = match_offset;
}
if ((window_posn + match_length) > lzx->window_size) {
cli_dbgmsg("lzx_decompress: match ran over window wrap\n");
return lzx->error = CL_EFORMAT;
}
/* copy match */
rundest = &window[window_posn];
i = match_length;
/* does match offset wrap the window? */
if (match_offset > window_posn) {
/* j = length from match offset to end of window */
j = match_offset - window_posn;
if (j > (int) lzx->window_size) {
cli_dbgmsg("lzx_decompress: match offset beyond window boundaries\n");
return lzx->error = CL_EFORMAT;
}
runsrc = &window[lzx->window_size - j];
if (j < i) {
/* if match goes over the window edge, do two copy runs */
i -= j; while (j-- > 0) *rundest++ = *runsrc++;
runsrc = window;
}
while (i-- > 0) *rundest++ = *runsrc++;
}
else {
runsrc = rundest - match_offset;
if(i > (int) (lzx->window_size - window_posn))
i = lzx->window_size - window_posn;
while (i-- > 0) *rundest++ = *runsrc++;
}
this_run -= match_length;
window_posn += match_length;
}
} /* while (this_run > 0) */
break;
case LZX_BLOCKTYPE_ALIGNED:
while (this_run > 0) {
LZX_READ_HUFFSYM(MAINTREE, main_element);
if (main_element < LZX_NUM_CHARS) {
/* literal: 0 to LZX_NUM_CHARS-1 */
window[window_posn++] = main_element;
this_run--;
}
else {
/* match: LZX_NUM_CHARS + ((slot<<3) | length_header (3 bits)) */
main_element -= LZX_NUM_CHARS;
/* get match length */
match_length = main_element & LZX_NUM_PRIMARY_LENGTHS;
if (match_length == LZX_NUM_PRIMARY_LENGTHS) {
LZX_READ_HUFFSYM(LENGTH, length_footer);
match_length += length_footer;
}
match_length += LZX_MIN_MATCH;
/* get match offset */
switch ((match_offset = (main_element >> 3))) {
case 0: match_offset = R0; break;
case 1: match_offset = R1; R1 = R0; R0 = match_offset; break;
case 2: match_offset = R2; R2 = R0; R0 = match_offset; break;
default:
extra = lzx->extra_bits[match_offset];
match_offset = lzx->position_base[match_offset] - 2;
if (extra > 3) {
/* verbatim and aligned bits */
extra -= 3;
LZX_READ_BITS(verbatim_bits, extra);
match_offset += (verbatim_bits << 3);
LZX_READ_HUFFSYM(ALIGNED, aligned_bits);
match_offset += aligned_bits;
}
else if (extra == 3) {
/* aligned bits only */
LZX_READ_HUFFSYM(ALIGNED, aligned_bits);
match_offset += aligned_bits;
}
else if (extra > 0) { /* extra==1, extra==2 */
/* verbatim bits only */
LZX_READ_BITS(verbatim_bits, extra);
match_offset += verbatim_bits;
}
else /* extra == 0 */ {
/* ??? not defined in LZX specification! */
match_offset = 1;
}
/* update repeated offset LRU queue */
R2 = R1; R1 = R0; R0 = match_offset;
}
if ((window_posn + match_length) > lzx->window_size) {
cli_dbgmsg("lzx_decompress: match ran over window wrap\n");
return lzx->error = CL_EFORMAT;
}
/* copy match */
rundest = &window[window_posn];
i = match_length;
/* does match offset wrap the window? */
if (match_offset > window_posn) {
/* j = length from match offset to end of window */
j = match_offset - window_posn;
if (j > (int) lzx->window_size) {
cli_dbgmsg("lzx_decompress: match offset beyond window boundaries\n");
return lzx->error = CL_EFORMAT;
}
runsrc = &window[lzx->window_size - j];
if (j < i) {
/* if match goes over the window edge, do two copy runs */
i -= j; while (j-- > 0) *rundest++ = *runsrc++;
runsrc = window;
}
while (i-- > 0) *rundest++ = *runsrc++;
}
else {
runsrc = rundest - match_offset;
while (i-- > 0) *rundest++ = *runsrc++;
}
this_run -= match_length;
window_posn += match_length;
}
} /* while (this_run > 0) */
break;
case LZX_BLOCKTYPE_UNCOMPRESSED:
/* as this_run is limited not to wrap a frame, this also means it
* won't wrap the window (as the window is a multiple of 32k) */
rundest = &window[window_posn];
window_posn += this_run;
while (this_run > 0) {
if ((i = i_end - i_ptr)) {
if (i > this_run) i = this_run;
memcpy(rundest, i_ptr, (size_t) i);
rundest += i;
i_ptr += i;
this_run -= i;
}
else {
if (lzx_read_input(lzx)) return lzx->error;
i_ptr = lzx->i_ptr;
i_end = lzx->i_end;
}
}
break;
default:
return lzx->error = CL_EFORMAT; /* might as well */
}
/* did the final match overrun our desired this_run length? */
if (this_run < 0) {
if ((unsigned int)(-this_run) > lzx->block_remaining) {
cli_dbgmsg("lzx_decompress: overrun went past end of block by %d (%d remaining)\n", -this_run, lzx->block_remaining);
return lzx->error = CL_EFORMAT;
}
lzx->block_remaining -= -this_run;
}
} /* while (bytes_todo > 0) */
/* streams don't extend over frame boundaries */
if ((window_posn - lzx->frame_posn) != frame_size) {
cli_dbgmsg("lzx_decompress: decode beyond output frame limits! %d != %d\n", window_posn - lzx->frame_posn, frame_size);
return lzx->error = CL_EFORMAT;
}
/* re-align input bitstream */
if (bits_left > 0) LZX_ENSURE_BITS(16);
if (bits_left & 15) LZX_REMOVE_BITS(bits_left & 15);
/* check that we've used all of the previous frame first */
if (lzx->o_ptr != lzx->o_end) {
cli_dbgmsg("lzx_decompress: %ld avail bytes, new %d frame\n", lzx->o_end-lzx->o_ptr, frame_size);
return lzx->error = CL_EFORMAT;
}
/* does this intel block _really_ need decoding? */
if (lzx->intel_started && lzx->intel_filesize &&
(lzx->frame <= 32768) && (frame_size > 10))
{
unsigned char *data = &lzx->e8_buf[0];
unsigned char *dataend = &lzx->e8_buf[frame_size - 10];
signed int curpos = lzx->intel_curpos;
signed int filesize = lzx->intel_filesize;
signed int abs_off, rel_off;
/* copy e8 block to the e8 buffer and tweak if needed */
lzx->o_ptr = data;
memcpy(data, &lzx->window[lzx->frame_posn], frame_size);
while (data < dataend) {
if (*data++ != 0xE8) { curpos++; continue; }
abs_off = data[0] | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
if ((abs_off >= -curpos) && (abs_off < filesize)) {
rel_off = (abs_off >= 0) ? abs_off - curpos : abs_off + filesize;
data[0] = (unsigned char) rel_off;
data[1] = (unsigned char) (rel_off >> 8);
data[2] = (unsigned char) (rel_off >> 16);
data[3] = (unsigned char) (rel_off >> 24);
}
data += 4;
curpos += 5;
}
lzx->intel_curpos += frame_size;
}
else {
lzx->o_ptr = &lzx->window[lzx->frame_posn];
if (lzx->intel_filesize) lzx->intel_curpos += frame_size;
}
lzx->o_end = &lzx->o_ptr[frame_size];
/* write a frame */
i = (out_bytes < (off_t)frame_size) ? (unsigned int)out_bytes : frame_size;
if (lzx->wflag && (ret = mspack_write(lzx->ofd, lzx->o_ptr, i, lzx->file)) != CL_SUCCESS) {
return lzx->error = ret;
}
lzx->o_ptr += i;
lzx->offset += i;
out_bytes -= i;
/* advance frame start position */
lzx->frame_posn += frame_size;
lzx->frame++;
/* wrap window / frame position pointers */
if (window_posn == lzx->window_size) window_posn = 0;
if (lzx->frame_posn == lzx->window_size) lzx->frame_posn = 0;
} /* while (lzx->frame < end_frame) */
if (out_bytes) {
cli_dbgmsg("lzx_decompress: bytes left to output\n");
return lzx->error = CL_EFORMAT;
}
/* store local state */
LZX_STORE_BITS;
lzx->window_posn = window_posn;
lzx->R0 = R0;
lzx->R1 = R1;
lzx->R2 = R2;
return CL_SUCCESS;
} | 1 | [] | clamav-devel | 158c35e81a25ea5fda55a2a7f62ea9fec2e883d9 | 114,945,764,076,337,520,000,000,000,000,000,000,000 | 428 | libclamav/mspack.c: improve unpacking of malformed cabinets (bb#1826) |
int qtm_decompress(struct qtm_stream *qtm, off_t out_bytes) {
unsigned int frame_start, frame_end, window_posn, match_offset, range;
unsigned char *window, *i_ptr, *i_end, *runsrc, *rundest;
int i, j, selector, extra, sym, match_length, ret;
unsigned short H, L, C, symf;
register unsigned int bit_buffer;
register unsigned char bits_left;
unsigned char bits_needed, bit_run;
/* easy answers */
if (!qtm || (out_bytes < 0)) return CL_ENULLARG;
if (qtm->error) return qtm->error;
/* flush out any stored-up bytes before we begin */
i = qtm->o_end - qtm->o_ptr;
if ((off_t) i > out_bytes) i = (int) out_bytes;
if (i) {
if (qtm->wflag && (ret = mspack_write(qtm->ofd, qtm->o_ptr, i, qtm->file)) != CL_SUCCESS) {
return qtm->error = ret;
}
qtm->o_ptr += i;
out_bytes -= i;
}
if (out_bytes == 0) return CL_SUCCESS;
/* restore local state */
QTM_RESTORE_BITS;
window = qtm->window;
window_posn = qtm->window_posn;
frame_start = qtm->frame_start;
H = qtm->H;
L = qtm->L;
C = qtm->C;
/* while we do not have enough decoded bytes in reserve: */
while ((qtm->o_end - qtm->o_ptr) < out_bytes) {
/* read header if necessary. Initialises H, L and C */
if (!qtm->header_read) {
H = 0xFFFF; L = 0; QTM_READ_BITS(C, 16);
qtm->header_read = 1;
}
/* decode more, at most up to to frame boundary */
frame_end = window_posn + (out_bytes - (qtm->o_end - qtm->o_ptr));
if ((frame_start + QTM_FRAME_SIZE) < frame_end) {
frame_end = frame_start + QTM_FRAME_SIZE;
}
while (window_posn < frame_end) {
QTM_GET_SYMBOL(qtm->model7, selector);
if (selector < 4) {
struct qtm_model *mdl = (selector == 0) ? &qtm->model0 :
((selector == 1) ? &qtm->model1 :
((selector == 2) ? &qtm->model2 :
&qtm->model3));
QTM_GET_SYMBOL((*mdl), sym);
window[window_posn++] = sym;
}
else {
switch (selector) {
case 4: /* selector 4 = fixed length match (3 bytes) */
QTM_GET_SYMBOL(qtm->model4, sym);
QTM_READ_BITS(extra, qtm->extra_bits[sym]);
match_offset = qtm->position_base[sym] + extra + 1;
match_length = 3;
break;
case 5: /* selector 5 = fixed length match (4 bytes) */
QTM_GET_SYMBOL(qtm->model5, sym);
QTM_READ_BITS(extra, qtm->extra_bits[sym]);
match_offset = qtm->position_base[sym] + extra + 1;
match_length = 4;
break;
case 6: /* selector 6 = variable length match */
QTM_GET_SYMBOL(qtm->model6len, sym);
QTM_READ_BITS(extra, qtm->length_extra[sym]);
match_length = qtm->length_base[sym] + extra + 5;
QTM_GET_SYMBOL(qtm->model6, sym);
QTM_READ_BITS(extra, qtm->extra_bits[sym]);
match_offset = qtm->position_base[sym] + extra + 1;
break;
default:
/* should be impossible, model7 can only return 0-6 */
return qtm->error = CL_EFORMAT;
}
rundest = &window[window_posn];
i = match_length;
/* does match offset wrap the window? */
if (match_offset > window_posn) {
/* j = length from match offset to end of window */
j = match_offset - window_posn;
if (j > (int) qtm->window_size) {
cli_dbgmsg("qtm_decompress: match offset beyond window boundaries\n");
return qtm->error = CL_EFORMAT;
}
runsrc = &window[qtm->window_size - j];
if (j < i) {
/* if match goes over the window edge, do two copy runs */
i -= j; while (j-- > 0) *rundest++ = *runsrc++;
runsrc = window;
}
while (i-- > 0) *rundest++ = *runsrc++;
}
else {
runsrc = rundest - match_offset;
if(i > (int) (qtm->window_size - window_posn))
i = qtm->window_size - window_posn;
while (i-- > 0) *rundest++ = *runsrc++;
}
window_posn += match_length;
}
} /* while (window_posn < frame_end) */
qtm->o_end = &window[window_posn];
/* another frame completed? */
if ((window_posn - frame_start) >= QTM_FRAME_SIZE) {
if ((window_posn - frame_start) != QTM_FRAME_SIZE) {
cli_dbgmsg("qtm_decompress: overshot frame alignment\n");
return qtm->error = CL_EFORMAT;
}
/* re-align input */
if (bits_left & 7) QTM_REMOVE_BITS(bits_left & 7);
do { QTM_READ_BITS(i, 8); } while (i != 0xFF);
qtm->header_read = 0;
/* window wrap? */
if (window_posn == qtm->window_size) {
/* flush all currently stored data */
i = (qtm->o_end - qtm->o_ptr);
if (qtm->wflag && (ret = mspack_write(qtm->ofd, qtm->o_ptr, i, qtm->file)) != CL_SUCCESS) {
return qtm->error = ret;
}
out_bytes -= i;
qtm->o_ptr = &window[0];
qtm->o_end = &window[0];
window_posn = 0;
}
frame_start = window_posn;
}
} /* while (more bytes needed) */
if (out_bytes) {
i = (int) out_bytes;
if (qtm->wflag && (ret = mspack_write(qtm->ofd, qtm->o_ptr, i, qtm->file)) != CL_SUCCESS) {
return qtm->error = ret;
}
qtm->o_ptr += i;
}
/* store local state */
QTM_STORE_BITS;
qtm->window_posn = window_posn;
qtm->frame_start = frame_start;
qtm->H = H;
qtm->L = L;
qtm->C = C;
return CL_SUCCESS;
} | 1 | [
"CWE-20"
] | clamav-devel | 224fee54dd6cd8933d7007331ec2bfca0398d4b4 | 7,293,124,244,714,633,000,000,000,000,000,000,000 | 169 | libclamav/mspack.c: fix Quantum decompressor (bb#1771) |
struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
{
struct key *keyring;
int bucket;
keyring = ERR_PTR(-EINVAL);
if (!name)
goto error;
bucket = keyring_hash(name);
read_lock(&keyring_name_lock);
if (keyring_name_hash[bucket].next) {
/* search this hash bucket for a keyring with a matching name
* that's readable and that hasn't been revoked */
list_for_each_entry(keyring,
&keyring_name_hash[bucket],
type_data.link
) {
if (keyring->user->user_ns != current_user_ns())
continue;
if (test_bit(KEY_FLAG_REVOKED, &keyring->flags))
continue;
if (strcmp(keyring->description, name) != 0)
continue;
if (!skip_perm_check &&
key_permission(make_key_ref(keyring, 0),
KEY_SEARCH) < 0)
continue;
/* we've got a match */
atomic_inc(&keyring->usage);
read_unlock(&keyring_name_lock);
goto error;
}
}
read_unlock(&keyring_name_lock);
keyring = ERR_PTR(-ENOKEY);
error:
return keyring;
} /* end find_keyring_by_name() */ | 1 | [
"CWE-362"
] | linux-2.6 | cea7daa3589d6b550546a8c8963599f7c1a3ae5c | 16,621,305,839,720,120,000,000,000,000,000,000,000 | 48 | KEYS: find_keyring_by_name() can gain access to a freed keyring
find_keyring_by_name() can gain access to a keyring that has had its reference
count reduced to zero, and is thus ready to be freed. This then allows the
dead keyring to be brought back into use whilst it is being destroyed.
The following timeline illustrates the process:
|(cleaner) (user)
|
| free_user(user) sys_keyctl()
| | |
| key_put(user->session_keyring) keyctl_get_keyring_ID()
| || //=> keyring->usage = 0 |
| |schedule_work(&key_cleanup_task) lookup_user_key()
| || |
| kmem_cache_free(,user) |
| . |[KEY_SPEC_USER_KEYRING]
| . install_user_keyrings()
| . ||
| key_cleanup() [<= worker_thread()] ||
| | ||
| [spin_lock(&key_serial_lock)] |[mutex_lock(&key_user_keyr..mutex)]
| | ||
| atomic_read() == 0 ||
| |{ rb_ease(&key->serial_node,) } ||
| | ||
| [spin_unlock(&key_serial_lock)] |find_keyring_by_name()
| | |||
| keyring_destroy(keyring) ||[read_lock(&keyring_name_lock)]
| || |||
| |[write_lock(&keyring_name_lock)] ||atomic_inc(&keyring->usage)
| |. ||| *** GET freeing keyring ***
| |. ||[read_unlock(&keyring_name_lock)]
| || ||
| |list_del() |[mutex_unlock(&key_user_k..mutex)]
| || |
| |[write_unlock(&keyring_name_lock)] ** INVALID keyring is returned **
| | .
| kmem_cache_free(,keyring) .
| .
| atomic_dec(&keyring->usage)
v *** DESTROYED ***
TIME
If CONFIG_SLUB_DEBUG=y then we may see the following message generated:
=============================================================================
BUG key_jar: Poison overwritten
-----------------------------------------------------------------------------
INFO: 0xffff880197a7e200-0xffff880197a7e200. First byte 0x6a instead of 0x6b
INFO: Allocated in key_alloc+0x10b/0x35f age=25 cpu=1 pid=5086
INFO: Freed in key_cleanup+0xd0/0xd5 age=12 cpu=1 pid=10
INFO: Slab 0xffffea000592cb90 objects=16 used=2 fp=0xffff880197a7e200 flags=0x200000000000c3
INFO: Object 0xffff880197a7e200 @offset=512 fp=0xffff880197a7e300
Bytes b4 0xffff880197a7e1f0: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
Object 0xffff880197a7e200: 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b jkkkkkkkkkkkkkkk
Alternatively, we may see a system panic happen, such as:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000001
IP: [<ffffffff810e61a3>] kmem_cache_alloc+0x5b/0xe9
PGD 6b2b4067 PUD 6a80d067 PMD 0
Oops: 0000 [#1] SMP
last sysfs file: /sys/kernel/kexec_crash_loaded
CPU 1
...
Pid: 31245, comm: su Not tainted 2.6.34-rc5-nofixed-nodebug #2 D2089/PRIMERGY
RIP: 0010:[<ffffffff810e61a3>] [<ffffffff810e61a3>] kmem_cache_alloc+0x5b/0xe9
RSP: 0018:ffff88006af3bd98 EFLAGS: 00010002
RAX: 0000000000000000 RBX: 0000000000000001 RCX: ffff88007d19900b
RDX: 0000000100000000 RSI: 00000000000080d0 RDI: ffffffff81828430
RBP: ffffffff81828430 R08: ffff88000a293750 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000100000 R12: 00000000000080d0
R13: 00000000000080d0 R14: 0000000000000296 R15: ffffffff810f20ce
FS: 00007f97116bc700(0000) GS:ffff88000a280000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000001 CR3: 000000006a91c000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process su (pid: 31245, threadinfo ffff88006af3a000, task ffff8800374414c0)
Stack:
0000000512e0958e 0000000000008000 ffff880037f8d180 0000000000000001
0000000000000000 0000000000008001 ffff88007d199000 ffffffff810f20ce
0000000000008000 ffff88006af3be48 0000000000000024 ffffffff810face3
Call Trace:
[<ffffffff810f20ce>] ? get_empty_filp+0x70/0x12f
[<ffffffff810face3>] ? do_filp_open+0x145/0x590
[<ffffffff810ce208>] ? tlb_finish_mmu+0x2a/0x33
[<ffffffff810ce43c>] ? unmap_region+0xd3/0xe2
[<ffffffff810e4393>] ? virt_to_head_page+0x9/0x2d
[<ffffffff81103916>] ? alloc_fd+0x69/0x10e
[<ffffffff810ef4ed>] ? do_sys_open+0x56/0xfc
[<ffffffff81008a02>] ? system_call_fastpath+0x16/0x1b
Code: 0f 1f 44 00 00 49 89 c6 fa 66 0f 1f 44 00 00 65 4c 8b 04 25 60 e8 00 00 48 8b 45 00 49 01 c0 49 8b 18 48 85 db 74 0d 48 63 45 18 <48> 8b 04 03 49 89 00 eb 14 4c 89 f9 83 ca ff 44 89 e6 48 89 ef
RIP [<ffffffff810e61a3>] kmem_cache_alloc+0x5b/0xe9
This problem is that find_keyring_by_name does not confirm that the keyring is
valid before accepting it.
Skipping keyrings that have been reduced to a zero count seems the way to go.
To this end, use atomic_inc_not_zero() to increment the usage count and skip
the candidate keyring if that returns false.
The following script _may_ cause the bug to happen, but there's no guarantee
as the window of opportunity is small:
#!/bin/sh
LOOP=100000
USER=dummy_user
/bin/su -c "exit;" $USER || { /usr/sbin/adduser -m $USER; add=1; }
for ((i=0; i<LOOP; i++))
do
/bin/su -c "echo '$i' > /dev/null" $USER
done
(( add == 1 )) && /usr/sbin/userdel -r $USER
exit
Note that the nominated user must not be in use.
An alternative way of testing this may be:
for ((i=0; i<100000; i++))
do
keyctl session foo /bin/true || break
done >&/dev/null
as that uses a keyring named "foo" rather than relying on the user and
user-session named keyrings.
Reported-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org> |
static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
{
struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd;
struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
unsigned int data_blocks, ind_blocks;
struct gfs2_holder *ghs, i_gh;
unsigned int qx, x;
struct gfs2_quota_data *qd;
loff_t offset;
unsigned int nalloc = 0, blocks;
struct gfs2_alloc *al = NULL;
int error;
gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
&data_blocks, &ind_blocks);
ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_NOFS);
if (!ghs)
return -ENOMEM;
sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL);
mutex_lock_nested(&ip->i_inode.i_mutex, I_MUTEX_QUOTA);
for (qx = 0; qx < num_qd; qx++) {
error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE,
GL_NOCACHE, &ghs[qx]);
if (error)
goto out;
}
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
if (error)
goto out;
for (x = 0; x < num_qd; x++) {
int alloc_required;
offset = qd2offset(qda[x]);
error = gfs2_write_alloc_required(ip, offset,
sizeof(struct gfs2_quota),
&alloc_required);
if (error)
goto out_gunlock;
if (alloc_required)
nalloc++;
}
al = gfs2_alloc_get(ip);
if (!al) {
error = -ENOMEM;
goto out_gunlock;
}
/*
* 1 blk for unstuffing inode if stuffed. We add this extra
* block to the reservation unconditionally. If the inode
* doesn't need unstuffing, the block will be released to the
* rgrp since it won't be allocated during the transaction
*/
al->al_requested = 1;
/* +1 in the end for block requested above for unstuffing */
blocks = num_qd * data_blocks + RES_DINODE + num_qd + 1;
if (nalloc)
al->al_requested += nalloc * (data_blocks + ind_blocks);
error = gfs2_inplace_reserve(ip);
if (error)
goto out_alloc;
if (nalloc)
blocks += al->al_rgd->rd_length + nalloc * ind_blocks + RES_STATFS;
error = gfs2_trans_begin(sdp, blocks, 0);
if (error)
goto out_ipres;
for (x = 0; x < num_qd; x++) {
qd = qda[x];
offset = qd2offset(qd);
error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync, qd, NULL);
if (error)
goto out_end_trans;
do_qc(qd, -qd->qd_change_sync);
}
error = 0;
out_end_trans:
gfs2_trans_end(sdp);
out_ipres:
gfs2_inplace_release(ip);
out_alloc:
gfs2_alloc_put(ip);
out_gunlock:
gfs2_glock_dq_uninit(&i_gh);
out:
while (qx--)
gfs2_glock_dq_uninit(&ghs[qx]);
mutex_unlock(&ip->i_inode.i_mutex);
kfree(ghs);
gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
return error;
} | 1 | [
"CWE-399"
] | linux-2.6 | 7e619bc3e6252dc746f64ac3b486e784822e9533 | 18,619,989,573,510,160,000,000,000,000,000,000,000 | 102 | GFS2: Fix writing to non-page aligned gfs2_quota structures
This is the upstream fix for this bug. This patch differs
from the RHEL5 fix (Red Hat bz #555754) which simply writes to the 8-byte
value field of the quota. In upstream quota code, we're
required to write the entire quota (88 bytes) which can be split
across a page boundary. We check for such quotas, and read/write
the two parts from/to the corresponding pages holding these parts.
With this patch, I don't see the bug anymore using the reproducer
in Red Hat bz 555754. I successfully ran a couple of simple tests/mounts/
umounts and it doesn't seem like this patch breaks anything else.
Signed-off-by: Abhi Das <adas@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com> |
static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
s64 change, struct gfs2_quota_data *qd,
struct fs_disk_quota *fdq)
{
struct inode *inode = &ip->i_inode;
struct address_space *mapping = inode->i_mapping;
unsigned long index = loc >> PAGE_CACHE_SHIFT;
unsigned offset = loc & (PAGE_CACHE_SIZE - 1);
unsigned blocksize, iblock, pos;
struct buffer_head *bh, *dibh;
struct page *page;
void *kaddr;
struct gfs2_quota *qp;
s64 value;
int err = -EIO;
u64 size;
if (gfs2_is_stuffed(ip))
gfs2_unstuff_dinode(ip, NULL);
page = grab_cache_page(mapping, index);
if (!page)
return -ENOMEM;
blocksize = inode->i_sb->s_blocksize;
iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
if (!page_has_buffers(page))
create_empty_buffers(page, blocksize, 0);
bh = page_buffers(page);
pos = blocksize;
while (offset >= pos) {
bh = bh->b_this_page;
iblock++;
pos += blocksize;
}
if (!buffer_mapped(bh)) {
gfs2_block_map(inode, iblock, bh, 1);
if (!buffer_mapped(bh))
goto unlock;
}
if (PageUptodate(page))
set_buffer_uptodate(bh);
if (!buffer_uptodate(bh)) {
ll_rw_block(READ_META, 1, &bh);
wait_on_buffer(bh);
if (!buffer_uptodate(bh))
goto unlock;
}
gfs2_trans_add_bh(ip->i_gl, bh, 0);
kaddr = kmap_atomic(page, KM_USER0);
qp = kaddr + offset;
value = (s64)be64_to_cpu(qp->qu_value) + change;
qp->qu_value = cpu_to_be64(value);
qd->qd_qb.qb_value = qp->qu_value;
if (fdq) {
if (fdq->d_fieldmask & FS_DQ_BSOFT) {
qp->qu_warn = cpu_to_be64(fdq->d_blk_softlimit);
qd->qd_qb.qb_warn = qp->qu_warn;
}
if (fdq->d_fieldmask & FS_DQ_BHARD) {
qp->qu_limit = cpu_to_be64(fdq->d_blk_hardlimit);
qd->qd_qb.qb_limit = qp->qu_limit;
}
}
flush_dcache_page(page);
kunmap_atomic(kaddr, KM_USER0);
err = gfs2_meta_inode_buffer(ip, &dibh);
if (err)
goto unlock;
size = loc + sizeof(struct gfs2_quota);
if (size > inode->i_size) {
ip->i_disksize = size;
i_size_write(inode, size);
}
inode->i_mtime = inode->i_atime = CURRENT_TIME;
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_dinode_out(ip, dibh->b_data);
brelse(dibh);
mark_inode_dirty(inode);
unlock:
unlock_page(page);
page_cache_release(page);
return err;
} | 1 | [
"CWE-399"
] | linux-2.6 | 7e619bc3e6252dc746f64ac3b486e784822e9533 | 59,470,795,693,199,750,000,000,000,000,000,000,000 | 94 | GFS2: Fix writing to non-page aligned gfs2_quota structures
This is the upstream fix for this bug. This patch differs
from the RHEL5 fix (Red Hat bz #555754) which simply writes to the 8-byte
value field of the quota. In upstream quota code, we're
required to write the entire quota (88 bytes) which can be split
across a page boundary. We check for such quotas, and read/write
the two parts from/to the corresponding pages holding these parts.
With this patch, I don't see the bug anymore using the reproducer
in Red Hat bz 555754. I successfully ran a couple of simple tests/mounts/
umounts and it doesn't seem like this patch breaks anything else.
Signed-off-by: Abhi Das <adas@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com> |
void chain_reply(struct smb_request *req)
{
size_t smblen = smb_len(req->inbuf);
size_t already_used, length_needed;
uint8_t chain_cmd;
uint32_t chain_offset; /* uint32_t to avoid overflow */
uint8_t wct;
uint16_t *vwv;
uint16_t buflen;
uint8_t *buf;
if (IVAL(req->outbuf, smb_rcls) != 0) {
fixup_chain_error_packet(req);
}
/*
* Any of the AndX requests and replies have at least a wct of
* 2. vwv[0] is the next command, vwv[1] is the offset from the
* beginning of the SMB header to the next wct field.
*
* None of the AndX requests put anything valuable in vwv[0] and [1],
* so we can overwrite it here to form the chain.
*/
if ((req->wct < 2) || (CVAL(req->outbuf, smb_wct) < 2)) {
goto error;
}
/*
* Here we assume that this is the end of the chain. For that we need
* to set "next command" to 0xff and the offset to 0. If we later find
* more commands in the chain, this will be overwritten again.
*/
SCVAL(req->outbuf, smb_vwv0, 0xff);
SCVAL(req->outbuf, smb_vwv0+1, 0);
SSVAL(req->outbuf, smb_vwv1, 0);
if (req->chain_outbuf == NULL) {
/*
* In req->chain_outbuf we collect all the replies. Start the
* chain by copying in the first reply.
*
* We do the realloc because later on we depend on
* talloc_get_size to determine the length of
* chain_outbuf. The reply_xxx routines might have
* over-allocated (reply_pipe_read_and_X used to be such an
* example).
*/
req->chain_outbuf = TALLOC_REALLOC_ARRAY(
req, req->outbuf, uint8_t, smb_len(req->outbuf) + 4);
if (req->chain_outbuf == NULL) {
goto error;
}
req->outbuf = NULL;
} else {
/*
* Update smb headers where subsequent chained commands
* may have updated them.
*/
SCVAL(req->chain_outbuf, smb_tid, CVAL(req->outbuf, smb_tid));
SCVAL(req->chain_outbuf, smb_uid, CVAL(req->outbuf, smb_uid));
if (!smb_splice_chain(&req->chain_outbuf,
CVAL(req->outbuf, smb_com),
CVAL(req->outbuf, smb_wct),
(uint16_t *)(req->outbuf + smb_vwv),
0, smb_buflen(req->outbuf),
(uint8_t *)smb_buf(req->outbuf))) {
goto error;
}
TALLOC_FREE(req->outbuf);
}
/*
* We use the old request's vwv field to grab the next chained command
* and offset into the chained fields.
*/
chain_cmd = CVAL(req->vwv+0, 0);
chain_offset = SVAL(req->vwv+1, 0);
if (chain_cmd == 0xff) {
/*
* End of chain, no more requests from the client. So ship the
* replies.
*/
smb_setlen((char *)(req->chain_outbuf),
talloc_get_size(req->chain_outbuf) - 4);
if (!srv_send_smb(smbd_server_fd(), (char *)req->chain_outbuf,
true, req->seqnum+1,
IS_CONN_ENCRYPTED(req->conn)
||req->encrypted,
&req->pcd)) {
exit_server_cleanly("chain_reply: srv_send_smb "
"failed.");
}
TALLOC_FREE(req->chain_outbuf);
req->done = true;
return;
}
/* add a new perfcounter for this element of chain */
SMB_PERFCOUNT_ADD(&req->pcd);
SMB_PERFCOUNT_SET_OP(&req->pcd, chain_cmd);
SMB_PERFCOUNT_SET_MSGLEN_IN(&req->pcd, smblen);
/*
* Check if the client tries to fool us. The request so far uses the
* space to the end of the byte buffer in the request just
* processed. The chain_offset can't point into that area. If that was
* the case, we could end up with an endless processing of the chain,
* we would always handle the same request.
*/
already_used = PTR_DIFF(req->buf+req->buflen, smb_base(req->inbuf));
if (chain_offset < already_used) {
goto error;
}
/*
* Next check: Make sure the chain offset does not point beyond the
* overall smb request length.
*/
length_needed = chain_offset+1; /* wct */
if (length_needed > smblen) {
goto error;
}
/*
* Now comes the pointer magic. Goal here is to set up req->vwv and
* req->buf correctly again to be able to call the subsequent
* switch_message(). The chain offset (the former vwv[1]) points at
* the new wct field.
*/
wct = CVAL(smb_base(req->inbuf), chain_offset);
/*
* Next consistency check: Make the new vwv array fits in the overall
* smb request.
*/
length_needed += (wct+1)*sizeof(uint16_t); /* vwv+buflen */
if (length_needed > smblen) {
goto error;
}
vwv = (uint16_t *)(smb_base(req->inbuf) + chain_offset + 1);
/*
* Now grab the new byte buffer....
*/
buflen = SVAL(vwv+wct, 0);
/*
* .. and check that it fits.
*/
length_needed += buflen;
if (length_needed > smblen) {
goto error;
}
buf = (uint8_t *)(vwv+wct+1);
req->cmd = chain_cmd;
req->wct = wct;
req->vwv = vwv;
req->buflen = buflen;
req->buf = buf;
switch_message(chain_cmd, req, smblen);
if (req->outbuf == NULL) {
/*
* This happens if the chained command has suspended itself or
* if it has called srv_send_smb() itself.
*/
return;
}
/*
* We end up here if the chained command was not itself chained or
* suspended, but for example a close() command. We now need to splice
* the chained commands' outbuf into the already built up chain_outbuf
* and ship the result.
*/
goto done;
error:
/*
* We end up here if there's any error in the chain syntax. Report a
* DOS error, just like Windows does.
*/
reply_force_doserror(req, ERRSRV, ERRerror);
fixup_chain_error_packet(req);
done:
/*
* This scary statement intends to set the
* FLAGS2_32_BIT_ERROR_CODES flg2 field in req->chain_outbuf
* to the value req->outbuf carries
*/
SSVAL(req->chain_outbuf, smb_flg2,
(SVAL(req->chain_outbuf, smb_flg2) & ~FLAGS2_32_BIT_ERROR_CODES)
| (SVAL(req->outbuf, smb_flg2) & FLAGS2_32_BIT_ERROR_CODES));
/*
* Transfer the error codes from the subrequest to the main one
*/
SSVAL(req->chain_outbuf, smb_rcls, SVAL(req->outbuf, smb_rcls));
SSVAL(req->chain_outbuf, smb_err, SVAL(req->outbuf, smb_err));
if (!smb_splice_chain(&req->chain_outbuf,
CVAL(req->outbuf, smb_com),
CVAL(req->outbuf, smb_wct),
(uint16_t *)(req->outbuf + smb_vwv),
0, smb_buflen(req->outbuf),
(uint8_t *)smb_buf(req->outbuf))) {
exit_server_cleanly("chain_reply: smb_splice_chain failed\n");
}
TALLOC_FREE(req->outbuf);
smb_setlen((char *)(req->chain_outbuf),
talloc_get_size(req->chain_outbuf) - 4);
show_msg((char *)(req->chain_outbuf));
if (!srv_send_smb(smbd_server_fd(), (char *)req->chain_outbuf,
true, req->seqnum+1,
IS_CONN_ENCRYPTED(req->conn)||req->encrypted,
&req->pcd)) {
exit_server_cleanly("construct_reply: srv_send_smb failed.");
}
TALLOC_FREE(req->chain_outbuf);
req->done = true;
} | 1 | [] | samba | 25452a2268ac7013da28125f3df22085139af12d | 285,756,523,219,705,400,000,000,000,000,000,000,000 | 240 | s3: Fix a NULL pointer dereference
Found by Laurent Gaffie <laurent.gaffie@gmail.com>.
Thanks!
Volker |
static void reply_sesssetup_and_X_spnego(struct smb_request *req)
{
const uint8 *p;
DATA_BLOB blob1;
size_t bufrem;
char *tmp;
const char *native_os;
const char *native_lanman;
const char *primary_domain;
const char *p2;
uint16 data_blob_len = SVAL(req->vwv+7, 0);
enum remote_arch_types ra_type = get_remote_arch();
int vuid = req->vuid;
user_struct *vuser = NULL;
NTSTATUS status = NT_STATUS_OK;
uint16 smbpid = req->smbpid;
struct smbd_server_connection *sconn = smbd_server_conn;
DEBUG(3,("Doing spnego session setup\n"));
if (global_client_caps == 0) {
global_client_caps = IVAL(req->vwv+10, 0);
if (!(global_client_caps & CAP_STATUS32)) {
remove_from_common_flags2(FLAGS2_32_BIT_ERROR_CODES);
}
}
p = req->buf;
if (data_blob_len == 0) {
/* an invalid request */
reply_nterror(req, nt_status_squash(NT_STATUS_LOGON_FAILURE));
return;
}
bufrem = smbreq_bufrem(req, p);
/* pull the spnego blob */
blob1 = data_blob(p, MIN(bufrem, data_blob_len));
#if 0
file_save("negotiate.dat", blob1.data, blob1.length);
#endif
p2 = (char *)req->buf + data_blob_len;
p2 += srvstr_pull_req_talloc(talloc_tos(), req, &tmp, p2,
STR_TERMINATE);
native_os = tmp ? tmp : "";
p2 += srvstr_pull_req_talloc(talloc_tos(), req, &tmp, p2,
STR_TERMINATE);
native_lanman = tmp ? tmp : "";
p2 += srvstr_pull_req_talloc(talloc_tos(), req, &tmp, p2,
STR_TERMINATE);
primary_domain = tmp ? tmp : "";
DEBUG(3,("NativeOS=[%s] NativeLanMan=[%s] PrimaryDomain=[%s]\n",
native_os, native_lanman, primary_domain));
if ( ra_type == RA_WIN2K ) {
/* Vista sets neither the OS or lanman strings */
if ( !strlen(native_os) && !strlen(native_lanman) )
set_remote_arch(RA_VISTA);
/* Windows 2003 doesn't set the native lanman string,
but does set primary domain which is a bug I think */
if ( !strlen(native_lanman) ) {
ra_lanman_string( primary_domain );
} else {
ra_lanman_string( native_lanman );
}
}
/* Did we get a valid vuid ? */
if (!is_partial_auth_vuid(sconn, vuid)) {
/* No, then try and see if this is an intermediate sessionsetup
* for a large SPNEGO packet. */
struct pending_auth_data *pad;
pad = get_pending_auth_data(sconn, smbpid);
if (pad) {
DEBUG(10,("reply_sesssetup_and_X_spnego: found "
"pending vuid %u\n",
(unsigned int)pad->vuid ));
vuid = pad->vuid;
}
}
/* Do we have a valid vuid now ? */
if (!is_partial_auth_vuid(sconn, vuid)) {
/* No, start a new authentication setup. */
vuid = register_initial_vuid(sconn);
if (vuid == UID_FIELD_INVALID) {
data_blob_free(&blob1);
reply_nterror(req, nt_status_squash(
NT_STATUS_INVALID_PARAMETER));
return;
}
}
vuser = get_partial_auth_user_struct(sconn, vuid);
/* This MUST be valid. */
if (!vuser) {
smb_panic("reply_sesssetup_and_X_spnego: invalid vuid.");
}
/* Large (greater than 4k) SPNEGO blobs are split into multiple
* sessionsetup requests as the Windows limit on the security blob
* field is 4k. Bug #4400. JRA.
*/
status = check_spnego_blob_complete(sconn, smbpid, vuid, &blob1);
if (!NT_STATUS_IS_OK(status)) {
if (!NT_STATUS_EQUAL(status,
NT_STATUS_MORE_PROCESSING_REQUIRED)) {
/* Real error - kill the intermediate vuid */
invalidate_vuid(sconn, vuid);
}
data_blob_free(&blob1);
reply_nterror(req, nt_status_squash(status));
return;
}
if (blob1.data[0] == ASN1_APPLICATION(0)) {
/* its a negTokenTarg packet */
reply_spnego_negotiate(req, vuid, blob1,
&vuser->auth_ntlmssp_state);
data_blob_free(&blob1);
return;
}
if (blob1.data[0] == ASN1_CONTEXT(1)) {
/* its a auth packet */
reply_spnego_auth(req, vuid, blob1,
&vuser->auth_ntlmssp_state);
data_blob_free(&blob1);
return;
}
if (strncmp((char *)(blob1.data), "NTLMSSP", 7) == 0) {
DATA_BLOB chal;
if (!vuser->auth_ntlmssp_state) {
status = auth_ntlmssp_start(&vuser->auth_ntlmssp_state);
if (!NT_STATUS_IS_OK(status)) {
/* Kill the intermediate vuid */
invalidate_vuid(sconn, vuid);
data_blob_free(&blob1);
reply_nterror(req, nt_status_squash(status));
return;
}
}
status = auth_ntlmssp_update(vuser->auth_ntlmssp_state,
blob1, &chal);
data_blob_free(&blob1);
reply_spnego_ntlmssp(req, vuid,
&vuser->auth_ntlmssp_state,
&chal, status, OID_NTLMSSP, false);
data_blob_free(&chal);
return;
}
/* what sort of packet is this? */
DEBUG(1,("Unknown packet in reply_sesssetup_and_X_spnego\n"));
data_blob_free(&blob1);
reply_nterror(req, nt_status_squash(NT_STATUS_LOGON_FAILURE));
} | 1 | [
"CWE-119"
] | samba | 9280051bfba337458722fb157f3082f93cbd9f2b | 328,722,533,825,058,300,000,000,000,000,000,000,000 | 180 | s3: Fix an uninitialized variable read
Found by Laurent Gaffie <laurent.gaffie@gmail.com>
Thanks for that,
Volker
Fix bug #7254 (An uninitialized variable read could cause an smbd crash). |
void chain_reply(struct smb_request *req)
{
size_t smblen = smb_len(req->inbuf);
size_t already_used, length_needed;
uint8_t chain_cmd;
uint32_t chain_offset; /* uint32_t to avoid overflow */
uint8_t wct;
uint16_t *vwv;
uint16_t buflen;
uint8_t *buf;
if (IVAL(req->outbuf, smb_rcls) != 0) {
fixup_chain_error_packet(req);
}
/*
* Any of the AndX requests and replies have at least a wct of
* 2. vwv[0] is the next command, vwv[1] is the offset from the
* beginning of the SMB header to the next wct field.
*
* None of the AndX requests put anything valuable in vwv[0] and [1],
* so we can overwrite it here to form the chain.
*/
if ((req->wct < 2) || (CVAL(req->outbuf, smb_wct) < 2)) {
goto error;
}
/*
* Here we assume that this is the end of the chain. For that we need
* to set "next command" to 0xff and the offset to 0. If we later find
* more commands in the chain, this will be overwritten again.
*/
SCVAL(req->outbuf, smb_vwv0, 0xff);
SCVAL(req->outbuf, smb_vwv0+1, 0);
SSVAL(req->outbuf, smb_vwv1, 0);
if (req->chain_outbuf == NULL) {
/*
* In req->chain_outbuf we collect all the replies. Start the
* chain by copying in the first reply.
*
* We do the realloc because later on we depend on
* talloc_get_size to determine the length of
* chain_outbuf. The reply_xxx routines might have
* over-allocated (reply_pipe_read_and_X used to be such an
* example).
*/
req->chain_outbuf = TALLOC_REALLOC_ARRAY(
req, req->outbuf, uint8_t, smb_len(req->outbuf) + 4);
if (req->chain_outbuf == NULL) {
goto error;
}
req->outbuf = NULL;
} else {
/*
* Update smb headers where subsequent chained commands
* may have updated them.
*/
SCVAL(req->chain_outbuf, smb_tid, CVAL(req->outbuf, smb_tid));
SCVAL(req->chain_outbuf, smb_uid, CVAL(req->outbuf, smb_uid));
if (!smb_splice_chain(&req->chain_outbuf,
CVAL(req->outbuf, smb_com),
CVAL(req->outbuf, smb_wct),
(uint16_t *)(req->outbuf + smb_vwv),
0, smb_buflen(req->outbuf),
(uint8_t *)smb_buf(req->outbuf))) {
goto error;
}
TALLOC_FREE(req->outbuf);
}
/*
* We use the old request's vwv field to grab the next chained command
* and offset into the chained fields.
*/
chain_cmd = CVAL(req->vwv+0, 0);
chain_offset = SVAL(req->vwv+1, 0);
if (chain_cmd == 0xff) {
/*
* End of chain, no more requests from the client. So ship the
* replies.
*/
smb_setlen((char *)(req->chain_outbuf),
talloc_get_size(req->chain_outbuf) - 4);
if (!srv_send_smb(smbd_server_fd(), (char *)req->chain_outbuf,
true, req->seqnum+1,
IS_CONN_ENCRYPTED(req->conn)
||req->encrypted,
&req->pcd)) {
exit_server_cleanly("chain_reply: srv_send_smb "
"failed.");
}
TALLOC_FREE(req);
return;
}
/* add a new perfcounter for this element of chain */
SMB_PERFCOUNT_ADD(&req->pcd);
SMB_PERFCOUNT_SET_OP(&req->pcd, chain_cmd);
SMB_PERFCOUNT_SET_MSGLEN_IN(&req->pcd, smblen);
/*
* Check if the client tries to fool us. The request so far uses the
* space to the end of the byte buffer in the request just
* processed. The chain_offset can't point into that area. If that was
* the case, we could end up with an endless processing of the chain,
* we would always handle the same request.
*/
already_used = PTR_DIFF(req->buf+req->buflen, smb_base(req->inbuf));
if (chain_offset < already_used) {
goto error;
}
/*
* Next check: Make sure the chain offset does not point beyond the
* overall smb request length.
*/
length_needed = chain_offset+1; /* wct */
if (length_needed > smblen) {
goto error;
}
/*
* Now comes the pointer magic. Goal here is to set up req->vwv and
* req->buf correctly again to be able to call the subsequent
* switch_message(). The chain offset (the former vwv[1]) points at
* the new wct field.
*/
wct = CVAL(smb_base(req->inbuf), chain_offset);
/*
* Next consistency check: Make the new vwv array fits in the overall
* smb request.
*/
length_needed += (wct+1)*sizeof(uint16_t); /* vwv+buflen */
if (length_needed > smblen) {
goto error;
}
vwv = (uint16_t *)(smb_base(req->inbuf) + chain_offset + 1);
/*
* Now grab the new byte buffer....
*/
buflen = SVAL(vwv+wct, 0);
/*
* .. and check that it fits.
*/
length_needed += buflen;
if (length_needed > smblen) {
goto error;
}
buf = (uint8_t *)(vwv+wct+1);
req->cmd = chain_cmd;
req->wct = wct;
req->vwv = vwv;
req->buflen = buflen;
req->buf = buf;
switch_message(chain_cmd, req, smblen);
if (req->outbuf == NULL) {
/*
* This happens if the chained command has suspended itself or
* if it has called srv_send_smb() itself.
*/
return;
}
/*
* We end up here if the chained command was not itself chained or
* suspended, but for example a close() command. We now need to splice
* the chained commands' outbuf into the already built up chain_outbuf
* and ship the result.
*/
goto done;
error:
/*
* We end up here if there's any error in the chain syntax. Report a
* DOS error, just like Windows does.
*/
reply_nterror(req, NT_STATUS_DOS(ERRSRV, ERRerror));
fixup_chain_error_packet(req);
done:
if (!smb_splice_chain(&req->chain_outbuf,
CVAL(req->outbuf, smb_com),
CVAL(req->outbuf, smb_wct),
(uint16_t *)(req->outbuf + smb_vwv),
0, smb_buflen(req->outbuf),
(uint8_t *)smb_buf(req->outbuf))) {
exit_server_cleanly("chain_reply: smb_splice_chain failed\n");
}
TALLOC_FREE(req->outbuf);
smb_setlen((char *)(req->chain_outbuf),
talloc_get_size(req->chain_outbuf) - 4);
show_msg((char *)(req->chain_outbuf));
if (!srv_send_smb(smbd_server_fd(), (char *)req->chain_outbuf,
true, req->seqnum+1,
IS_CONN_ENCRYPTED(req->conn)||req->encrypted,
&req->pcd)) {
exit_server_cleanly("construct_reply: srv_send_smb failed.");
}
TALLOC_FREE(req);
} | 1 | [] | samba | c116652a3050a8549b722ae8ab5f9a2bf9a33b9f | 193,845,603,418,617,400,000,000,000,000,000,000,000 | 224 | In chain_reply, copy the subrequests' error to the main request |
_gnutls_x509_oid2mac_algorithm (const char *oid)
{
gnutls_mac_algorithm_t ret = 0;
GNUTLS_HASH_LOOP (if (strcmp (oid, p->oid) == 0)
{
ret = p->id; break;}
);
if (ret == 0)
return GNUTLS_MAC_UNKNOWN;
return ret;
} | 1 | [
"CWE-310"
] | gnutls | 34d87a7c3f12794a3ec2305cd2fdbae152bf2a76 | 42,633,597,698,949,330,000,000,000,000,000,000,000 | 13 | (_gnutls_x509_oid2mac_algorithm): Don't crash trying to strcmp the
NULL OID value in the hash_algorithms array, which happens when the
input OID doesn't match our OIDs for SHA1, MD5, MD2 or RIPEMD160.
Reported by satyakumar <satyam_kkd@hyd.hellosoft.com>. |
cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
{
off_t size; /* total number of bytes in the file */
off_t bytesleft, trailerlength;
char *buf; /* start of memory mapped area */
const char *p, *q, *trailerstart;
const char *xrefstart; /* cross reference table */
/*size_t xreflength;*/
int printed_predictor_message, printed_embedded_font_message, rc;
unsigned int files;
fmap_t *map = *ctx->fmap;
int opt_failed = 0;
cli_dbgmsg("in cli_pdf(%s)\n", dir);
size = map->len - offset;
if(size <= 7) /* doesn't even include the file header */
return CL_CLEAN;
p = buf = fmap_need_off_once(map, 0, size); /* FIXME: really port to fmap */
if(!buf) {
cli_errmsg("cli_pdf: mmap() failed\n");
return CL_EMAP;
}
cli_dbgmsg("cli_pdf: scanning %lu bytes\n", (unsigned long)size);
/* Lines are terminated by \r, \n or both */
/* File Header */
bytesleft = size - 5;
for(q = p; bytesleft; bytesleft--, q++) {
if(!strncasecmp(q, "%PDF-", 5)) {
bytesleft = size - (off_t) (q - p);
p = q;
break;
}
}
if(!bytesleft) {
cli_dbgmsg("cli_pdf: file header not found\n");
return CL_CLEAN;
}
/* Find the file trailer */
for(q = &p[bytesleft - 5]; q > p; --q)
if(strncasecmp(q, "%%EOF", 5) == 0)
break;
if(q <= p) {
cli_dbgmsg("cli_pdf: trailer not found\n");
return CL_CLEAN;
}
for(trailerstart = &q[-7]; trailerstart > p; --trailerstart)
if(memcmp(trailerstart, "trailer", 7) == 0)
break;
/*
* q points to the end of the trailer section
*/
trailerlength = (long)(q - trailerstart);
if(cli_memstr(trailerstart, trailerlength, "Encrypt", 7)) {
/*
* This tends to mean that the file is, in effect, read-only
* http://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
* http://www.adobe.com/devnet/pdf/
*/
cli_dbgmsg("cli_pdf: Encrypted PDF files not yet supported\n");
return CL_CLEAN;
}
/*
* not true, since edits may put data after the trailer
bytesleft -= trailerlength;
*/
/*
* FIXME: Handle more than one xref section in the xref table
*/
for(xrefstart = trailerstart; xrefstart > p; --xrefstart)
if(memcmp(xrefstart, "xref", 4) == 0)
/*
* Make sure it's the start of the line, not a startxref
* token
*/
if((xrefstart[-1] == '\n') || (xrefstart[-1] == '\r'))
break;
if(xrefstart == p) {
cli_dbgmsg("cli_pdf: xref not found\n");
return CL_CLEAN;
}
printed_predictor_message = printed_embedded_font_message = 0;
/*
* not true, since edits may put data after the trailer
xreflength = (size_t)(trailerstart - xrefstart);
bytesleft -= xreflength;
*/
files = 0;
rc = CL_CLEAN;
/*
* The body section consists of a sequence of indirect objects
*/
while((p < xrefstart) && (cli_checklimits("cli_pdf", ctx, 0, 0, 0)==CL_CLEAN) &&
((q = pdf_nextobject(p, bytesleft)) != NULL)) {
int is_ascii85decode, is_flatedecode, fout, len, has_cr;
/*int object_number, generation_number;*/
const char *objstart, *objend, *streamstart, *streamend;
unsigned long length, objlen, real_streamlen, calculated_streamlen;
int is_embedded_font, predictor;
char fullname[NAME_MAX + 1];
rc = CL_CLEAN;
if(q == xrefstart)
break;
if(memcmp(q, "xref", 4) == 0)
break;
/*object_number = atoi(q);*/
bytesleft -= (off_t)(q - p);
p = q;
if(memcmp(q, "endobj", 6) == 0)
continue;
if(!isdigit(*q)) {
cli_dbgmsg("cli_pdf: Object number missing\n");
break;
}
q = pdf_nextobject(p, bytesleft);
if((q == NULL) || !isdigit(*q)) {
cli_dbgmsg("cli_pdf: Generation number missing\n");
break;
}
/*generation_number = atoi(q);*/
bytesleft -= (off_t)(q - p);
p = q;
q = pdf_nextobject(p, bytesleft);
if((q == NULL) || (memcmp(q, "obj", 3) != 0)) {
cli_dbgmsg("cli_pdf: Indirect object missing \"obj\"\n");
break;
}
bytesleft -= (off_t)((q - p) + 3);
objstart = p = &q[3];
objend = cli_memstr(p, bytesleft, "endobj", 6);
if(objend == NULL) {
cli_dbgmsg("cli_pdf: No matching endobj\n");
break;
}
bytesleft -= (off_t)((objend - p) + 6);
p = &objend[6];
objlen = (unsigned long)(objend - objstart);
/* Is this object a stream? */
streamstart = cli_memstr(objstart, objlen, "stream", 6);
if(streamstart == NULL)
continue;
is_embedded_font = length = is_ascii85decode =
is_flatedecode = 0;
predictor = 1;
/*
* TODO: handle F and FFilter?
*/
q = objstart;
while(q < streamstart) {
if(*q == '/') { /* name object */
/*cli_dbgmsg("Name object %8.8s\n", q+1, q+1);*/
if(strncmp(++q, "Length ", 7) == 0) {
q += 7;
length = atoi(q);
while(isdigit(*q))
q++;
/*
* Note: incremental updates are not
* supported
*/
if((bytesleft > 11) && strncmp(q, " 0 R", 4) == 0) {
const char *r, *nq;
char b[14];
q += 4;
cli_dbgmsg("cli_pdf: Length is in indirect obj %lu\n",
length);
snprintf(b, sizeof(b),
"%lu 0 obj", length);
length = (unsigned long)strlen(b);
/* optimization: assume objects
* are sequential */
if(!opt_failed) {
nq = q;
len = buf + size - q;
} else {
nq = buf;
len = q - buf;
}
do {
r = cli_memstr(nq, len, b, length);
if (r > nq) {
const char x = *(r-1);
if (x == '\n' || x=='\r') {
--r;
break;
}
}
if (r) {
len -= r + length - nq;
nq = r + length;
} else if (!opt_failed) {
/* we failed optimized match,
* try matching from the beginning
*/
len = q - buf;
r = nq = buf;
/* prevent
* infloop */
opt_failed = 1;
}
} while (r);
if(r) {
r += length - 1;
r = pdf_nextobject(r, bytesleft - (r - q));
if(r) {
length = atoi(r);
while(isdigit(*r))
r++;
cli_dbgmsg("cli_pdf: length in '%s' %lu\n",
&b[1],
length);
}
} else
cli_dbgmsg("cli_pdf: Couldn't find '%s'\n",
&b[1]);
}
q--;
} else if(strncmp(q, "Length2 ", 8) == 0)
is_embedded_font = 1;
else if(strncmp(q, "Predictor ", 10) == 0) {
q += 10;
predictor = atoi(q);
while(isdigit(*q))
q++;
q--;
} else if(strncmp(q, "FlateDecode", 11) == 0) {
is_flatedecode = 1;
q += 11;
} else if(strncmp(q, "ASCII85Decode", 13) == 0) {
is_ascii85decode = 1;
q += 13;
}
}
q = pdf_nextobject(q, (size_t)(streamstart - q));
if(q == NULL)
break;
}
if(is_embedded_font) {
/*
* Need some documentation, the only I can find a
* reference to is not free, if some kind soul wishes
* to donate a copy, please contact me!
* (http://safari.adobepress.com/0321304748)
*/
if(!printed_embedded_font_message) {
cli_dbgmsg("cli_pdf: Embedded fonts not yet supported\n");
printed_embedded_font_message = 1;
}
continue;
}
if(predictor > 1) {
/*
* Needs some thought
*/
if(!printed_predictor_message) {
cli_dbgmsg("cli_pdf: Predictor %d not honoured for embedded image\n",
predictor);
printed_predictor_message = 1;
}
continue;
}
/* objend points to the end of the object (start of "endobj") */
streamstart += 6; /* go past the word "stream" */
len = (int)(objend - streamstart);
q = pdf_nextlinestart(streamstart, len);
if(q == NULL)
break;
len -= (int)(q - streamstart);
streamstart = q;
streamend = cli_memstr(streamstart, len, "endstream\n", 10);
if(streamend == NULL) {
streamend = cli_memstr(streamstart, len, "endstream\r", 10);
if(streamend == NULL) {
cli_dbgmsg("cli_pdf: No endstream\n");
break;
}
has_cr = 1;
} else
has_cr = 0;
snprintf(fullname, sizeof(fullname), "%s"PATHSEP"pdf%02u", dir, files);
fout = open(fullname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
if(fout < 0) {
char err[128];
cli_errmsg("cli_pdf: can't create temporary file %s: %s\n", fullname, cli_strerror(errno, err, sizeof(err)));
rc = CL_ETMPFILE;
break;
}
/*
* Calculate the length ourself, the Length parameter is often
* wrong
*/
if((*--streamend != '\n') && (*streamend != '\r'))
streamend++;
else if(has_cr && (*--streamend != '\r'))
streamend++;
if(streamend <= streamstart) {
close(fout);
cli_dbgmsg("cli_pdf: Empty stream\n");
if (cli_unlink(fullname)) {
rc = CL_EUNLINK;
break;
}
continue;
}
calculated_streamlen = (int)(streamend - streamstart);
real_streamlen = length;
cli_dbgmsg("cli_pdf: length %lu, calculated_streamlen %lu isFlate %d isASCII85 %d\n",
length, calculated_streamlen,
is_flatedecode, is_ascii85decode);
if(calculated_streamlen != real_streamlen) {
cli_dbgmsg("cli_pdf: Incorrect Length field in file attempting to recover\n");
if(real_streamlen > calculated_streamlen)
real_streamlen = calculated_streamlen;
}
#if 0
/* FIXME: this isn't right... */
if(length)
/*streamlen = (is_flatedecode) ? length : MIN(length, streamlen);*/
streamlen = MIN(length, streamlen);
#endif
if(is_ascii85decode) {
unsigned char *tmpbuf;
int ret = cli_checklimits("cli_pdf", ctx, calculated_streamlen * 5, calculated_streamlen, real_streamlen);
if(ret != CL_CLEAN) {
close(fout);
if (cli_unlink(fullname)) {
rc = CL_EUNLINK;
break;
}
continue;
}
tmpbuf = cli_malloc(calculated_streamlen * 5);
if(tmpbuf == NULL) {
close(fout);
if (cli_unlink(fullname)) {
rc = CL_EUNLINK;
break;
}
continue;
}
ret = ascii85decode(streamstart, calculated_streamlen, tmpbuf);
if(ret == -1) {
free(tmpbuf);
close(fout);
if (cli_unlink(fullname)) {
rc = CL_EUNLINK;
break;
}
continue;
}
if(ret) {
unsigned char *t;
real_streamlen = ret;
/* free unused trailing bytes */
t = (unsigned char *)cli_realloc(tmpbuf,calculated_streamlen);
if(t == NULL) {
free(tmpbuf);
close(fout);
if (cli_unlink(fullname)) {
rc = CL_EUNLINK;
break;
}
continue;
}
tmpbuf = t;
/*
* Note that it will probably be both
* ascii85encoded and flateencoded
*/
if(is_flatedecode)
rc = try_flatedecode((unsigned char *)tmpbuf, real_streamlen, real_streamlen, fout, ctx);
else
rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen)==real_streamlen ? CL_CLEAN : CL_EWRITE;
}
free(tmpbuf);
} else if(is_flatedecode) {
rc = try_flatedecode((unsigned char *)streamstart, real_streamlen, calculated_streamlen, fout, ctx);
} else {
cli_dbgmsg("cli_pdf: writing %lu bytes from the stream\n",
(unsigned long)real_streamlen);
if((rc = cli_checklimits("cli_pdf", ctx, real_streamlen, 0, 0))==CL_CLEAN)
rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen) == real_streamlen ? CL_CLEAN : CL_EWRITE;
}
if (rc == CL_CLEAN) {
cli_dbgmsg("cli_pdf: extracted file %u to %s\n", files, fullname);
files++;
lseek(fout, 0, SEEK_SET);
rc = cli_magic_scandesc(fout, ctx);
}
close(fout);
if(!ctx->engine->keeptmp)
if (cli_unlink(fullname)) rc = CL_EUNLINK;
if(rc != CL_CLEAN) break;
}
cli_dbgmsg("cli_pdf: returning %d\n", rc);
return rc;
} | 1 | [] | clamav-devel | f0eb394501ec21b9fe67f36cbf5db788711d4236 | 9,558,431,477,193,906,000,000,000,000,000,000,000 | 442 | bb #2016. |
int cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
{
struct pdf_struct pdf;
fmap_t *map = *ctx->fmap;
size_t size = map->len - offset;
off_t versize = size > 1032 ? 1032 : size;
off_t map_off, bytesleft;
long xref;
const char *pdfver, *start, *eofmap, *q, *eof;
int rc;
unsigned i;
cli_dbgmsg("in cli_pdf(%s)\n", dir);
memset(&pdf, 0, sizeof(pdf));
pdf.ctx = ctx;
pdf.dir = dir;
pdfver = start = fmap_need_off_once(map, offset, versize);
/* Check PDF version */
if (!pdfver) {
cli_errmsg("cli_pdf: mmap() failed (1)\n");
return CL_EMAP;
}
/* offset is 0 when coming from filetype2 */
pdfver = cli_memstr(pdfver, versize, "%PDF-", 5);
if (!pdfver) {
cli_dbgmsg("cli_pdf: no PDF- header found\n");
return CL_SUCCESS;
}
/* Check for PDF-1.[0-9]. Although 1.7 is highest now, allow for future
* versions */
if (pdfver[5] != '1' || pdfver[6] != '.' ||
pdfver[7] < '1' || pdfver[7] > '9') {
pdf.flags |= 1 << BAD_PDF_VERSION;
cli_dbgmsg("cli_pdf: bad pdf version: %.8s\n", pdfver);
}
if (pdfver != start || offset) {
pdf.flags |= 1 << BAD_PDF_HEADERPOS;
cli_dbgmsg("cli_pdf: PDF header is not at position 0: %ld\n",pdfver-start+offset);
}
offset += pdfver - start;
/* find trailer and xref, don't fail if not found */
map_off = map->len - 2048;
if (map_off < 0)
map_off = 0;
bytesleft = map->len - map_off;
eofmap = fmap_need_off_once(map, map_off, bytesleft);
if (!eofmap) {
cli_errmsg("cli_pdf: mmap() failed (2)\n");
return CL_EMAP;
}
eof = eofmap + bytesleft;
for (q=&eofmap[bytesleft-5]; q > eofmap; q--) {
if (memcmp(q, "%%EOF", 5) == 0)
break;
}
if (q <= eofmap) {
pdf.flags |= 1 << BAD_PDF_TRAILER;
cli_dbgmsg("cli_pdf: %%%%EOF not found\n");
} else {
size = q - eofmap + map_off;
for (;q > eofmap;q--) {
if (memcmp(q, "startxref", 9) == 0)
break;
}
if (q <= eofmap) {
pdf.flags |= 1 << BAD_PDF_TRAILER;
cli_dbgmsg("cli_pdf: startxref not found\n");
}
q += 9;
while (q < eof && (*q == ' ' || *q == '\n' || *q == '\r')) { q++; }
xref = atol(q);
bytesleft = map->len - offset - xref;
if (bytesleft > 4096)
bytesleft = 4096;
q = fmap_need_off_once(map, offset + xref, bytesleft);
if (!q || xrefCheck(q, q+bytesleft) == -1) {
cli_dbgmsg("cli_pdf: did not find valid xref\n");
pdf.flags |= 1 << BAD_PDF_TRAILER;
}
}
size -= offset;
pdf.size = size;
pdf.map = fmap_need_off_once(map, offset, size);
if (!pdf.map) {
cli_errmsg("cli_pdf: mmap() failed (3)\n");
return CL_EMAP;
}
/* parse PDF and find obj offsets */
while ((rc = pdf_findobj(&pdf)) > 0) {
struct pdf_obj *obj = &pdf.objs[pdf.nobjs-1];
cli_dbgmsg("found %d %d obj @%ld\n", obj->id >> 8, obj->id&0xff, obj->start + offset);
pdf_parseobj(&pdf, obj);
}
if (rc == -1)
pdf.flags |= 1 << BAD_PDF_TOOMANYOBJS;
/* extract PDF objs */
for (i=0;i<pdf.nobjs;i++) {
struct pdf_obj *obj = &pdf.objs[i];
rc = pdf_extract_obj(&pdf, obj);
if (rc != CL_SUCCESS)
break;
}
if (pdf.flags) {
cli_dbgmsg("cli_pdf: flags 0x%02x\n", pdf.flags);
if (pdf.flags & (1 << ESCAPED_COMMON_PDFNAME)) {
/* for example /Fl#61te#44#65#63#6f#64#65 instead of /FlateDecode */
*ctx->virname = "Heuristics.PDF.ObfuscatedNameObject";
rc = CL_VIRUS;
}
}
cli_dbgmsg("cli_pdf: returning %d\n", rc);
free(pdf.objs);
return rc;
} | 1 | [] | clamav-devel | f0eb394501ec21b9fe67f36cbf5db788711d4236 | 177,816,760,801,689,420,000,000,000,000,000,000,000 | 120 | bb #2016. |
retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
char **newloc, const char *refurl, int *dt, bool recursive,
struct iri *iri, bool register_status)
{
uerr_t result;
char *url;
bool location_changed;
bool iri_fallbacked = 0;
int dummy;
char *mynewloc, *proxy;
struct url *u = orig_parsed, *proxy_url;
int up_error_code; /* url parse error code */
char *local_file;
int redirection_count = 0;
bool post_data_suspended = false;
char *saved_post_data = NULL;
char *saved_post_file_name = NULL;
/* If dt is NULL, use local storage. */
if (!dt)
{
dt = &dummy;
dummy = 0;
}
url = xstrdup (origurl);
if (newloc)
*newloc = NULL;
if (file)
*file = NULL;
if (!refurl)
refurl = opt.referer;
redirected:
/* (also for IRI fallbacking) */
result = NOCONERROR;
mynewloc = NULL;
local_file = NULL;
proxy_url = NULL;
proxy = getproxy (u);
if (proxy)
{
struct iri *pi = iri_new ();
set_uri_encoding (pi, opt.locale, true);
pi->utf8_encode = false;
/* Parse the proxy URL. */
proxy_url = url_parse (proxy, &up_error_code, NULL, true);
if (!proxy_url)
{
char *error = url_error (proxy, up_error_code);
logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
proxy, error);
xfree (url);
xfree (error);
RESTORE_POST_DATA;
result = PROXERR;
goto bail;
}
if (proxy_url->scheme != SCHEME_HTTP && proxy_url->scheme != u->scheme)
{
logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
url_free (proxy_url);
xfree (url);
RESTORE_POST_DATA;
result = PROXERR;
goto bail;
}
}
if (u->scheme == SCHEME_HTTP
#ifdef HAVE_SSL
|| u->scheme == SCHEME_HTTPS
#endif
|| (proxy_url && proxy_url->scheme == SCHEME_HTTP))
{
result = http_loop (u, &mynewloc, &local_file, refurl, dt, proxy_url, iri);
}
else if (u->scheme == SCHEME_FTP)
{
/* If this is a redirection, temporarily turn off opt.ftp_glob
and opt.recursive, both being undesirable when following
redirects. */
bool oldrec = recursive, glob = opt.ftp_glob;
if (redirection_count)
oldrec = glob = false;
result = ftp_loop (u, &local_file, dt, proxy_url, recursive, glob);
recursive = oldrec;
/* There is a possibility of having HTTP being redirected to
FTP. In these cases we must decide whether the text is HTML
according to the suffix. The HTML suffixes are `.html',
`.htm' and a few others, case-insensitive. */
if (redirection_count && local_file && u->scheme == SCHEME_FTP)
{
if (has_html_suffix_p (local_file))
*dt |= TEXTHTML;
}
}
if (proxy_url)
{
url_free (proxy_url);
proxy_url = NULL;
}
location_changed = (result == NEWLOCATION);
if (location_changed)
{
char *construced_newloc;
struct url *newloc_parsed;
assert (mynewloc != NULL);
if (local_file)
xfree (local_file);
/* The HTTP specs only allow absolute URLs to appear in
redirects, but a ton of boneheaded webservers and CGIs out
there break the rules and use relative URLs, and popular
browsers are lenient about this, so wget should be too. */
construced_newloc = uri_merge (url, mynewloc);
xfree (mynewloc);
mynewloc = construced_newloc;
/* Reset UTF-8 encoding state, keep the URI encoding and reset
the content encoding. */
iri->utf8_encode = opt.enable_iri;
set_content_encoding (iri, NULL);
xfree_null (iri->orig_url);
/* Now, see if this new location makes sense. */
newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
if (!newloc_parsed)
{
char *error = url_error (mynewloc, up_error_code);
logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
error);
if (orig_parsed != u)
{
url_free (u);
}
xfree (url);
xfree (mynewloc);
xfree (error);
RESTORE_POST_DATA;
goto bail;
}
/* Now mynewloc will become newloc_parsed->url, because if the
Location contained relative paths like .././something, we
don't want that propagating as url. */
xfree (mynewloc);
mynewloc = xstrdup (newloc_parsed->url);
/* Check for max. number of redirections. */
if (++redirection_count > opt.max_redirect)
{
logprintf (LOG_NOTQUIET, _("%d redirections exceeded.\n"),
opt.max_redirect);
url_free (newloc_parsed);
if (orig_parsed != u)
{
url_free (u);
}
xfree (url);
xfree (mynewloc);
RESTORE_POST_DATA;
result = WRONGCODE;
goto bail;
}
xfree (url);
url = mynewloc;
if (orig_parsed != u)
{
url_free (u);
}
u = newloc_parsed;
/* If we're being redirected from POST, we don't want to POST
again. Many requests answer POST with a redirection to an
index page; that redirection is clearly a GET. We "suspend"
POST data for the duration of the redirections, and restore
it when we're done. */
if (!post_data_suspended)
SUSPEND_POST_DATA;
goto redirected;
}
/* Try to not encode in UTF-8 if fetching failed */
if (!(*dt & RETROKF) && iri->utf8_encode)
{
iri->utf8_encode = false;
if (orig_parsed != u)
{
url_free (u);
}
u = url_parse (origurl, NULL, iri, true);
if (u)
{
DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
url = xstrdup (u->url);
iri_fallbacked = 1;
goto redirected;
}
else
DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url)));
}
if (local_file && *dt & RETROKF)
{
register_download (u->url, local_file);
if (redirection_count && 0 != strcmp (origurl, u->url))
register_redirection (origurl, u->url);
if (*dt & TEXTHTML)
register_html (u->url, local_file);
if (*dt & RETROKF)
{
register_download (u->url, local_file);
if (redirection_count && 0 != strcmp (origurl, u->url))
register_redirection (origurl, u->url);
if (*dt & TEXTHTML)
register_html (u->url, local_file);
if (*dt & TEXTCSS)
register_css (u->url, local_file);
}
}
if (file)
*file = local_file ? local_file : NULL;
else
xfree_null (local_file);
if (orig_parsed != u)
{
url_free (u);
}
if (redirection_count || iri_fallbacked)
{
if (newloc)
*newloc = url;
else
xfree (url);
}
else
{
if (newloc)
*newloc = NULL;
xfree (url);
}
RESTORE_POST_DATA;
bail:
if (register_status)
inform_exit_status (result);
return result;
} | 1 | [
"CWE-20"
] | wget | 3e25a9817f47fbb8660cc6a3b2f3eea239526c6c | 308,507,981,451,037,930,000,000,000,000,000,000,000 | 265 | Introduce --trust-server-names. Close CVE-2010-2252. |
print_help (void)
{
/* We split the help text this way to ease translation of individual
entries. */
static const char *help[] = {
"\n",
N_("\
Mandatory arguments to long options are mandatory for short options too.\n\n"),
N_("\
Startup:\n"),
N_("\
-V, --version display the version of Wget and exit.\n"),
N_("\
-h, --help print this help.\n"),
N_("\
-b, --background go to background after startup.\n"),
N_("\
-e, --execute=COMMAND execute a `.wgetrc'-style command.\n"),
"\n",
N_("\
Logging and input file:\n"),
N_("\
-o, --output-file=FILE log messages to FILE.\n"),
N_("\
-a, --append-output=FILE append messages to FILE.\n"),
#ifdef ENABLE_DEBUG
N_("\
-d, --debug print lots of debugging information.\n"),
#endif
#ifdef USE_WATT32
N_("\
--wdebug print Watt-32 debug output.\n"),
#endif
N_("\
-q, --quiet quiet (no output).\n"),
N_("\
-v, --verbose be verbose (this is the default).\n"),
N_("\
-nv, --no-verbose turn off verboseness, without being quiet.\n"),
N_("\
-i, --input-file=FILE download URLs found in local or external FILE.\n"),
N_("\
-F, --force-html treat input file as HTML.\n"),
N_("\
-B, --base=URL resolves HTML input-file links (-i -F)\n\
relative to URL.\n"),
"\n",
N_("\
Download:\n"),
N_("\
-t, --tries=NUMBER set number of retries to NUMBER (0 unlimits).\n"),
N_("\
--retry-connrefused retry even if connection is refused.\n"),
N_("\
-O, --output-document=FILE write documents to FILE.\n"),
N_("\
-nc, --no-clobber skip downloads that would download to\n\
existing files.\n"),
N_("\
-c, --continue resume getting a partially-downloaded file.\n"),
N_("\
--progress=TYPE select progress gauge type.\n"),
N_("\
-N, --timestamping don't re-retrieve files unless newer than\n\
local.\n"),
N_("\
--no-use-server-timestamps don't set the local file's timestamp by\n\
the one on the server.\n"),
N_("\
-S, --server-response print server response.\n"),
N_("\
--spider don't download anything.\n"),
N_("\
-T, --timeout=SECONDS set all timeout values to SECONDS.\n"),
N_("\
--dns-timeout=SECS set the DNS lookup timeout to SECS.\n"),
N_("\
--connect-timeout=SECS set the connect timeout to SECS.\n"),
N_("\
--read-timeout=SECS set the read timeout to SECS.\n"),
N_("\
-w, --wait=SECONDS wait SECONDS between retrievals.\n"),
N_("\
--waitretry=SECONDS wait 1..SECONDS between retries of a retrieval.\n"),
N_("\
--random-wait wait from 0.5*WAIT...1.5*WAIT secs between retrievals.\n"),
N_("\
--no-proxy explicitly turn off proxy.\n"),
N_("\
-Q, --quota=NUMBER set retrieval quota to NUMBER.\n"),
N_("\
--bind-address=ADDRESS bind to ADDRESS (hostname or IP) on local host.\n"),
N_("\
--limit-rate=RATE limit download rate to RATE.\n"),
N_("\
--no-dns-cache disable caching DNS lookups.\n"),
N_("\
--restrict-file-names=OS restrict chars in file names to ones OS allows.\n"),
N_("\
--ignore-case ignore case when matching files/directories.\n"),
#ifdef ENABLE_IPV6
N_("\
-4, --inet4-only connect only to IPv4 addresses.\n"),
N_("\
-6, --inet6-only connect only to IPv6 addresses.\n"),
N_("\
--prefer-family=FAMILY connect first to addresses of specified family,\n\
one of IPv6, IPv4, or none.\n"),
#endif
N_("\
--user=USER set both ftp and http user to USER.\n"),
N_("\
--password=PASS set both ftp and http password to PASS.\n"),
N_("\
--ask-password prompt for passwords.\n"),
N_("\
--no-iri turn off IRI support.\n"),
N_("\
--local-encoding=ENC use ENC as the local encoding for IRIs.\n"),
N_("\
--remote-encoding=ENC use ENC as the default remote encoding.\n"),
"\n",
N_("\
Directories:\n"),
N_("\
-nd, --no-directories don't create directories.\n"),
N_("\
-x, --force-directories force creation of directories.\n"),
N_("\
-nH, --no-host-directories don't create host directories.\n"),
N_("\
--protocol-directories use protocol name in directories.\n"),
N_("\
-P, --directory-prefix=PREFIX save files to PREFIX/...\n"),
N_("\
--cut-dirs=NUMBER ignore NUMBER remote directory components.\n"),
"\n",
N_("\
HTTP options:\n"),
N_("\
--http-user=USER set http user to USER.\n"),
N_("\
--http-password=PASS set http password to PASS.\n"),
N_("\
--no-cache disallow server-cached data.\n"),
N_ ("\
--default-page=NAME Change the default page name (normally\n\
this is `index.html'.).\n"),
N_("\
-E, --adjust-extension save HTML/CSS documents with proper extensions.\n"),
N_("\
--ignore-length ignore `Content-Length' header field.\n"),
N_("\
--header=STRING insert STRING among the headers.\n"),
N_("\
--max-redirect maximum redirections allowed per page.\n"),
N_("\
--proxy-user=USER set USER as proxy username.\n"),
N_("\
--proxy-password=PASS set PASS as proxy password.\n"),
N_("\
--referer=URL include `Referer: URL' header in HTTP request.\n"),
N_("\
--save-headers save the HTTP headers to file.\n"),
N_("\
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n"),
N_("\
--no-http-keep-alive disable HTTP keep-alive (persistent connections).\n"),
N_("\
--no-cookies don't use cookies.\n"),
N_("\
--load-cookies=FILE load cookies from FILE before session.\n"),
N_("\
--save-cookies=FILE save cookies to FILE after session.\n"),
N_("\
--keep-session-cookies load and save session (non-permanent) cookies.\n"),
N_("\
--post-data=STRING use the POST method; send STRING as the data.\n"),
N_("\
--post-file=FILE use the POST method; send contents of FILE.\n"),
N_("\
--content-disposition honor the Content-Disposition header when\n\
choosing local file names (EXPERIMENTAL).\n"),
N_("\
--auth-no-challenge send Basic HTTP authentication information\n\
without first waiting for the server's\n\
challenge.\n"),
"\n",
#ifdef HAVE_SSL
N_("\
HTTPS (SSL/TLS) options:\n"),
N_("\
--secure-protocol=PR choose secure protocol, one of auto, SSLv2,\n\
SSLv3, and TLSv1.\n"),
N_("\
--no-check-certificate don't validate the server's certificate.\n"),
N_("\
--certificate=FILE client certificate file.\n"),
N_("\
--certificate-type=TYPE client certificate type, PEM or DER.\n"),
N_("\
--private-key=FILE private key file.\n"),
N_("\
--private-key-type=TYPE private key type, PEM or DER.\n"),
N_("\
--ca-certificate=FILE file with the bundle of CA's.\n"),
N_("\
--ca-directory=DIR directory where hash list of CA's is stored.\n"),
N_("\
--random-file=FILE file with random data for seeding the SSL PRNG.\n"),
N_("\
--egd-file=FILE file naming the EGD socket with random data.\n"),
"\n",
#endif /* HAVE_SSL */
N_("\
FTP options:\n"),
#ifdef __VMS
N_("\
--ftp-stmlf Use Stream_LF format for all binary FTP files.\n"),
#endif /* def __VMS */
N_("\
--ftp-user=USER set ftp user to USER.\n"),
N_("\
--ftp-password=PASS set ftp password to PASS.\n"),
N_("\
--no-remove-listing don't remove `.listing' files.\n"),
N_("\
--no-glob turn off FTP file name globbing.\n"),
N_("\
--no-passive-ftp disable the \"passive\" transfer mode.\n"),
N_("\
--retr-symlinks when recursing, get linked-to files (not dir).\n"),
"\n",
N_("\
Recursive download:\n"),
N_("\
-r, --recursive specify recursive download.\n"),
N_("\
-l, --level=NUMBER maximum recursion depth (inf or 0 for infinite).\n"),
N_("\
--delete-after delete files locally after downloading them.\n"),
N_("\
-k, --convert-links make links in downloaded HTML or CSS point to\n\
local files.\n"),
#ifdef __VMS
N_("\
-K, --backup-converted before converting file X, back up as X_orig.\n"),
#else /* def __VMS */
N_("\
-K, --backup-converted before converting file X, back up as X.orig.\n"),
#endif /* def __VMS [else] */
N_("\
-m, --mirror shortcut for -N -r -l inf --no-remove-listing.\n"),
N_("\
-p, --page-requisites get all images, etc. needed to display HTML page.\n"),
N_("\
--strict-comments turn on strict (SGML) handling of HTML comments.\n"),
"\n",
N_("\
Recursive accept/reject:\n"),
N_("\
-A, --accept=LIST comma-separated list of accepted extensions.\n"),
N_("\
-R, --reject=LIST comma-separated list of rejected extensions.\n"),
N_("\
-D, --domains=LIST comma-separated list of accepted domains.\n"),
N_("\
--exclude-domains=LIST comma-separated list of rejected domains.\n"),
N_("\
--follow-ftp follow FTP links from HTML documents.\n"),
N_("\
--follow-tags=LIST comma-separated list of followed HTML tags.\n"),
N_("\
--ignore-tags=LIST comma-separated list of ignored HTML tags.\n"),
N_("\
-H, --span-hosts go to foreign hosts when recursive.\n"),
N_("\
-L, --relative follow relative links only.\n"),
N_("\
-I, --include-directories=LIST list of allowed directories.\n"),
N_("\
-X, --exclude-directories=LIST list of excluded directories.\n"),
N_("\
-np, --no-parent don't ascend to the parent directory.\n"),
"\n",
N_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n")
};
size_t i;
printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
version_string);
print_usage (0);
for (i = 0; i < countof (help); i++)
fputs (_(help[i]), stdout);
exit (0);
} | 1 | [
"CWE-20"
] | wget | 3e25a9817f47fbb8660cc6a3b2f3eea239526c6c | 231,552,610,299,097,700,000,000,000,000,000,000,000 | 308 | Introduce --trust-server-names. Close CVE-2010-2252. |
http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
int *dt, struct url *proxy, struct iri *iri)
{
int count;
bool got_head = false; /* used for time-stamping and filename detection */
bool time_came_from_head = false;
bool got_name = false;
char *tms;
const char *tmrate;
uerr_t err, ret = TRYLIMEXC;
time_t tmr = -1; /* remote time-stamp */
struct http_stat hstat; /* HTTP status */
struct_stat st;
bool send_head_first = true;
char *file_name;
bool force_full_retrieve = false;
/* Assert that no value for *LOCAL_FILE was passed. */
assert (local_file == NULL || *local_file == NULL);
/* Set LOCAL_FILE parameter. */
if (local_file && opt.output_document)
*local_file = HYPHENP (opt.output_document) ? NULL : xstrdup (opt.output_document);
/* Reset NEWLOC parameter. */
*newloc = NULL;
/* This used to be done in main(), but it's a better idea to do it
here so that we don't go through the hoops if we're just using
FTP or whatever. */
if (opt.cookies)
load_cookies ();
/* Warn on (likely bogus) wildcard usage in HTTP. */
if (opt.ftp_glob && has_wildcards_p (u->path))
logputs (LOG_VERBOSE, _("Warning: wildcards not supported in HTTP.\n"));
/* Setup hstat struct. */
xzero (hstat);
hstat.referer = referer;
if (opt.output_document)
{
hstat.local_file = xstrdup (opt.output_document);
got_name = true;
}
else if (!opt.content_disposition)
{
hstat.local_file = url_file_name (u);
got_name = true;
}
/* TODO: Ick! This code is now in both gethttp and http_loop, and is
* screaming for some refactoring. */
if (got_name && file_exists_p (hstat.local_file) && opt.noclobber && !opt.output_document)
{
/* If opt.noclobber is turned on and file already exists, do not
retrieve the file. But if the output_document was given, then this
test was already done and the file didn't exist. Hence the !opt.output_document */
logprintf (LOG_VERBOSE, _("\
File %s already there; not retrieving.\n\n"),
quote (hstat.local_file));
/* If the file is there, we suppose it's retrieved OK. */
*dt |= RETROKF;
/* #### Bogusness alert. */
/* If its suffix is "html" or "htm" or similar, assume text/html. */
if (has_html_suffix_p (hstat.local_file))
*dt |= TEXTHTML;
ret = RETROK;
goto exit;
}
/* Reset the counter. */
count = 0;
/* Reset the document type. */
*dt = 0;
/* Skip preliminary HEAD request if we're not in spider mode. */
if (!opt.spider)
send_head_first = false;
/* Send preliminary HEAD request if -N is given and we have an existing
* destination file. */
file_name = url_file_name (u);
if (opt.timestamping && (file_exists_p (file_name)
|| opt.content_disposition))
send_head_first = true;
xfree (file_name);
/* THE loop */
do
{
/* Increment the pass counter. */
++count;
sleep_between_retrievals (count);
/* Get the current time string. */
tms = datetime_str (time (NULL));
if (opt.spider && !got_head)
logprintf (LOG_VERBOSE, _("\
Spider mode enabled. Check if remote file exists.\n"));
/* Print fetch message, if opt.verbose. */
if (opt.verbose)
{
char *hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
if (count > 1)
{
char tmp[256];
sprintf (tmp, _("(try:%2d)"), count);
logprintf (LOG_NOTQUIET, "--%s-- %s %s\n",
tms, tmp, hurl);
}
else
{
logprintf (LOG_NOTQUIET, "--%s-- %s\n",
tms, hurl);
}
#ifdef WINDOWS
ws_changetitle (hurl);
#endif
xfree (hurl);
}
/* Default document type is empty. However, if spider mode is
on or time-stamping is employed, HEAD_ONLY commands is
encoded within *dt. */
if (send_head_first && !got_head)
*dt |= HEAD_ONLY;
else
*dt &= ~HEAD_ONLY;
/* Decide whether or not to restart. */
if (force_full_retrieve)
hstat.restval = hstat.len;
else if (opt.always_rest
&& got_name
&& stat (hstat.local_file, &st) == 0
&& S_ISREG (st.st_mode))
/* When -c is used, continue from on-disk size. (Can't use
hstat.len even if count>1 because we don't want a failed
first attempt to clobber existing data.) */
hstat.restval = st.st_size;
else if (count > 1)
/* otherwise, continue where the previous try left off */
hstat.restval = hstat.len;
else
hstat.restval = 0;
/* Decide whether to send the no-cache directive. We send it in
two cases:
a) we're using a proxy, and we're past our first retrieval.
Some proxies are notorious for caching incomplete data, so
we require a fresh get.
b) caching is explicitly inhibited. */
if ((proxy && count > 1) /* a */
|| !opt.allow_cache) /* b */
*dt |= SEND_NOCACHE;
else
*dt &= ~SEND_NOCACHE;
/* Try fetching the document, or at least its head. */
err = gethttp (u, &hstat, dt, proxy, iri);
/* Time? */
tms = datetime_str (time (NULL));
/* Get the new location (with or without the redirection). */
if (hstat.newloc)
*newloc = xstrdup (hstat.newloc);
switch (err)
{
case HERR: case HEOF: case CONSOCKERR: case CONCLOSED:
case CONERROR: case READERR: case WRITEFAILED:
case RANGEERR: case FOPEN_EXCL_ERR:
/* Non-fatal errors continue executing the loop, which will
bring them to "while" statement at the end, to judge
whether the number of tries was exceeded. */
printwhat (count, opt.ntry);
continue;
case FWRITEERR: case FOPENERR:
/* Another fatal error. */
logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("Cannot write to %s (%s).\n"),
quote (hstat.local_file), strerror (errno));
case HOSTERR: case CONIMPOSSIBLE: case PROXERR: case AUTHFAILED:
case SSLINITFAILED: case CONTNOTSUPPORTED: case VERIFCERTERR:
/* Fatal errors just return from the function. */
ret = err;
goto exit;
case CONSSLERR:
/* Another fatal error. */
logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
ret = err;
goto exit;
case NEWLOCATION:
/* Return the new location to the caller. */
if (!*newloc)
{
logprintf (LOG_NOTQUIET,
_("ERROR: Redirection (%d) without location.\n"),
hstat.statcode);
ret = WRONGCODE;
}
else
{
ret = NEWLOCATION;
}
goto exit;
case RETRUNNEEDED:
/* The file was already fully retrieved. */
ret = RETROK;
goto exit;
case RETRFINISHED:
/* Deal with you later. */
break;
default:
/* All possibilities should have been exhausted. */
abort ();
}
if (!(*dt & RETROKF))
{
char *hurl = NULL;
if (!opt.verbose)
{
/* #### Ugly ugly ugly! */
hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
logprintf (LOG_NONVERBOSE, "%s:\n", hurl);
}
/* Fall back to GET if HEAD fails with a 500 or 501 error code. */
if (*dt & HEAD_ONLY
&& (hstat.statcode == 500 || hstat.statcode == 501))
{
got_head = true;
continue;
}
/* Maybe we should always keep track of broken links, not just in
* spider mode.
* Don't log error if it was UTF-8 encoded because we will try
* once unencoded. */
else if (opt.spider && !iri->utf8_encode)
{
/* #### Again: ugly ugly ugly! */
if (!hurl)
hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
nonexisting_url (hurl);
logprintf (LOG_NOTQUIET, _("\
Remote file does not exist -- broken link!!!\n"));
}
else
{
logprintf (LOG_NOTQUIET, _("%s ERROR %d: %s.\n"),
tms, hstat.statcode,
quotearg_style (escape_quoting_style, hstat.error));
}
logputs (LOG_VERBOSE, "\n");
ret = WRONGCODE;
xfree_null (hurl);
goto exit;
}
/* Did we get the time-stamp? */
if (!got_head)
{
got_head = true; /* no more time-stamping */
if (opt.timestamping && !hstat.remote_time)
{
logputs (LOG_NOTQUIET, _("\
Last-modified header missing -- time-stamps turned off.\n"));
}
else if (hstat.remote_time)
{
/* Convert the date-string into struct tm. */
tmr = http_atotm (hstat.remote_time);
if (tmr == (time_t) (-1))
logputs (LOG_VERBOSE, _("\
Last-modified header invalid -- time-stamp ignored.\n"));
if (*dt & HEAD_ONLY)
time_came_from_head = true;
}
if (send_head_first)
{
/* The time-stamping section. */
if (opt.timestamping)
{
if (hstat.orig_file_name) /* Perform the following
checks only if the file
we're supposed to
download already exists. */
{
if (hstat.remote_time &&
tmr != (time_t) (-1))
{
/* Now time-stamping can be used validly.
Time-stamping means that if the sizes of
the local and remote file match, and local
file is newer than the remote file, it will
not be retrieved. Otherwise, the normal
download procedure is resumed. */
if (hstat.orig_file_tstamp >= tmr)
{
if (hstat.contlen == -1
|| hstat.orig_file_size == hstat.contlen)
{
logprintf (LOG_VERBOSE, _("\
Server file no newer than local file %s -- not retrieving.\n\n"),
quote (hstat.orig_file_name));
ret = RETROK;
goto exit;
}
else
{
logprintf (LOG_VERBOSE, _("\
The sizes do not match (local %s) -- retrieving.\n"),
number_to_static_string (hstat.orig_file_size));
}
}
else
{
force_full_retrieve = true;
logputs (LOG_VERBOSE,
_("Remote file is newer, retrieving.\n"));
}
logputs (LOG_VERBOSE, "\n");
}
}
/* free_hstat (&hstat); */
hstat.timestamp_checked = true;
}
if (opt.spider)
{
bool finished = true;
if (opt.recursive)
{
if (*dt & TEXTHTML)
{
logputs (LOG_VERBOSE, _("\
Remote file exists and could contain links to other resources -- retrieving.\n\n"));
finished = false;
}
else
{
logprintf (LOG_VERBOSE, _("\
Remote file exists but does not contain any link -- not retrieving.\n\n"));
ret = RETROK; /* RETRUNNEEDED is not for caller. */
}
}
else
{
if (*dt & TEXTHTML)
{
logprintf (LOG_VERBOSE, _("\
Remote file exists and could contain further links,\n\
but recursion is disabled -- not retrieving.\n\n"));
}
else
{
logprintf (LOG_VERBOSE, _("\
Remote file exists.\n\n"));
}
ret = RETROK; /* RETRUNNEEDED is not for caller. */
}
if (finished)
{
logprintf (LOG_NONVERBOSE,
_("%s URL: %s %2d %s\n"),
tms, u->url, hstat.statcode,
hstat.message ? quotearg_style (escape_quoting_style, hstat.message) : "");
goto exit;
}
}
got_name = true;
*dt &= ~HEAD_ONLY;
count = 0; /* the retrieve count for HEAD is reset */
continue;
} /* send_head_first */
} /* !got_head */
if (opt.useservertimestamps
&& (tmr != (time_t) (-1))
&& ((hstat.len == hstat.contlen) ||
((hstat.res == 0) && (hstat.contlen == -1))))
{
const char *fl = NULL;
set_local_file (&fl, hstat.local_file);
if (fl)
{
time_t newtmr = -1;
/* Reparse time header, in case it's changed. */
if (time_came_from_head
&& hstat.remote_time && hstat.remote_time[0])
{
newtmr = http_atotm (hstat.remote_time);
if (newtmr != (time_t)-1)
tmr = newtmr;
}
touch (fl, tmr);
}
}
/* End of time-stamping section. */
tmrate = retr_rate (hstat.rd_size, hstat.dltime);
total_download_time += hstat.dltime;
if (hstat.len == hstat.contlen)
{
if (*dt & RETROKF)
{
bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
logprintf (LOG_VERBOSE,
write_to_stdout
? _("%s (%s) - written to stdout %s[%s/%s]\n\n")
: _("%s (%s) - %s saved [%s/%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (hstat.local_file),
number_to_static_string (hstat.len),
number_to_static_string (hstat.contlen));
logprintf (LOG_NONVERBOSE,
"%s URL:%s [%s/%s] -> \"%s\" [%d]\n",
tms, u->url,
number_to_static_string (hstat.len),
number_to_static_string (hstat.contlen),
hstat.local_file, count);
}
++numurls;
total_downloaded_bytes += hstat.rd_size;
/* Remember that we downloaded the file for later ".orig" code. */
if (*dt & ADDED_HTML_EXTENSION)
downloaded_file(FILE_DOWNLOADED_AND_HTML_EXTENSION_ADDED, hstat.local_file);
else
downloaded_file(FILE_DOWNLOADED_NORMALLY, hstat.local_file);
ret = RETROK;
goto exit;
}
else if (hstat.res == 0) /* No read error */
{
if (hstat.contlen == -1) /* We don't know how much we were supposed
to get, so assume we succeeded. */
{
if (*dt & RETROKF)
{
bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
logprintf (LOG_VERBOSE,
write_to_stdout
? _("%s (%s) - written to stdout %s[%s]\n\n")
: _("%s (%s) - %s saved [%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (hstat.local_file),
number_to_static_string (hstat.len));
logprintf (LOG_NONVERBOSE,
"%s URL:%s [%s] -> \"%s\" [%d]\n",
tms, u->url, number_to_static_string (hstat.len),
hstat.local_file, count);
}
++numurls;
total_downloaded_bytes += hstat.rd_size;
/* Remember that we downloaded the file for later ".orig" code. */
if (*dt & ADDED_HTML_EXTENSION)
downloaded_file(FILE_DOWNLOADED_AND_HTML_EXTENSION_ADDED, hstat.local_file);
else
downloaded_file(FILE_DOWNLOADED_NORMALLY, hstat.local_file);
ret = RETROK;
goto exit;
}
else if (hstat.len < hstat.contlen) /* meaning we lost the
connection too soon */
{
logprintf (LOG_VERBOSE,
_("%s (%s) - Connection closed at byte %s. "),
tms, tmrate, number_to_static_string (hstat.len));
printwhat (count, opt.ntry);
continue;
}
else if (hstat.len != hstat.restval)
/* Getting here would mean reading more data than
requested with content-length, which we never do. */
abort ();
else
{
/* Getting here probably means that the content-length was
* _less_ than the original, local size. We should probably
* truncate or re-read, or something. FIXME */
ret = RETROK;
goto exit;
}
}
else /* from now on hstat.res can only be -1 */
{
if (hstat.contlen == -1)
{
logprintf (LOG_VERBOSE,
_("%s (%s) - Read error at byte %s (%s)."),
tms, tmrate, number_to_static_string (hstat.len),
hstat.rderrmsg);
printwhat (count, opt.ntry);
continue;
}
else /* hstat.res == -1 and contlen is given */
{
logprintf (LOG_VERBOSE,
_("%s (%s) - Read error at byte %s/%s (%s). "),
tms, tmrate,
number_to_static_string (hstat.len),
number_to_static_string (hstat.contlen),
hstat.rderrmsg);
printwhat (count, opt.ntry);
continue;
}
}
/* not reached */
}
while (!opt.ntry || (count < opt.ntry));
exit:
if (ret == RETROK)
*local_file = xstrdup (hstat.local_file);
free_hstat (&hstat);
return ret;
} | 1 | [
"CWE-20"
] | wget | 3e25a9817f47fbb8660cc6a3b2f3eea239526c6c | 123,054,588,746,694,250,000,000,000,000,000,000,000 | 542 | Introduce --trust-server-names. Close CVE-2010-2252. |
ftp_loop (struct url *u, char **local_file, int *dt, struct url *proxy,
bool recursive, bool glob)
{
ccon con; /* FTP connection */
uerr_t res;
*dt = 0;
xzero (con);
con.csock = -1;
con.st = ON_YOUR_OWN;
con.rs = ST_UNIX;
con.id = NULL;
con.proxy = proxy;
/* If the file name is empty, the user probably wants a directory
index. We'll provide one, properly HTML-ized. Unless
opt.htmlify is 0, of course. :-) */
if (!*u->file && !recursive)
{
struct fileinfo *f;
res = ftp_get_listing (u, &con, &f);
if (res == RETROK)
{
if (opt.htmlify && !opt.spider)
{
char *filename = (opt.output_document
? xstrdup (opt.output_document)
: (con.target ? xstrdup (con.target)
: url_file_name (u)));
res = ftp_index (filename, u, f);
if (res == FTPOK && opt.verbose)
{
if (!opt.output_document)
{
struct_stat st;
wgint sz;
if (stat (filename, &st) == 0)
sz = st.st_size;
else
sz = -1;
logprintf (LOG_NOTQUIET,
_("Wrote HTML-ized index to %s [%s].\n"),
quote (filename), number_to_static_string (sz));
}
else
logprintf (LOG_NOTQUIET,
_("Wrote HTML-ized index to %s.\n"),
quote (filename));
}
xfree (filename);
}
freefileinfo (f);
}
}
else
{
bool ispattern = false;
if (glob)
{
/* Treat the URL as a pattern if the file name part of the
URL path contains wildcards. (Don't check for u->file
because it is unescaped and therefore doesn't leave users
the option to escape literal '*' as %2A.) */
char *file_part = strrchr (u->path, '/');
if (!file_part)
file_part = u->path;
ispattern = has_wildcards_p (file_part);
}
if (ispattern || recursive || opt.timestamping)
{
/* ftp_retrieve_glob is a catch-all function that gets called
if we need globbing, time-stamping or recursion. Its
third argument is just what we really need. */
res = ftp_retrieve_glob (u, &con,
ispattern ? GLOB_GLOBALL : GLOB_GETONE);
}
else
res = ftp_loop_internal (u, NULL, &con, local_file);
}
if (res == FTPOK)
res = RETROK;
if (res == RETROK)
*dt |= RETROKF;
/* If a connection was left, quench it. */
if (con.csock != -1)
fd_close (con.csock);
xfree_null (con.id);
con.id = NULL;
xfree_null (con.target);
con.target = NULL;
return res;
} | 1 | [
"CWE-20"
] | wget | 3e25a9817f47fbb8660cc6a3b2f3eea239526c6c | 173,197,912,256,458,500,000,000,000,000,000,000,000 | 95 | Introduce --trust-server-names. Close CVE-2010-2252. |
static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
void __user *useraddr)
{
struct ethtool_rxnfc info;
const struct ethtool_ops *ops = dev->ethtool_ops;
int ret;
void *rule_buf = NULL;
if (!ops->get_rxnfc)
return -EOPNOTSUPP;
if (copy_from_user(&info, useraddr, sizeof(info)))
return -EFAULT;
if (info.cmd == ETHTOOL_GRXCLSRLALL) {
if (info.rule_cnt > 0) {
rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
GFP_USER);
if (!rule_buf)
return -ENOMEM;
}
}
ret = ops->get_rxnfc(dev, &info, rule_buf);
if (ret < 0)
goto err_out;
ret = -EFAULT;
if (copy_to_user(useraddr, &info, sizeof(info)))
goto err_out;
if (rule_buf) {
useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
if (copy_to_user(useraddr, rule_buf,
info.rule_cnt * sizeof(u32)))
goto err_out;
}
ret = 0;
err_out:
kfree(rule_buf);
return ret;
} | 1 | [
"CWE-190"
] | linux-2.6 | db048b69037e7fa6a7d9e95a1271a50dc08ae233 | 256,352,693,318,403,330,000,000,000,000,000,000,000 | 44 | ethtool: Fix potential kernel buffer overflow in ETHTOOL_GRXCLSRLALL
On a 32-bit machine, info.rule_cnt >= 0x40000000 leads to integer
overflow and the buffer may be smaller than needed. Since
ETHTOOL_GRXCLSRLALL is unprivileged, this can presumably be used for at
least denial of service.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Cc: stable@kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net> |
void Server::msgQueryUsers(ServerUser *uSource, MumbleProto::QueryUsers &msg) {
MSG_SETUP(ServerUser::Authenticated);
MumbleProto::QueryUsers reply;
for (int i=0;i<msg.ids_size();++i) {
int id = msg.ids(i);
if (id >= 0) {
const QString &name = getUserName(id);
if (! name.isEmpty()) {
reply.add_ids(id);
reply.add_names(u8(name));
}
}
}
for (int i=0;i<msg.names_size();++i) {
QString name = u8(msg.names(i));
int id = getUserID(name);
if (id >= 0) {
name = getUserName(id);
reply.add_ids(id);
reply.add_names(u8(name));
}
}
sendMessage(uSource, reply);
} | 1 | [
"CWE-20"
] | mumble | 6b33dda344f89e5a039b7d79eb43925040654242 | 196,009,093,498,939,000,000,000,000,000,000,000,000 | 28 | Don't crash on long usernames |
int Server::authenticate(QString &name, const QString &pw, const QStringList &emails, const QString &certhash, bool bStrongCert, const QList<QSslCertificate> &certs) {
int res = -2;
emit authenticateSig(res, name, certs, certhash, bStrongCert, pw);
if (res != -2) {
// External authentication handled it. Ignore certificate completely.
if (res != -1) {
TransactionHolder th;
QSqlQuery &query = *th.qsqQuery;
int lchan=readLastChannel(res);
if (lchan < 0)
lchan = 0;
SQLPREP("REPLACE INTO `%1users` (`server_id`, `user_id`, `name`, `lastchannel`) VALUES (?,?,?,?)");
query.addBindValue(iServerNum);
query.addBindValue(res);
query.addBindValue(name);
query.addBindValue(lchan);
SQLEXEC();
}
if (res >= 0) {
qhUserNameCache.remove(res);
qhUserIDCache.remove(name);
}
return res;
}
TransactionHolder th;
QSqlQuery &query = *th.qsqQuery;
SQLPREP("SELECT `user_id`,`name`,`pw` FROM `%1users` WHERE `server_id` = ? AND `name` like ?");
query.addBindValue(iServerNum);
query.addBindValue(name);
SQLEXEC();
if (query.next()) {
res = -1;
QString storedpw = query.value(2).toString();
QString hashedpw = QString::fromLatin1(sha1(pw).toHex());
if (! storedpw.isEmpty() && (storedpw == hashedpw)) {
name = query.value(1).toString();
res = query.value(0).toInt();
} else if (query.value(0).toInt() == 0) {
return -1;
}
}
// No password match. Try cert or email match, but only for non-SuperUser.
if (!certhash.isEmpty() && (res < 0)) {
SQLPREP("SELECT `user_id` FROM `%1user_info` WHERE `server_id` = ? AND `key` = ? AND `value` = ?");
query.addBindValue(iServerNum);
query.addBindValue(ServerDB::User_Hash);
query.addBindValue(certhash);
SQLEXEC();
if (query.next()) {
res = query.value(0).toInt();
} else if (bStrongCert) {
foreach(const QString &email, emails) {
if (! email.isEmpty()) {
query.addBindValue(iServerNum);
query.addBindValue(ServerDB::User_Email);
query.addBindValue(email);
SQLEXEC();
if (query.next()) {
res = query.value(0).toInt();
break;
}
}
}
}
if (res > 0) {
SQLPREP("SELECT `name` FROM `%1users` WHERE `server_id` = ? AND `user_id` = ?");
query.addBindValue(iServerNum);
query.addBindValue(res);
SQLEXEC();
if (! query.next()) {
res = -1;
} else {
name = query.value(0).toString();
}
}
}
if (! certhash.isEmpty() && (res > 0)) {
SQLPREP("REPLACE INTO `%1user_info` (`server_id`, `user_id`, `key`, `value`) VALUES (?, ?, ?, ?)");
query.addBindValue(iServerNum);
query.addBindValue(res);
query.addBindValue(ServerDB::User_Hash);
query.addBindValue(certhash);
SQLEXEC();
if (! emails.isEmpty()) {
query.addBindValue(iServerNum);
query.addBindValue(res);
query.addBindValue(ServerDB::User_Email);
query.addBindValue(emails.at(0));
SQLEXEC();
}
}
if (res >= 0) {
qhUserNameCache.remove(res);
qhUserIDCache.remove(name);
}
return res;
} | 1 | [
"CWE-20"
] | mumble | 6b33dda344f89e5a039b7d79eb43925040654242 | 80,257,356,580,533,810,000,000,000,000,000,000,000 | 105 | Don't crash on long usernames |
int Server::getUserID(const QString &name) {
if (qhUserIDCache.contains(name))
return qhUserIDCache.value(name);
int id = -2;
emit nameToIdSig(id, name);
if (id != -2) {
qhUserIDCache.insert(name, id);
qhUserNameCache.insert(id, name);
return id;
}
TransactionHolder th;
QSqlQuery &query = *th.qsqQuery;
SQLPREP("SELECT `user_id` FROM `%1users` WHERE `server_id` = ? AND `name` like ?");
query.addBindValue(iServerNum);
query.addBindValue(name);
SQLEXEC();
if (query.next()) {
id = query.value(0).toInt();
qhUserIDCache.insert(name, id);
qhUserNameCache.insert(id, name);
}
return id;
} | 1 | [
"CWE-20"
] | mumble | 6b33dda344f89e5a039b7d79eb43925040654242 | 176,557,232,937,900,040,000,000,000,000,000,000,000 | 24 | Don't crash on long usernames |
vte_sequence_handler_window_manipulation (VteTerminal *terminal, GValueArray *params)
{
GdkScreen *gscreen;
VteScreen *screen;
GValue *value;
GtkWidget *widget;
char buf[128];
long param, arg1, arg2;
gint width, height;
guint i;
widget = &terminal->widget;
screen = terminal->pvt->screen;
for (i = 0; ((params != NULL) && (i < params->n_values)); i++) {
arg1 = arg2 = -1;
if (i + 1 < params->n_values) {
value = g_value_array_get_nth(params, i + 1);
if (G_VALUE_HOLDS_LONG(value)) {
arg1 = g_value_get_long(value);
}
}
if (i + 2 < params->n_values) {
value = g_value_array_get_nth(params, i + 2);
if (G_VALUE_HOLDS_LONG(value)) {
arg2 = g_value_get_long(value);
}
}
value = g_value_array_get_nth(params, i);
if (!G_VALUE_HOLDS_LONG(value)) {
continue;
}
param = g_value_get_long(value);
switch (param) {
case 1:
_vte_debug_print(VTE_DEBUG_PARSE,
"Deiconifying window.\n");
vte_terminal_emit_deiconify_window(terminal);
break;
case 2:
_vte_debug_print(VTE_DEBUG_PARSE,
"Iconifying window.\n");
vte_terminal_emit_iconify_window(terminal);
break;
case 3:
if ((arg1 != -1) && (arg2 != -2)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Moving window to "
"%ld,%ld.\n", arg1, arg2);
vte_terminal_emit_move_window(terminal,
arg1, arg2);
i += 2;
}
break;
case 4:
if ((arg1 != -1) && (arg2 != -1)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing window "
"(to %ldx%ld pixels).\n",
arg2, arg1);
vte_terminal_emit_resize_window(terminal,
arg2 +
VTE_PAD_WIDTH * 2,
arg1 +
VTE_PAD_WIDTH * 2);
i += 2;
}
break;
case 5:
_vte_debug_print(VTE_DEBUG_PARSE, "Raising window.\n");
vte_terminal_emit_raise_window(terminal);
break;
case 6:
_vte_debug_print(VTE_DEBUG_PARSE, "Lowering window.\n");
vte_terminal_emit_lower_window(terminal);
break;
case 7:
_vte_debug_print(VTE_DEBUG_PARSE,
"Refreshing window.\n");
_vte_invalidate_all(terminal);
vte_terminal_emit_refresh_window(terminal);
break;
case 8:
if ((arg1 != -1) && (arg2 != -1)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing window "
"(to %ld columns, %ld rows).\n",
arg2, arg1);
vte_terminal_emit_resize_window(terminal,
arg2 * terminal->char_width +
VTE_PAD_WIDTH * 2,
arg1 * terminal->char_height +
VTE_PAD_WIDTH * 2);
i += 2;
}
break;
case 9:
switch (arg1) {
case 0:
_vte_debug_print(VTE_DEBUG_PARSE,
"Restoring window.\n");
vte_terminal_emit_restore_window(terminal);
break;
case 1:
_vte_debug_print(VTE_DEBUG_PARSE,
"Maximizing window.\n");
vte_terminal_emit_maximize_window(terminal);
break;
default:
break;
}
i++;
break;
case 11:
/* If we're unmapped, then we're iconified. */
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%dt",
1 + !GTK_WIDGET_MAPPED(widget));
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window state %s.\n",
GTK_WIDGET_MAPPED(widget) ?
"non-iconified" : "iconified");
vte_terminal_feed_child(terminal, buf, -1);
break;
case 13:
/* Send window location, in pixels. */
gdk_window_get_origin(widget->window,
&width, &height);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%d;%dt",
width + VTE_PAD_WIDTH, height + VTE_PAD_WIDTH);
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window location"
"(%d++,%d++).\n",
width, height);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 14:
/* Send window size, in pixels. */
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%d;%dt",
widget->allocation.height - 2 * VTE_PAD_WIDTH,
widget->allocation.width - 2 * VTE_PAD_WIDTH);
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window size "
"(%dx%dn",
width - 2 * VTE_PAD_WIDTH,
height - 2 * VTE_PAD_WIDTH);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 18:
/* Send widget size, in cells. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting widget size.\n");
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%ld;%ldt",
terminal->row_count,
terminal->column_count);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 19:
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting screen size.\n");
gscreen = gtk_widget_get_screen(widget);
height = gdk_screen_get_height(gscreen);
width = gdk_screen_get_width(gscreen);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%ld;%ldt",
height / terminal->char_height,
width / terminal->char_width);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 20:
/* Report the icon title. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting icon title.\n");
vte_terminal_feed_child(terminal, _VTE_CAP_OSC "LTerminal" _VTE_CAP_ST, -1);
break;
case 21:
/* Report the window title. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window title.\n");
vte_terminal_feed_child(terminal, _VTE_CAP_OSC "LTerminal" _VTE_CAP_ST, -1);
break;
default:
if (param >= 24) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing to %ld rows.\n",
param);
/* Resize to the specified number of
* rows. */
vte_terminal_emit_resize_window(terminal,
terminal->column_count * terminal->char_width +
VTE_PAD_WIDTH * 2,
param * terminal->char_height +
VTE_PAD_WIDTH * 2);
}
break;
}
}
} | 1 | [] | vte | 58bc3a942f198a1a8788553ca72c19d7c1702b74 | 142,489,256,848,579,330,000,000,000,000,000,000,000 | 201 | fix bug #548272
svn path=/trunk/; revision=2365 |
vte_sequence_handler_window_manipulation (VteTerminal *terminal, GValueArray *params)
{
GdkScreen *gscreen;
VteScreen *screen;
GValue *value;
GtkWidget *widget;
char buf[128];
long param, arg1, arg2;
gint width, height;
guint i;
GtkAllocation allocation;
widget = &terminal->widget;
screen = terminal->pvt->screen;
for (i = 0; ((params != NULL) && (i < params->n_values)); i++) {
arg1 = arg2 = -1;
if (i + 1 < params->n_values) {
value = g_value_array_get_nth(params, i + 1);
if (G_VALUE_HOLDS_LONG(value)) {
arg1 = g_value_get_long(value);
}
}
if (i + 2 < params->n_values) {
value = g_value_array_get_nth(params, i + 2);
if (G_VALUE_HOLDS_LONG(value)) {
arg2 = g_value_get_long(value);
}
}
value = g_value_array_get_nth(params, i);
if (!G_VALUE_HOLDS_LONG(value)) {
continue;
}
param = g_value_get_long(value);
switch (param) {
case 1:
_vte_debug_print(VTE_DEBUG_PARSE,
"Deiconifying window.\n");
vte_terminal_emit_deiconify_window(terminal);
break;
case 2:
_vte_debug_print(VTE_DEBUG_PARSE,
"Iconifying window.\n");
vte_terminal_emit_iconify_window(terminal);
break;
case 3:
if ((arg1 != -1) && (arg2 != -2)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Moving window to "
"%ld,%ld.\n", arg1, arg2);
vte_terminal_emit_move_window(terminal,
arg1, arg2);
i += 2;
}
break;
case 4:
if ((arg1 != -1) && (arg2 != -1)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing window "
"(to %ldx%ld pixels).\n",
arg2, arg1);
vte_terminal_emit_resize_window(terminal,
arg2 +
terminal->pvt->inner_border.left +
terminal->pvt->inner_border.right,
arg1 +
terminal->pvt->inner_border.top +
terminal->pvt->inner_border.bottom);
i += 2;
}
break;
case 5:
_vte_debug_print(VTE_DEBUG_PARSE, "Raising window.\n");
vte_terminal_emit_raise_window(terminal);
break;
case 6:
_vte_debug_print(VTE_DEBUG_PARSE, "Lowering window.\n");
vte_terminal_emit_lower_window(terminal);
break;
case 7:
_vte_debug_print(VTE_DEBUG_PARSE,
"Refreshing window.\n");
_vte_invalidate_all(terminal);
vte_terminal_emit_refresh_window(terminal);
break;
case 8:
if ((arg1 != -1) && (arg2 != -1)) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing window "
"(to %ld columns, %ld rows).\n",
arg2, arg1);
vte_terminal_emit_resize_window(terminal,
arg2 * terminal->char_width +
terminal->pvt->inner_border.left +
terminal->pvt->inner_border.right,
arg1 * terminal->char_height +
terminal->pvt->inner_border.top +
terminal->pvt->inner_border.bottom);
i += 2;
}
break;
case 9:
switch (arg1) {
case 0:
_vte_debug_print(VTE_DEBUG_PARSE,
"Restoring window.\n");
vte_terminal_emit_restore_window(terminal);
break;
case 1:
_vte_debug_print(VTE_DEBUG_PARSE,
"Maximizing window.\n");
vte_terminal_emit_maximize_window(terminal);
break;
default:
break;
}
i++;
break;
case 11:
/* If we're unmapped, then we're iconified. */
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "%dt",
1 + !gtk_widget_get_mapped(widget));
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window state %s.\n",
gtk_widget_get_mapped(widget) ?
"non-iconified" : "iconified");
vte_terminal_feed_child(terminal, buf, -1);
break;
case 13:
/* Send window location, in pixels. */
gdk_window_get_origin(gtk_widget_get_window(widget),
&width, &height);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "3;%d;%dt",
width + terminal->pvt->inner_border.left,
height + terminal->pvt->inner_border.top);
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window location"
"(%d++,%d++).\n",
width, height);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 14:
/* Send window size, in pixels. */
gtk_widget_get_allocation(widget, &allocation);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "4;%d;%dt",
allocation.height -
(terminal->pvt->inner_border.top +
terminal->pvt->inner_border.bottom),
allocation.width -
(terminal->pvt->inner_border.left +
terminal->pvt->inner_border.right));
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window size "
"(%dx%dn",
width - (terminal->pvt->inner_border.left + terminal->pvt->inner_border.right),
height - (terminal->pvt->inner_border.top + terminal->pvt->inner_border.bottom));
vte_terminal_feed_child(terminal, buf, -1);
break;
case 18:
/* Send widget size, in cells. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting widget size.\n");
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "8;%ld;%ldt",
terminal->row_count,
terminal->column_count);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 19:
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting screen size.\n");
gscreen = gtk_widget_get_screen(widget);
height = gdk_screen_get_height(gscreen);
width = gdk_screen_get_width(gscreen);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "9;%ld;%ldt",
height / terminal->char_height,
width / terminal->char_width);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 20:
/* Report the icon title. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting icon title.\n");
g_snprintf (buf, sizeof (buf),
_VTE_CAP_OSC "L%s" _VTE_CAP_ST,
terminal->icon_title);
vte_terminal_feed_child(terminal, buf, -1);
break;
case 21:
/* Report the window title. */
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window title.\n");
g_snprintf (buf, sizeof (buf),
_VTE_CAP_OSC "l%s" _VTE_CAP_ST,
terminal->window_title);
vte_terminal_feed_child(terminal, buf, -1);
break;
default:
if (param >= 24) {
_vte_debug_print(VTE_DEBUG_PARSE,
"Resizing to %ld rows.\n",
param);
/* Resize to the specified number of
* rows. */
vte_terminal_emit_resize_window(terminal,
terminal->column_count * terminal->char_width +
terminal->pvt->inner_border.left +
terminal->pvt->inner_border.right,
param * terminal->char_height +
terminal->pvt->inner_border.top +
terminal->pvt->inner_border.bottom);
}
break;
}
}
} | 1 | [] | vte | 8b971a7b2c59902914ecbbc3915c45dd21530a91 | 112,569,028,621,208,800,000,000,000,000,000,000,000 | 220 | Fix terminal title reporting
Fixed CVE-2003-0070 again.
See also http://marc.info/?l=bugtraq&m=104612710031920&w=2 .
(cherry picked from commit 6042c75b5a6daa0e499e61c8e07242d890d38ff1) |
main( int argc,
char* argv[] )
{
int old_ptsize, orig_ptsize, file;
int first_glyph = 0;
int XisSetup = 0;
char* execname;
int option;
int file_loaded;
grEvent event;
execname = ft_basename( argv[0] );
while ( 1 )
{
option = getopt( argc, argv, "d:e:f:r:" );
if ( option == -1 )
break;
switch ( option )
{
case 'd':
parse_design_coords( optarg );
break;
case 'e':
encoding = (FT_Encoding)make_tag( optarg );
break;
case 'f':
first_glyph = atoi( optarg );
break;
case 'r':
res = atoi( optarg );
if ( res < 1 )
usage( execname );
break;
default:
usage( execname );
break;
}
}
argc -= optind;
argv += optind;
if ( argc <= 1 )
usage( execname );
if ( sscanf( argv[0], "%d", &orig_ptsize ) != 1 )
orig_ptsize = 64;
file = 1;
/* Initialize engine */
error = FT_Init_FreeType( &library );
if ( error )
PanicZ( "Could not initialize FreeType library" );
NewFile:
ptsize = orig_ptsize;
hinted = 1;
file_loaded = 0;
/* Load face */
error = FT_New_Face( library, argv[file], 0, &face );
if ( error )
goto Display_Font;
if ( encoding != FT_ENCODING_NONE )
{
error = FT_Select_Charmap( face, encoding );
if ( error )
goto Display_Font;
}
/* retrieve multiple master information */
error = FT_Get_MM_Var( face, &multimaster );
if ( error )
goto Display_Font;
/* if the user specified a position, use it, otherwise */
/* set the current position to the median of each axis */
{
int n;
for ( n = 0; n < (int)multimaster->num_axis; n++ )
{
design_pos[n] = n < requested_cnt ? requested_pos[n]
: multimaster->axis[n].def;
if ( design_pos[n] < multimaster->axis[n].minimum )
design_pos[n] = multimaster->axis[n].minimum;
else if ( design_pos[n] > multimaster->axis[n].maximum )
design_pos[n] = multimaster->axis[n].maximum;
}
}
error = FT_Set_Var_Design_Coordinates( face,
multimaster->num_axis,
design_pos );
if ( error )
goto Display_Font;
file_loaded++;
Reset_Scale( ptsize );
num_glyphs = face->num_glyphs;
glyph = face->glyph;
size = face->size;
Display_Font:
/* initialize graphics if needed */
if ( !XisSetup )
{
XisSetup = 1;
Init_Display();
}
grSetTitle( surface, "FreeType Glyph Viewer - press F1 for help" );
old_ptsize = ptsize;
if ( file_loaded >= 1 )
{
Fail = 0;
Num = first_glyph;
if ( Num >= num_glyphs )
Num = num_glyphs - 1;
if ( Num < 0 )
Num = 0;
}
for ( ;; )
{
int key;
Clear_Display();
if ( file_loaded >= 1 )
{
switch ( render_mode )
{
case 0:
Render_Text( Num );
break;
default:
Render_All( Num, ptsize );
}
sprintf( Header, "%s %s (file %s)",
face->family_name,
face->style_name,
ft_basename( argv[file] ) );
if ( !new_header )
new_header = Header;
grWriteCellString( &bit, 0, 0, new_header, fore_color );
new_header = 0;
sprintf( Header, "axis: " );
{
int n;
for ( n = 0; n < (int)multimaster->num_axis; n++ )
{
char temp[32];
sprintf( temp, " %s:%g",
multimaster->axis[n].name,
design_pos[n]/65536. );
strcat( Header, temp );
}
}
grWriteCellString( &bit, 0, 16, Header, fore_color );
sprintf( Header, "at %d points, first glyph = %d",
ptsize,
Num );
}
else
{
sprintf( Header, "%s: not an MM font file, or could not be opened",
ft_basename( argv[file] ) );
}
grWriteCellString( &bit, 0, 8, Header, fore_color );
grRefreshSurface( surface );
grListenSurface( surface, 0, &event );
if ( !( key = Process_Event( &event ) ) )
goto End;
if ( key == 'n' )
{
if ( file_loaded >= 1 )
FT_Done_Face( face );
if ( file < argc - 1 )
file++;
goto NewFile;
}
if ( key == 'p' )
{
if ( file_loaded >= 1 )
FT_Done_Face( face );
if ( file > 1 )
file--;
goto NewFile;
}
if ( ptsize != old_ptsize )
{
Reset_Scale( ptsize );
old_ptsize = ptsize;
}
}
End:
grDoneSurface( surface );
grDoneDevices();
free ( multimaster );
FT_Done_Face ( face );
FT_Done_FreeType( library );
printf( "Execution completed successfully.\n" );
printf( "Fails = %d\n", Fail );
exit( 0 ); /* for safety reasons */
return 0; /* never reached */
} | 1 | [
"CWE-120"
] | freetype2-demos | b995299b73ba4cd259f221f500d4e63095508bec | 237,280,854,367,069,740,000,000,000,000,000,000,000 | 249 | Fix Savannah bug #30054.
* src/ftdiff.c, src/ftgrid.c, src/ftmulti.c, src/ftstring.c,
src/ftview.c: Use precision for `%s' where appropriate to avoid
buffer overflows. |
write_header( FT_Error error_code )
{
FT_Face face;
const char* basename;
const char* format;
error = FTC_Manager_LookupFace( handle->cache_manager,
handle->scaler.face_id, &face );
if ( error )
Fatal( "can't access font file" );
if ( !status.header )
{
basename = ft_basename( handle->current_font->filepathname );
switch ( error_code )
{
case FT_Err_Ok:
sprintf( status.header_buffer, "%s %s (file `%s')",
face->family_name, face->style_name, basename );
break;
case FT_Err_Invalid_Pixel_Size:
sprintf( status.header_buffer, "Invalid pixel size (file `%s')",
basename );
break;
case FT_Err_Invalid_PPem:
sprintf( status.header_buffer, "Invalid ppem value (file `%s')",
basename );
break;
default:
sprintf( status.header_buffer, "File `%s': error 0x%04x",
basename, (FT_UShort)error_code );
break;
}
status.header = (const char *)status.header_buffer;
}
grWriteCellString( display->bitmap, 0, 0, status.header,
display->fore_color );
format = "at %g points, first glyph index = %d";
snprintf( status.header_buffer, 256, format, status.ptsize/64., status.Num );
if ( FT_HAS_GLYPH_NAMES( face ) )
{
char* p;
int format_len, gindex, size;
size = strlen( status.header_buffer );
p = status.header_buffer + size;
size = 256 - size;
format = ", name = ";
format_len = strlen( format );
if ( size >= format_len + 2 )
{
gindex = status.Num;
strcpy( p, format );
if ( FT_Get_Glyph_Name( face, gindex, p + format_len, size - format_len ) )
*p = '\0';
}
}
status.header = (const char *)status.header_buffer;
grWriteCellString( display->bitmap, 0, HEADER_HEIGHT,
status.header_buffer, display->fore_color );
grRefreshSurface( display->surface );
} | 1 | [
"CWE-120"
] | freetype2-demos | b995299b73ba4cd259f221f500d4e63095508bec | 51,136,699,242,632,680,000,000,000,000,000,000,000 | 78 | Fix Savannah bug #30054.
* src/ftdiff.c, src/ftgrid.c, src/ftmulti.c, src/ftstring.c,
src/ftview.c: Use precision for `%s' where appropriate to avoid
buffer overflows. |
write_header( FT_Error error_code )
{
FT_Face face;
const char* basename;
error = FTC_Manager_LookupFace( handle->cache_manager,
handle->scaler.face_id, &face );
if ( error )
PanicZ( "can't access font file" );
if ( !status.header )
{
basename = ft_basename( handle->current_font->filepathname );
switch ( error_code )
{
case FT_Err_Ok:
sprintf( status.header_buffer, "%s %s (file `%s')", face->family_name,
face->style_name, basename );
break;
case FT_Err_Invalid_Pixel_Size:
sprintf( status.header_buffer, "Invalid pixel size (file `%s')",
basename );
break;
case FT_Err_Invalid_PPem:
sprintf( status.header_buffer, "Invalid ppem value (file `%s')",
basename );
break;
default:
sprintf( status.header_buffer, "File `%s': error 0x%04x", basename,
(FT_UShort)error_code );
break;
}
status.header = status.header_buffer;
}
grWriteCellString( display->bitmap, 0, 0,
status.header, display->fore_color );
sprintf( status.header_buffer, "at %g points, angle = %d",
status.ptsize/64.0, status.angle );
grWriteCellString( display->bitmap, 0, CELLSTRING_HEIGHT,
status.header_buffer, display->fore_color );
grRefreshSurface( display->surface );
} | 1 | [
"CWE-120"
] | freetype2-demos | b995299b73ba4cd259f221f500d4e63095508bec | 311,184,877,056,379,570,000,000,000,000,000,000,000 | 48 | Fix Savannah bug #30054.
* src/ftdiff.c, src/ftgrid.c, src/ftmulti.c, src/ftstring.c,
src/ftview.c: Use precision for `%s' where appropriate to avoid
buffer overflows. |
write_header( FT_Error error_code )
{
FT_Face face;
const char* basename;
const char* format;
error = FTC_Manager_LookupFace( handle->cache_manager,
handle->scaler.face_id, &face );
if ( error )
Fatal( "can't access font file" );
if ( !status.header )
{
basename = ft_basename( handle->current_font->filepathname );
switch ( error_code )
{
case FT_Err_Ok:
sprintf( status.header_buffer, "%s %s (file `%s')",
face->family_name, face->style_name, basename );
break;
case FT_Err_Invalid_Pixel_Size:
sprintf( status.header_buffer, "Invalid pixel size (file `%s')",
basename );
break;
case FT_Err_Invalid_PPem:
sprintf( status.header_buffer, "Invalid ppem value (file `%s')",
basename );
break;
default:
sprintf( status.header_buffer, "File `%s': error 0x%04x",
basename, (FT_UShort)error_code );
break;
}
status.header = status.header_buffer;
}
grWriteCellString( display->bitmap, 0, 0,
status.header, display->fore_color );
format = status.encoding != FT_ENCODING_NONE
? "at %g points, first char code = 0x%x"
: "at %g points, first glyph index = %d";
snprintf( status.header_buffer, 256, format,
status.ptsize / 64.0, status.Num );
if ( FT_HAS_GLYPH_NAMES( face ) )
{
char* p;
int format_len, gindex, size;
size = strlen( status.header_buffer );
p = status.header_buffer + size;
size = 256 - size;
format = ", name = ";
format_len = strlen( format );
if ( size >= format_len + 2 )
{
gindex = status.Num;
if ( status.encoding != FT_ENCODING_NONE )
gindex = FTDemo_Get_Index( handle, status.Num );
strcpy( p, format );
if ( FT_Get_Glyph_Name( face, gindex,
p + format_len, size - format_len ) )
*p = '\0';
}
}
status.header = status.header_buffer;
grWriteCellString( display->bitmap, 0, HEADER_HEIGHT,
status.header_buffer, display->fore_color );
if ( status.use_custom_lcd_filter )
{
int fwi = status.fw_index;
unsigned char *fw = status.filter_weights;
sprintf( status.header_buffer,
"%s0x%02X%s%s0x%02X%s%s0x%02X%s%s0x%02X%s%s0x%02X%s",
fwi == 0 ? "[" : " ", fw[0], fwi == 0 ? "]" : " ",
fwi == 1 ? "[" : " ", fw[1], fwi == 1 ? "]" : " ",
fwi == 2 ? "[" : " ", fw[2], fwi == 2 ? "]" : " ",
fwi == 3 ? "[" : " ", fw[3], fwi == 3 ? "]" : " ",
fwi == 4 ? "[" : " ", fw[4], fwi == 4 ? "]" : " " );
grWriteCellString( display->bitmap, 0, 2 * HEADER_HEIGHT,
status.header_buffer, display->fore_color );
}
grRefreshSurface( display->surface );
} | 1 | [
"CWE-120"
] | freetype2-demos | b995299b73ba4cd259f221f500d4e63095508bec | 69,731,635,452,952,740,000,000,000,000,000,000,000 | 98 | Fix Savannah bug #30054.
* src/ftdiff.c, src/ftgrid.c, src/ftmulti.c, src/ftstring.c,
src/ftview.c: Use precision for `%s' where appropriate to avoid
buffer overflows. |
write_message( RenderState state )
{
ADisplay adisplay = (ADisplay)state->display.disp;
if ( state->message == NULL )
{
FontFace face = &state->faces[state->face_index];
int idx, total;
idx = face->index;
total = 1;
while ( total + state->face_index < state->num_faces &&
face[total].filepath == face[0].filepath )
total++;
total += idx;
state->message = state->message0;
if ( total > 1 )
sprintf( state->message0, "%s %d/%d @ %5.1fpt",
state->filename, idx + 1, total,
state->char_size );
else
sprintf( state->message0, "%s @ %5.1fpt",
state->filename,
state->char_size );
}
grWriteCellString( adisplay->bitmap, 0, DIM_Y - 10, state->message,
adisplay->fore_color );
state->message = NULL;
} | 1 | [
"CWE-120"
] | freetype2-demos | b995299b73ba4cd259f221f500d4e63095508bec | 316,756,505,032,776,100,000,000,000,000,000,000,000 | 35 | Fix Savannah bug #30054.
* src/ftdiff.c, src/ftgrid.c, src/ftmulti.c, src/ftstring.c,
src/ftview.c: Use precision for `%s' where appropriate to avoid
buffer overflows. |