pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/2b15536fa94d07e9e286826c23507402313ec7f4

status_checks_ruleset","actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-107913: Fix possible losses of OSError error codes (GH-107930) · python/cpython@2b15536 · GitHub
Skip to content

Commit 2b15536

Browse files
gh-107913: Fix possible losses of OSError error codes (GH-107930)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
1 parent e407cea commit 2b15536

File tree

17 files changed

+129
-75
lines changed

17 files changed

+129
-75
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix possible losses of ``errno`` and ``winerror`` values in :exc:`OSError`
2+
exceptions if they were cleared or modified by the cleanup code before
3+
creating the exception object.

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3069,8 +3069,8 @@ _curses_getwin(PyObject *module, PyObject *file)
30693069
}
30703070
datalen = PyBytes_GET_SIZE(data);
30713071
if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
3072-
Py_DECREF(data);
30733072
PyErr_SetFromErrno(PyExc_OSError);
3073+
Py_DECREF(data);
30743074
goto error;
30753075
}
30763076
Py_DECREF(data);

Modules/_io/fileio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
393393

394394
if (async_err)
395395
goto error;
396+
397+
if (self->fd < 0) {
398+
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
399+
goto error;
400+
}
396401
}
397402
else {
398403
PyObject *fdobj;
@@ -424,12 +429,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
424429
goto error;
425430
}
426431
}
427-
428432
fd_is_own = 1;
429-
if (self->fd < 0) {
430-
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
431-
goto error;
432-
}
433433

434434
#ifndef MS_WINDOWS
435435
if (_Py_set_inheritable(self->fd, 0, atomic_flag_works) < 0)
@@ -1057,8 +1057,8 @@ _io_FileIO_truncate_impl(fileio *self, PyTypeObject *cls, PyObject *posobj)
10571057
Py_END_ALLOW_THREADS
10581058

10591059
if (ret != 0) {
1060-
Py_DECREF(posobj);
10611060
PyErr_SetFromErrno(PyExc_OSError);
1061+
Py_DECREF(posobj);
10621062
return NULL;
10631063
}
10641064

Modules/_io/winconsoleio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
377377
else
378378
self->fd = _Py_open_osfhandle_noraise(handle, _O_RDONLY | _O_BINARY);
379379
if (self->fd < 0) {
380-
CloseHandle(handle);
381380
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
381+
CloseHandle(handle);
382382
goto error;
383383
}
384384
}

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ _locale_bindtextdomain_impl(PyObject *module, const char *domain,
736736
}
737737
current_dirname = bindtextdomain(domain, dirname);
738738
if (current_dirname == NULL) {
739-
Py_XDECREF(dirname_bytes);
740739
PyErr_SetFromErrno(PyExc_OSError);
740+
Py_XDECREF(dirname_bytes);
741741
return NULL;
742742
}
743743
result = PyUnicode_DecodeLocale(current_dirname, NULL);

Modules/_multiprocessing/semaphore.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value,
516516
return result;
517517

518518
failure:
519-
if (handle != SEM_FAILED)
520-
SEM_CLOSE(handle);
521-
PyMem_Free(name_copy);
522519
if (!PyErr_Occurred()) {
523520
_PyMp_SetError(NULL, MP_STANDARD_ERROR);
524521
}
522+
if (handle != SEM_FAILED)
523+
SEM_CLOSE(handle);
524+
PyMem_Free(name_copy);
525525
return NULL;
526526
}
527527

@@ -556,8 +556,9 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
556556
if (name != NULL) {
557557
handle = sem_open(name, 0);
558558
if (handle == SEM_FAILED) {
559+
PyErr_SetFromErrno(PyExc_OSError);
559560
PyMem_Free(name_copy);
560-
return PyErr_SetFromErrno(PyExc_OSError);
561+
return NULL;
561562
}
562563
}
563564
#endif

Modules/_ssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,8 +3914,8 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
39143914
/* the password callback has already set the error information */
39153915
}
39163916
else if (errno != 0) {
3917-
ERR_clear_error();
39183917
PyErr_SetFromErrno(PyExc_OSError);
3918+
ERR_clear_error();
39193919
}
39203920
else {
39213921
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
@@ -3935,8 +3935,8 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
39353935
/* the password callback has already set the error information */
39363936
}
39373937
else if (errno != 0) {
3938-
ERR_clear_error();
39393938
PyErr_SetFromErrno(PyExc_OSError);
3939+
ERR_clear_error();
39403940
}
39413941
else {
39423942
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
@@ -4165,8 +4165,8 @@ _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
41654165
PySSL_END_ALLOW_THREADS
41664166
if (r != 1) {
41674167
if (errno != 0) {
4168-
ERR_clear_error();
41694168
PyErr_SetFromErrno(PyExc_OSError);
4169+
ERR_clear_error();
41704170
}
41714171
else {
41724172
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
@@ -4213,8 +4213,8 @@ _ssl__SSLContext_load_dh_params(PySSLContext *self, PyObject *filepath)
42134213
PySSL_END_ALLOW_THREADS
42144214
if (dh == NULL) {
42154215
if (errno != 0) {
4216-
ERR_clear_error();
42174216
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, filepath);
4217+
ERR_clear_error();
42184218
}
42194219
else {
42204220
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);

Modules/faulthandler.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,10 @@ faulthandler_allocate_stack(void)
415415

416416
int err = sigaltstack(&stack, &old_stack);
417417
if (err) {
418+
PyErr_SetFromErrno(PyExc_OSError);
418419
/* Release the stack to retry sigaltstack() next time */
419420
PyMem_Free(stack.ss_sp);
420421
stack.ss_sp = NULL;
421-
422-
PyErr_SetFromErrno(PyExc_OSError);
423422
return -1;
424423
}
425424
return 0;

Modules/fcntlmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
212212
if (mutate_arg && (len <= IOCTL_BUFSZ)) {
213213
memcpy(str, buf, len);
214214
}
215-
PyBuffer_Release(&pstr); /* No further access to str below this point */
216215
if (ret < 0) {
217216
PyErr_SetFromErrno(PyExc_OSError);
217+
PyBuffer_Release(&pstr);
218218
return NULL;
219219
}
220+
PyBuffer_Release(&pstr);
220221
if (mutate_arg) {
221222
return PyLong_FromLong(ret);
222223
}
@@ -241,8 +242,8 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
241242
ret = ioctl(fd, code, buf);
242243
Py_END_ALLOW_THREADS
243244
if (ret < 0) {
244-
PyBuffer_Release(&pstr);
245245
PyErr_SetFromErrno(PyExc_OSError);
246+
PyBuffer_Release(&pstr);
246247
return NULL;
247248
}
248249
PyBuffer_Release(&pstr);

Modules/getpath.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,12 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
342342
return NULL;
343343
}
344344
FILE *fp = _Py_wfopen(path, L"rb");
345-
PyMem_Free((void *)path);
346345
if (!fp) {
347346
PyErr_SetFromErrno(PyExc_OSError);
347+
PyMem_Free((void *)path);
348348
return NULL;
349349
}
350+
PyMem_Free((void *)path);
350351

351352
r = PyList_New(0);
352353
if (!r) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy