You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyType_FromSpecWithBases: spec->name is dereferenced before checking for NULL #78682
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-08-25.18:53:49.746>created_at=<Date2018-08-25.15:26:40.523>labels= ['interpreter-core', '3.8', 'type-bug', '3.7']
title='PyType_FromSpecWithBases: spec->name is dereferenced before checking for NULL'updated_at=<Date2018-08-25.19:17:16.347>user='https://github.com/izbyshev'
In the following snippet from PyType_FromSpecWithBases() in Objects/typeobject.c, spec->name is dereferenced by strrchr() but then is checked for NULL:
/* Set the type name and qualname */
s = strrchr(spec->name, '.');
if (s == NULL)
s = (char*)spec->name;
else
s++;
[snip]
type->tp_name = spec->name;
if (!type->tp_name)
goto fail;
This was reported by Svace static analyzer.
If I were to check spec->name first, what error should I report to the caller? Is something like the following OK?
if (spec->name==NULL) {
PyErr_SetString(PyExc_SystemError,
"Type spec does not define the name field.");
goto fail;
}
But if the error message is set, then for consistency, it should be also the case that the later checks set some kind of error message.
izbyshev commented on Aug 25, 2018
izbyshevmannequin
MannequinAuthor
More actions
@enedil It seems that all later check either set a message or simply propagate the error set by a called function. Did you mean any specific later check?
New changeset 5f79b50 by Benjamin Peterson (Alexey Izbyshev) in branch 'master':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930) 5f79b50
New changeset 15dadac by Miss Islington (bot) in branch '3.7':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930) 15dadac
New changeset 323a91b by Miss Islington (bot) in branch '3.6':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930) 323a91b
Activity
izbyshev commentedon Aug 25, 2018
In the following snippet from PyType_FromSpecWithBases() in Objects/typeobject.c, spec->name is dereferenced by strrchr() but then is checked for NULL:
This was reported by Svace static analyzer.
If I were to check spec->name first, what error should I report to the caller? Is something like the following OK?
benjaminp commentedon Aug 25, 2018
Your suggested fix seems fine to me.
enedil commentedon Aug 25, 2018
But if the error message is set, then for consistency, it should be also the case that the later checks set some kind of error message.
izbyshev commentedon Aug 25, 2018
@enedil It seems that all later check either set a message or simply propagate the error set by a called function. Did you mean any specific later check?
benjaminp commentedon Aug 25, 2018
New changeset 5f79b50 by Benjamin Peterson (Alexey Izbyshev) in branch 'master':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930)
5f79b50
miss-islington commentedon Aug 25, 2018
New changeset 15dadac by Miss Islington (bot) in branch '3.7':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930)
15dadac
miss-islington commentedon Aug 25, 2018
New changeset 323a91b by Miss Islington (bot) in branch '3.6':
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930)
323a91b