Skip to content

Address CVE-2020-10735 for long objects#18

Merged
ucodery merged 1 commit into2.7from
cve-2020-10735
Dec 21, 2022
Merged

Address CVE-2020-10735 for long objects#18
ucodery merged 1 commit into2.7from
cve-2020-10735

Conversation

@ucodery
Copy link
Copy Markdown

@ucodery ucodery commented Nov 30, 2022

No description provided.

@ucodery
Copy link
Copy Markdown
Author

ucodery commented Nov 30, 2022

Documentation is incoming

Comment thread Python/sysmodule.c
Comment thread Objects/longobject.c
if (env && *env != '\0') {
errno = 0;
maxdigits = strtol(env, (char **)&endptr, 10);
if (*endptr != '\0' || errno == ERANGE || maxdigits < INT_MIN || maxdigits > INT_MAX ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be LONG_MIN and LONG_MAX?

Copy link
Copy Markdown
Author

@ucodery ucodery Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because maxdigits is type int. Would love it if C had strtoi, but well best practice seems to be using the standard strtol and then cast when in an acceptable range.

(edit) maxdigits is long but it is just holding the value until it gets put in Py_LongMaxStrDigits, which is type int.

@ucodery ucodery requested a review from swagile1 December 7, 2022 20:05
Comment thread Objects/longobject.c
Comment on lines +1414 to +1415
int max_str_digits = interp->long_max_str_digits;
if ((max_str_digits > 0) && (digitlen > max_str_digits)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first conditional in line 1415 makes me wish that the max_str_digits value were unsigned. Is that at all possible?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you saw elsewhere, this is not really possible, as 0 is a special case for "disable this check entirely", and so -1 is used as a special case for "this was unset, use the default".

Comment thread Objects/longobject.c
#undef _STRINGIFY
#undef STRINGIFY
}
Py_LongMaxStrDigits = (int)maxdigits;
Copy link
Copy Markdown

@swagile1 swagile1 Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other place I'd check that maxdigits is 0 or positive. Given that longobject needs -1 as a flag value, I want to be very certain to about this condition.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, maxdigits is checked for 0 or positive on line 4459. I suppose it is theoretically possible that _PY_LONG_MAX_STR_DIGITS_THRESHOLD is changed to a negative, but that would probably lead to multiple issues.
Note that Py_FatalError doesn't return, it will kill the process.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have been misreading this conditional. To confirm then, maxdigits has be either 0 or a value greater than _PY_LONG_MAX_STR_DIGITS_THRESHOLD, or the process will abort?

That should work then.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, the check being performed here is enforcing the interface described (at length) in stdtypes.rst

Comment thread Python/pystate.c
#ifdef WITH_TSC
interp->tscdump = 0;
#endif
interp->long_max_str_digits = -1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Well then.

@ucodery ucodery merged commit 31171bf into 2.7 Dec 21, 2022
@ucodery ucodery deleted the cve-2020-10735 branch December 21, 2022 21:51
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

Successfully merging this pull request may close these issues.

3 participants