Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_related breaks existing ObjectProperties parent Objects #237

Open
gtback opened this issue Mar 30, 2015 · 2 comments
Open

add_related breaks existing ObjectProperties parent Objects #237

gtback opened this issue Mar 30, 2015 · 2 comments

Comments

@gtback
Copy link
Contributor

gtback commented Mar 30, 2015

The current implementation of add_related (used to relate two different objects together) is currently broken. If you create three ObjectProperties (A, B and C), and run the following:

A.add_related(B, ...)
C.add_related(A, ...)

then the relationship between A and B will be broken. This is due to the fact that relationships are between Objects, but the add_related function operates on the contained ObjectProperties. add_related creates a new RelatedObject (see here) as the parent of the ObjectProperties that is being added. Thus, the relationship between A and B is severed as a result of the second call.

A workaround is to switch the order of these calls. This is not a 100% solution for more complicated sets of relationships, but should hopefully help until we can fix this.

C.add_related(A, ...)
A.add_related(B, ...)

Thanks to @brlogan for identifying this bug.

@gtback
Copy link
Contributor Author

gtback commented Mar 30, 2015

As a more concrete example:

from cybox.objects.artifact_object import Artifact
from cybox.objects.email_message_object import EmailMessage, Attachments
from cybox.objects.file_object import File
filename = "example.txt"
data = "blah blah blah contents of file"

f = File()
f.file_name = filename
a = Artifact(data, Artifact.TYPE_FILE)
f.add_related(a, "Child_Of") # This is the A.add_related(B, ...)

m = EmailMessage()
m.from_ = "bob@example.com"
m.subject = "this is an email"
m.attachments = Attachments()
m.add_related(f, "Contains", inline=True) # This is C.add_related(A, ...)
# Move it to here: 
# f.add_related(a, "Child_Of")
m.attachments.append(f.parent.id_)

@brlogan
Copy link

brlogan commented Mar 31, 2015

Thanks for looking into this, @gtback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants