Skip to content

locale.c: Don't do asymmetric back out on failure #23172

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

Open
wants to merge 4 commits into
base: blead
Choose a base branch
from

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Apr 3, 2025

This fixes #23159

When something goes wrong doing locale-aware string collation, the code attempts to carry on as well as can be expected. prior to this commit the backout code was asymmetric, trying to undo things that had not been done. This happened when the failure was early on.

In the case of this ticket, the platform has a defective locale that was detectable before getting very far along.

The solution adopted here is to jump to a different label for those early failures that does less backout than for later failures.

  • This set of changes does not require a perldelta entry.

@khwilliamson khwilliamson force-pushed the smoke-me/khw-darwin_locale branch from eb43f7f to b9e1bad Compare April 3, 2025 18:54
@Leont
Copy link
Contributor

Leont commented Apr 6, 2025

It's not clear to me if free_me, sans_nuls and sans_highs will be correctly freed when an error occurs.

@tonycoz
Copy link
Contributor

tonycoz commented Apr 7, 2025

There's a few paths where they can leak.

@sevan
Copy link
Contributor

sevan commented Apr 10, 2025

All tests successful.
Elapsed: 2660 sec
u=22.73  s=11.66  cu=2088.93  cs=219.98  scripts=2748  tests=1180795

@khwilliamson khwilliamson force-pushed the smoke-me/khw-darwin_locale branch from b9e1bad to a25786b Compare April 20, 2025 21:24
@khwilliamson
Copy link
Contributor Author

I've reexamined this commit, and don't see anything wrong with it. It does look to me that the first two goto's can be replaced by returns, as nothing has been allocated yet. But I don't see any leak paths. @tonycoz can you provide a case

@@ -10090,7 +10090,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
if (UNLIKELY(! xbuf)) {
DEBUG_L(PerlIO_printf(Perl_debug_log,
"mem_collxfrm_: Couldn't malloc %zu bytes\n", xAlloc));
goto bad;
goto bad_no_strxfrm;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a potential memory leak to me. At this point, sans_highs, sans_nuls, and free_me may have been allocated, but bad_no_strxfrm skips over the free() calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow I got it into my head that that label had code to do the necessary cleanup, and was blind to the fact that it didn't. But with the latest push, it should now.

This is in preparation for the next commit where it will be split out
to be a stand-alone macro.
This fixes #23519

When something goes wrong doing locale-aware string collation, the code
attempts to carry on as well as can be expected.  Prior to this commit
the backout code was asymmetric, trying to undo things that had not been
done.  This happened when the failure was early on.

In the case of this ticket, the platform has a defective locale that was
detectable before getting very far along.

The solution adopted here is to jump to a different label for those
early failures that does less backout than for later failures.
This changes a subsidiary function's return value from void to bool,
returning false if it finds the locale doesn't have sane collation.

The calling function is changed to check this, and give up immediately
if the locale isn't sane.
The previous commit removed a block; so can outdent
@khwilliamson khwilliamson force-pushed the smoke-me/khw-darwin_locale branch from 6449b82 to 13d2b29 Compare April 22, 2025 15:55
@sevan
Copy link
Contributor

sevan commented Apr 22, 2025

Test suite still passes on Tiger/i386 with the latest version of the patch applied.

All tests successful.
Elapsed: 2294 sec
u=23.85  s=10.62  cu=1848.69  cs=199.30  scripts=2658  tests=1314307

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.

locale.t ends with panic "attempting to unlock already unlocked locale" on Mac OS X Tiger
5 participants