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

gh-111178: Avoid calling functions from incompatible pointer types in descrobject.c #112861

Merged
merged 49 commits into from
Jan 2, 2024

Conversation

chrstphrchvz
Copy link
Contributor

@chrstphrchvz chrstphrchvz commented Dec 8, 2023

Objects/descrobject.c:1913:5: warning: cast from 'void (*)(mappingproxyobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 1913 |     (destructor)mappingproxy_dealloc,           /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:1160: note: mappingproxy_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
Objects/descrobject.c:808:5: warning: cast from 'PyObject *(*)(PyMemberDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyMemberDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  808 |     (descrgetfunc)member_get,                   /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
Objects/descrobject.c:809:5: warning: cast from 'int (*)(PyMemberDescrObject *, PyObject *, PyObject *)' (aka 'int (*)(PyMemberDescrObject *, struct _object *, struct _object *)') to 'descrsetfunc' (aka 'int (*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  809 |     (descrsetfunc)member_set,                   /* tp_descr_set */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:1682:19: runtime error: call to function member_set through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:227: note: member_set defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1682:19 in
Objects/object.c:1564:19: runtime error: call to function member_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:160: note: member_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1564:19 in
Example compiler warning:

Objects/descrobject.c:703:5: warning: cast from 'void (*)(PyDescrObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  703 |     (destructor)descr_dealloc,                  /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:2857:5: runtime error: call to function descr_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:23: note: descr_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:2857:5 in
Objects/descrobject.c:771:5: warning: cast from 'PyObject *(*)(PyMethodDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyMethodDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  771 |     (descrgetfunc)classmethod_get,              /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/typeobject.c:10293:24: runtime error: call to function classmethod_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:94: note: classmethod_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:10293:24 in
Objects/descrobject.c:845:5: warning: cast from 'PyObject *(*)(PyGetSetDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyGetSetDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  845 |     (descrgetfunc)getset_get,                   /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
Objects/descrobject.c:846:5: warning: cast from 'int (*)(PyGetSetDescrObject *, PyObject *, PyObject *)' (aka 'int (*)(PyGetSetDescrObject *, struct _object *, struct _object *)') to 'descrsetfunc' (aka 'int (*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  846 |     (descrsetfunc)getset_set,                   /* tp_descr_set */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/typeobject.c:4861:19: runtime error: call to function getset_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:180: note: getset_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:4861:19 in
Objects/descrobject.c:739:5: warning: cast from 'PyObject *(*)(PyMethodDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyMethodDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  739 |     (descrgetfunc)method_get,                   /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:1621:15: runtime error: call to function method_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:138: note: method_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1621:15 in
Objects/descrobject.c Outdated Show resolved Hide resolved
@encukou encukou merged commit acf4cf5 into python:main Jan 2, 2024
31 checks passed
@chrstphrchvz chrstphrchvz deleted the patch-111178-descrobject branch January 2, 2024 14:22
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…pes in descrobject.c (pythonGH-112861)

Fix undefined behavior warnings (UBSan  -fsanitize=function), for example:

Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:1160: note: mappingproxy_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…pes in descrobject.c (pythonGH-112861)

Fix undefined behavior warnings (UBSan  -fsanitize=function), for example:

Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:1160: note: mappingproxy_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…pes in descrobject.c (pythonGH-112861)

Fix undefined behavior warnings (UBSan  -fsanitize=function), for example:

Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:1160: note: mappingproxy_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants