1
0
Fork 0

Change all g_memdup() to g_memdup2()

Using g_memdup() is dangerous due to the type of the size argument. See
https://gitlab.gnome.org/GNOME/glib/-/issues/2319 and
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1926 for details.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1708>
This commit is contained in:
Jonas Ådahl 2021-02-04 18:45:59 +01:00
parent 70c5febdd9
commit 30e1c51b33
19 changed files with 75 additions and 50 deletions

View file

@ -12,7 +12,7 @@ stages:
.mutter.fedora:33@common:
variables:
FDO_DISTRIBUTION_VERSION: 33
BASE_TAG: '2021-01-22.0'
BASE_TAG: '2021-02-04.1'
FDO_UPSTREAM_REPO: GNOME/mutter
FDO_DISTRIBUTION_EXEC: |
dnf install -y 'dnf-command(builddep)' &&
@ -34,6 +34,13 @@ stages:
dnf builddep -y xorg-x11-server-Xwayland --setopt=install_weak_deps=False &&
dnf remove -y --noautoremove 'xorg-x11-server-Xwayland' &&
# For glib
dnf builddep -y glib2 --setopt=install_weak_deps=False &&
./.gitlab-ci/install-meson-project.sh \
https://gitlab.gnome.org/GNOME/glib.git \
2.67.3 . &&
./.gitlab-ci/install-meson-project.sh \
-Dlibaudit=disabled \
-Dplymouth=disabled \

View file

@ -1315,20 +1315,29 @@ clutter_event_copy (const ClutterEvent *event)
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
if (event->button.axes != NULL)
new_event->button.axes = g_memdup (event->button.axes,
sizeof (gdouble) * CLUTTER_INPUT_AXIS_LAST);
{
new_event->button.axes =
g_memdup2 (event->button.axes,
sizeof (double) * CLUTTER_INPUT_AXIS_LAST);
}
break;
case CLUTTER_SCROLL:
if (event->scroll.axes != NULL)
new_event->scroll.axes = g_memdup (event->scroll.axes,
sizeof (gdouble) * CLUTTER_INPUT_AXIS_LAST);
{
new_event->scroll.axes =
g_memdup2 (event->scroll.axes,
sizeof (double) * CLUTTER_INPUT_AXIS_LAST);
}
break;
case CLUTTER_MOTION:
if (event->motion.axes != NULL)
new_event->motion.axes = g_memdup (event->motion.axes,
sizeof (gdouble) * CLUTTER_INPUT_AXIS_LAST);
{
new_event->motion.axes =
g_memdup2 (event->motion.axes,
sizeof (double) * CLUTTER_INPUT_AXIS_LAST);
}
break;
case CLUTTER_TOUCH_BEGIN:
@ -1336,8 +1345,11 @@ clutter_event_copy (const ClutterEvent *event)
case CLUTTER_TOUCH_END:
case CLUTTER_TOUCH_CANCEL:
if (event->touch.axes != NULL)
new_event->touch.axes = g_memdup (event->touch.axes,
sizeof (gdouble) * CLUTTER_INPUT_AXIS_LAST);
{
new_event->touch.axes =
g_memdup2 (event->touch.axes,
sizeof (double) * CLUTTER_INPUT_AXIS_LAST);
}
break;
case CLUTTER_DEVICE_ADDED:

View file

@ -157,7 +157,8 @@ clutter_value_lcopy_shader_float (const GValue *value,
G_VALUE_TYPE_NAME (value));
*float_count = shader_float->size;
*floats = g_memdup (shader_float->value, shader_float->size * sizeof (float));
*floats = g_memdup2 (shader_float->value,
shader_float->size * sizeof (float));
return NULL;
}
@ -248,7 +249,7 @@ clutter_value_lcopy_shader_int (const GValue *value,
G_VALUE_TYPE_NAME (value));
*int_count = shader_int->size;
*ints = g_memdup (shader_int->value, shader_int->size * sizeof (int));
*ints = g_memdup2 (shader_int->value, shader_int->size * sizeof (int));
return NULL;
}
@ -339,8 +340,10 @@ clutter_value_lcopy_shader_matrix (const GValue *value,
G_VALUE_TYPE_NAME (value));
*float_count = shader_float->size;
*floats = g_memdup (shader_float->value,
shader_float->size * shader_float->size * sizeof (float));
*floats = g_memdup2 (shader_float->value,
shader_float->size *
shader_float->size *
sizeof (float));
return NULL;
}

View file

