GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-111178: Avoid calling functions from incompatible pointer types in descrobject.c by chrstphrchvz · Pull Request #112861 · python/cpython

Conversation

@chrstphrchvz

@chrstphrchvz chrstphrchvz commented Dec 8, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
chrstphrchvz added 30 commits December 7, 2023 22:01
@chrstphrchvz
Update descrobject.c
e9c0f5f
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
@chrstphrchvz
Update descrobject.c
31f6c07
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
@chrstphrchvz
Update descrobject.c
b950d1a
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
@chrstphrchvz
Update descrobject.c
505a00c
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
@chrstphrchvz
Update descrobject.c
2e1b409
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
@chrstphrchvz
Update descrobject.c
b82d048
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
@chrstphrchvz
Make method_repr() compatible with reprfunc
eb6c22e
@chrstphrchvz
Make classmethoddescr_call() compatible with ternaryfunc
60c0d7a
@chrstphrchvz
Make getset_repr() compatible with reprfunc
1de5a1a
@chrstphrchvz
Make member_repr() compatible with reprfunc
8b57573
@chrstphrchvz
Make wrapperdescr_repr() compatible with reprfunc
d2f06e6
@chrstphrchvz
Make wrapperdescr_call() compatible with ternaryfunc
4cd2e6d
@chrstphrchvz
Make wrapper_repr() compatible with reprfunc
f32c9e0
@chrstphrchvz
Make wrapper_reduce() compatible with PyCFunction
83df0df
@chrstphrchvz
Make wrapper_hash() compatible with hashfunc
a4c7f17
@chrstphrchvz
Make wrapper_dealloc() compatible with destructor
be0fb74
@chrstphrchvz
Make wrapper_objclass() compatible with getter
356c2fe
@chrstphrchvz
Make wrapper_name() compatible with getter
ec4ca04
@chrstphrchvz
Make wrapper_qualname() compatible with getter
9ebb68f
@chrstphrchvz
Make wrapper_text_signature() compatible with getter
de99189
@chrstphrchvz
Make wrapper_doc() compatible with getter
9b43a8d
@chrstphrchvz
mappingproxy_dealloc(): less inconsistent parameter name
32b8dfe
@chrstphrchvz
descr_dealloc(): less inconsistent parameter name
78419d6
@chrstphrchvz
Make mappingproxy_getiter() compatible with getiterfunc
97d3ee8
@chrstphrchvz
Make mappingproxy_hash() compatible with hashfunc
30cd173
@chrstphrchvz
Make mappingproxy_str() compatible with reprfunc
fcce565
@chrstphrchvz
Make mappingproxy_repr() compatible with reprfunc
776acd7
@chrstphrchvz
Make mappingproxy_richcompare() compatible with richcmpfunc
f4dfb12
@chrstphrchvz
Remove redundant cast of property_clear()
80da821
@chrstphrchvz
Make mappingproxy_contains() compatible with objobjproc
7b903ea
chrstphrchvz added 17 commits December 7, 2023 22:02
@chrstphrchvz
Make wrapper_call() compatible with ternaryfunc
d646a9d
@chrstphrchvz
Make mappingproxy_reversed() compatible with PyCFunction
75a4980
@chrstphrchvz
Make mappingproxy_copy() compatible with PyCFunction
e96377d
@chrstphrchvz
Make mappingproxy_items() compatible with PyCFunction
0002cba
@chrstphrchvz
Make mappingproxy_values() compatible with PyCFunction
057c059
@chrstphrchvz
Make mappingproxy_keys() compatible with PyCFunction
57224d0
@chrstphrchvz
Make mappingproxy_getitem() compatible with binaryfunc
071d2bc
@chrstphrchvz
Make mappingproxy_len() compatible with lenfunc
65f0a90
@chrstphrchvz
Make method_get_doc() compatible with getter
385dbfd
@chrstphrchvz
Make descr_get_qualname() compatible with getter
a0e0ae0
@chrstphrchvz
Make method_get_text_signature() compatible with getter
ff534a1
@chrstphrchvz
Make member_get_doc() compatible with getter
ae28dc1
@chrstphrchvz
Make getset_get_doc() compatible with getter
547cbc0
@chrstphrchvz
Make wrapperdescr_get_doc() compatible with getter
6360a46
@chrstphrchvz
Make wrapperdescr_get_text_signature() compatible with getter
e823bed
@chrstphrchvz
Make wrapperdescr_get() compatible with descrgetfunc
6c15c76
@chrstphrchvz
Make descr_reduce() compatible with PyCFunction
238724f
@bedevere-app bedevere-app Bot added the awaiting review label Dec 8, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Dec 8, 2023
UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178
Closed
chrstphrchvz
chrstphrchvz commented Dec 8, 2023
View reviewed changes
Comment thread Objects/descrobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

chrstphrchvz added 2 commits December 8, 2023 02:23
@chrstphrchvz
Need to update type in cast
cb6f751
@chrstphrchvz
Make mappingproxy_get() compatible with _PyCFunctionFast
dd64280
@encukou encukou added the skip news label Jan 2, 2024
@encukou
encukou merged commit acf4cf5 into python:main Jan 2, 2024
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 2, 2024
@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
@chrstphrchvz @kulikjak
pythongh-111178: Avoid calling functions from incompatible pointer ty…
465eac6
…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
@chrstphrchvz @aisk
pythongh-111178: Avoid calling functions from incompatible pointer ty…
adb6a18
…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
@chrstphrchvz @Glyphack
pythongh-111178: Avoid calling functions from incompatible pointer ty…
3297cb3
…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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@chrstphrchvz @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.