Code review comment for lp://qastaging/~3v1n0/unity/lim

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

862 + if (sscanf (entry_id, "%p", &entry) == 1)
863 + {
864 + /* Checking that entry is really an IndicatorObjectEntry.
865 + * To do that, we use an hack that allows to check if the pointer we read is
866 + * actually a valid pointer without crashing. This can be done using the
867 + * low-level write function to read from the pointer to a valid fds (we use
868 + * a pipe for convenience). Write will fail without crashing if we try to
869 + * read from an invalid pointer, so we can finally be pretty sure if the
870 + * pointed entry is an IndicatorObjectEntry by checking if it has a valid
871 + * parent IndicatorObject */
872 +
873 + int fds[2];
874 +
875 + if (pipe (fds) > -1)
876 + {
877 + size_t data_size = sizeof (IndicatorObjectEntry);
878 +
879 + if (write (fds[1], entry, data_size) != data_size)
880 + {
881 + entry = NULL;
882 + }
883 + else
884 + {
885 + data_size = sizeof (IndicatorObject*);
886 +
887 + if (write (fds[1], entry->parent_object, data_size) != data_size ||
888 + !INDICATOR_IS_OBJECT (entry->parent_object))
889 + {
890 + entry = NULL;
891 + }
892 + }
893 +
894 + close (fds[0]);
895 + close (fds[1]);
896 + }
897 + }

Clever, but, why are we even checking for the validity of a pointer here ? Are we passing pointers around in dbus ?

« Back to merge proposal