@ -253,21 +253,21 @@ _cogl_boxed_value_copy (CoglBoxedValue *dst,
break;
case COGL_BOXED_INT:
dst->v.int_array = g_memdup (src->v.int_array,
src->size * src->count * sizeof (int));
dst->v.int_array = g_memdup2 (src->v.int_array,
src->size * src->count * sizeof (int));
break;
case COGL_BOXED_FLOAT:
dst->v.float_array = g_memdup (src->v.float_array,
src->size *
src->count *
sizeof (float));
dst->v.float_array = g_memdup2 (src->v.float_array,
src->size *
src->count *
sizeof (float));
break;
case COGL_BOXED_MATRIX:
dst->v.float_array = g_memdup (src->v.float_array,
src->size * src->size *
src->count * sizeof (float));
dst->v.float_array = g_memdup2 (src->v.float_array,
src->size * src->size *
src->count * sizeof (float));
break;
}
}

View file

@ -13,7 +13,7 @@ libmutter_api_version = '@0@'.format(api_version)
# generic version requirements
fribidi_req = '>= 1.0.0'
glib_req = '>= 2.61.1'
glib_req = '>= 2.67.3'
gi_req = '>= 0.9.5'
graphene_req = '>= 1.10.2'
gtk3_req = '>= 3.19.8'

View file

