Skip to content
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

Prevent data being truncated over persistent connection socket #43885

Merged
merged 9 commits into from Aug 10, 2018

Conversation

Qalthos
Copy link
Contributor

@Qalthos Qalthos commented Aug 9, 2018

SUMMARY

Fixes #43748

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ansible-connection

ANSIBLE VERSION
2.7

We can't rely on readline(), so send the size of the data first. We can
then read that many bytes from the stream on the recieving end.
@Qalthos Qalthos changed the title Remove unicode guillotine Prevent data being truncated over persistent connection socket Aug 9, 2018
@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. networking Network category support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Aug 9, 2018
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Aug 9, 2018
@ansibot

This comment has been minimized.

from ansible.module_utils.six.moves import cPickle


def write_to_socket(fd, obj):
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming wise, I don't think these are sockets so we probably don't want to call it that. (also shuld remove socket from the comments)

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Aug 9, 2018
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Aug 9, 2018
@abadger
Copy link
Contributor

abadger commented Aug 10, 2018

This looks good to me now. +1 to merge.

Note, however, that we should probably switch to using selectors in the future so that we don't ever hang. Here's some test code that demonstrates using selectors: https://gist.github.com/abadger/3c65c3b2d0a8e776bc2b35cd6b45384f

It uses selectors on both sides so that neither writing nor reading will hang.

@ansibot ansibot added the shipit This PR is ready to be merged by Core label Aug 10, 2018
@Qalthos Qalthos merged commit f221105 into ansible:devel Aug 10, 2018
@Qalthos Qalthos deleted the remove-unicode-guillotine branch August 10, 2018 13:27
alikins added a commit that referenced this pull request Aug 10, 2018
* devel: (30 commits)
  Prevent data being truncated over persistent connection socket (#43885)
  Fix eos_command integration test failures (#43922)
  Update iosxr cliconf plugin (#43837)
  win_domain modules: ensure Netlogon service is still running after promotion (#43703)
  openvswitch_db : Handle column value conversion and idempotency in no_key case (#43869)
  Fix typo
  Fix spelling of ansbile to ansible (#43898)
  added platform guides for NOS and VOSS (#43854)
  Fix download URL for yum integration test.
  New module for managing EMC VNX Block storage (#42945)
  Docker integration tests: factorize setup (#42306)
  VMware: datastore selection (#35812)
  Remove unnecessary features from cli_command (#43829)
  [doc] import_role: mention version from which behavior changed and fix some typos (#43843)
  Add source interface and use-vrf features (#43418)
  Fix unreferenced msg from vmware_host (#43872)
  set supports_generate_diff to False vyos (#43873)
  add group_by_os_family in azure dynamic inventory (#40702)
  ansible-test: Create public key creating Windows targets (#43760)
  azure_rm_loadbalancer_facts.py: list() takes at least 2 arguments fix (#29046) (#29050)
  ...
Qalthos added a commit to Qalthos/ansible that referenced this pull request Aug 14, 2018
…le#43885)

* Change how data is sent to the persistent connection socket.

We can't rely on readline(), so send the size of the data first. We can
then read that many bytes from the stream on the recieving end.

* Set pty to noncanonical mode before sending

* Now that we send data length, we don't need a sentinel anymore

* Copy socket changes to persistent, too

* Use os.write instead of fdopen()ing and using that.

* Follow pickle with sha1sum of pickle

* Swap order of vars and init being passed to ansible-connection

(cherry picked from commit f221105)
mattclay pushed a commit that referenced this pull request Aug 14, 2018
* Change how data is sent to the persistent connection socket.

We can't rely on readline(), so send the size of the data first. We can
then read that many bytes from the stream on the recieving end.

* Set pty to noncanonical mode before sending

* Now that we send data length, we don't need a sentinel anymore

* Copy socket changes to persistent, too

* Use os.write instead of fdopen()ing and using that.

* Follow pickle with sha1sum of pickle

* Swap order of vars and init being passed to ansible-connection

(cherry picked from commit f221105)
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. networking Network category shipit This PR is ready to be merged by Core support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
3 participants