miniobject: Always reject WRITE locks on READONLY miniobjects

Verify that mapping a read-only memory as read doesnt make it writable
This commit is contained in:
Olivier Crête 2012-09-28 15:17:27 -04:00
parent f02ba3b572
commit fd846a7c64
2 changed files with 11 additions and 2 deletions

View file

@ -121,8 +121,7 @@ gst_mini_object_init (GstMiniObject * mini_object, guint flags, GType type,
{
mini_object->type = type;
mini_object->refcount = 1;
mini_object->lockstate =
(flags & GST_MINI_OBJECT_FLAG_LOCK_READONLY ? GST_LOCK_FLAG_READ : 0);
mini_object->lockstate = 0;
mini_object->flags = flags;
mini_object->copy = copy_func;
@ -179,6 +178,10 @@ gst_mini_object_lock (GstMiniObject * object, GstLockFlags flags)
g_return_val_if_fail (object != NULL, FALSE);
g_return_val_if_fail (GST_MINI_OBJECT_IS_LOCKABLE (object), FALSE);
if (G_UNLIKELY (object->flags & GST_MINI_OBJECT_FLAG_LOCK_READONLY &&
flags & GST_LOCK_FLAG_WRITE))
return FALSE;
do {
access_mode = flags & FLAG_MASK;
newstate = state = g_atomic_int_get (&object->lockstate);

View file

@ -149,6 +149,12 @@ GST_START_TEST (test_writable)
fail_if (gst_memory_map (mem, &info, GST_MAP_WRITE));
/* Make sure mapping anxd unmapping it doesn't change it's locking state */
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
gst_memory_unmap (mem, &info);
fail_if (gst_memory_map (mem, &info, GST_MAP_WRITE));
mem2 = gst_memory_copy (mem, 0, -1);
fail_unless (GST_MEMORY_IS_READONLY (mem));
fail_if (GST_MEMORY_IS_READONLY (mem2));