@ -641,7 +641,7 @@ create_monitor_config (MetaMonitor *monitor,
monitor_config = g_new0 (MetaMonitorConfig, 1);
*monitor_config = (MetaMonitorConfig) {
.monitor_spec = meta_monitor_spec_clone (monitor_spec),
.mode_spec = g_memdup (mode_spec, sizeof (MetaMonitorModeSpec)),
.mode_spec = g_memdup2 (mode_spec, sizeof (MetaMonitorModeSpec)),
.enable_underscanning = meta_monitor_is_underscanning (monitor)
};
@ -928,8 +928,8 @@ clone_monitor_config_list (GList *monitor_configs_in)
monitor_config_out = g_new0 (MetaMonitorConfig, 1);
*monitor_config_out = (MetaMonitorConfig) {
.monitor_spec = meta_monitor_spec_clone (monitor_config_in->monitor_spec),
.mode_spec = g_memdup (monitor_config_in->mode_spec,
sizeof (MetaMonitorModeSpec)),
.mode_spec = g_memdup2 (monitor_config_in->mode_spec,
sizeof (MetaMonitorModeSpec)),
.enable_underscanning = monitor_config_in->enable_underscanning
};
monitor_configs_out =
@ -952,7 +952,8 @@ clone_logical_monitor_config_list (GList *logical_monitor_configs_in)
logical_monitor_config_in = l->data;
logical_monitor_config_out =
g_memdup (logical_monitor_config_in, sizeof (MetaLogicalMonitorConfig));
g_memdup2 (logical_monitor_config_in,
sizeof (MetaLogicalMonitorConfig));
logical_monitor_config_out->monitor_configs =
clone_monitor_config_list (logical_monitor_config_in->monitor_configs);

View file

@ -182,7 +182,7 @@ append_monitor (MetaMonitorManager *manager,
{
CrtcModeSpec *spec;
spec = g_memdup (&default_specs[i], sizeof (CrtcModeSpec));
spec = g_memdup2 (&default_specs[i], sizeof (CrtcModeSpec));
mode_specs = g_list_prepend (mode_specs, spec);
}
}

View file

@ -666,7 +666,7 @@ meta_input_settings_native_set_tablet_aspect_ratio (MetaInputSettings *settings
task = g_task_new (device, NULL, NULL, NULL);
g_task_set_task_data (task,
g_memdup (&aspect_ratio, sizeof (double)),
g_memdup2 (&aspect_ratio, sizeof (double)),
g_free);
input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);

View file

@ -273,11 +273,11 @@ meta_kms_crtc_predict_state (MetaKmsCrtc *crtc,
clear_gamma_state (crtc);
crtc->current_state.gamma.size = gamma->size;
crtc->current_state.gamma.red =
g_memdup (gamma->red, gamma->size * sizeof (uint16_t));
g_memdup2 (gamma->red, gamma->size * sizeof (uint16_t));
crtc->current_state.gamma.green =
g_memdup (gamma->green, gamma->size * sizeof (uint16_t));
g_memdup2 (gamma->green, gamma->size * sizeof (uint16_t));
crtc->current_state.gamma.blue =
g_memdup (gamma->blue, gamma->size * sizeof (uint16_t));
g_memdup2 (gamma->blue, gamma->size * sizeof (uint16_t));
break;
}

View file

@ -263,7 +263,7 @@ cached_mode_set_new (GList *connectors,
cached_mode_set = g_new0 (CachedModeSet, 1);
*cached_mode_set = (CachedModeSet) {
.connectors = g_list_copy (connectors),
.drm_mode = g_memdup (drm_mode, sizeof *drm_mode),
.drm_mode = g_memdup2 (drm_mode, sizeof *drm_mode),
};
return cached_mode_set;

View file

@ -364,9 +364,9 @@ meta_kms_crtc_gamma_new (MetaKmsCrtc *crtc,
*gamma = (MetaKmsCrtcGamma) {
.crtc = crtc,
.size = size,
.red = g_memdup (red, size * sizeof (*red)),
.green = g_memdup (green, size * sizeof (*green)),
.blue = g_memdup (blue, size * sizeof (*blue)),
.red = g_memdup2 (red, size * sizeof (*red)),
.green = g_memdup2 (green, size * sizeof (*green)),
.blue = g_memdup2 (blue, size * sizeof (*blue)),
};
return gamma;

View file

@ -353,9 +353,9 @@ meta_monitor_manager_kms_get_crtc_gamma (MetaMonitorManager *manager,
crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
*size = crtc_state->gamma.size;
*red = g_memdup (crtc_state->gamma.red, *size * sizeof **red);
*green = g_memdup (crtc_state->gamma.green, *size * sizeof **green);
*blue = g_memdup (crtc_state->gamma.blue, *size * sizeof **blue);
*red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
*green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
*blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
}
static char *

View file

@ -677,9 +677,9 @@ meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager *manager,
(XID) meta_crtc_get_id (crtc));
*size = gamma->size;
*red = g_memdup (gamma->red, sizeof (unsigned short) * gamma->size);
*green = g_memdup (gamma->green, sizeof (unsigned short) * gamma->size);
*blue = g_memdup (gamma->blue, sizeof (unsigned short) * gamma->size);
*red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
*green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
*blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
XRRFreeGamma (gamma);
}

View file

@ -476,7 +476,7 @@ get_edid_property (Display *xdisplay,
if (actual_type == XA_INTEGER && actual_format == 8)
{
result = g_memdup (prop, nitems);
result = g_memdup2 (prop, nitems);
if (len)
*len = nitems;
}

View file

@ -46,7 +46,7 @@
MetaRectangle *
meta_rectangle_copy (const MetaRectangle *rect)
{
return g_memdup (rect, sizeof (MetaRectangle));
return g_memdup2 (rect, sizeof (MetaRectangle));
}
void

View file

@ -2549,7 +2549,7 @@ meta_display_manage_all_xwindows (MetaDisplay *display)
meta_stack_tracker_get_stack (display->stack_tracker, &_children, &n_children);
/* Copy the stack as it will be modified as part of the loop */
children = g_memdup (_children, sizeof (guint64) * n_children);
children = g_memdup2 (_children, sizeof (uint64_t) * n_children);
for (i = 0; i < n_children; ++i)
{

View file

@ -95,8 +95,8 @@ resolved_key_combo_copy (MetaResolvedKeyCombo *from,
MetaResolvedKeyCombo *to)
{
to->len = from->len;
to->keycodes = g_memdup (from->keycodes,
from->len * sizeof (xkb_keycode_t));
to->keycodes = g_memdup2 (from->keycodes,
from->len * sizeof (xkb_keycode_t));
}
static gboolean

View file

@ -791,7 +791,7 @@ meta_workspace_invalidate_work_area (MetaWorkspace *workspace)
static MetaStrut *
copy_strut(MetaStrut *original)
{
return g_memdup(original, sizeof(MetaStrut));
return g_memdup2 (original, sizeof (MetaStrut));
}
static GSList *

View file

@ -1962,9 +1962,11 @@ meta_x11_display_init_window_prop_hooks (MetaX11Display *x11_display)
{ x11_display->atom__NET_WM_WINDOW_OPACITY, META_PROP_VALUE_CARDINAL, reload_window_opacity, LOAD_INIT | INCLUDE_OR },
{ 0 },
};
MetaWindowPropHooks *table;
MetaWindowPropHooks *cursor;
MetaWindowPropHooks *table = g_memdup (hooks, sizeof (hooks)),
*cursor = table;
table = g_memdup2 (hooks, sizeof (hooks)),
cursor = table;
g_assert (x11_display->prop_hooks == NULL);