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

switched to secure mkstemp() #460

Merged
merged 7 commits into from
Mar 13, 2018
Merged

Conversation

tpltnt
Copy link
Contributor

@tpltnt tpltnt commented Jan 15, 2018

Hi there,

I switched out the deprecated mktemp() for the secure (and recommended) mkstemp().

Cheers
tpltnt

@tpltnt
Copy link
Contributor Author

tpltnt commented Jan 28, 2018

The tests pass on my testing machine (Debian 9.3):

Ran 1504 tests in 433.457s

PASSED (skips=6, unexpectedSuccesses=2, successes=1496)

Most failiing tests are due to exceptions.IOError: [Errno 24] Too many open files ... and only one due to exceptions.ImportError: cannot import name failure. Any idea on how to proceed?

@codecov-io
Copy link

codecov-io commented Feb 5, 2018

Codecov Report

Merging #460 into master will decrease coverage by 2.91%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
- Coverage   93.03%   90.12%   -2.92%     
==========================================
  Files         232      144      -88     
  Lines       58668    27304   -31364     
  Branches     7649     3925    -3724     
==========================================
- Hits        54581    24607   -29974     
+ Misses       3122     1957    -1165     
+ Partials      965      740     -225
Impacted Files Coverage Δ
src/allmydata/node.py 93.22% <100%> (+0.1%) ⬆️
src/allmydata/test/test_stats.py
src/allmydata/test/test_magic_folder.py
src/allmydata/test/test_codec.py
src/allmydata/test/cli/common.py
src/allmydata/test/test_connections.py
src/allmydata/test/test_hung_server.py
src/allmydata/test/mutable/test_datahandle.py
src/allmydata/test/test_ftp.py
src/allmydata/test/mutable/test_exceptions.py
... and 80 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8f747c...a41d827. Read the comment docs.

@tpltnt tpltnt force-pushed the secure-mktemp branch 2 times, most recently from db9f902 to c054897 Compare February 7, 2018 10:37
Copy link
Member

@exarkun exarkun left a comment

Choose a reason for hiding this comment

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

Thanks!

# * appveyor complains about missing 'resource' module on Windows
if 'Darwin' == system():
import resource
resource.setrlimit(resource.RLIMIT_NOFILE, (2000, -1))
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is probably only necessary because the change to mkstemp() results in a leaked file descriptor per call. If you add a call to close the file descriptor then they won't leak and the process won't run out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it with no success. Currently I can't solve this and would withdraw this PR if there is no silver lining within the next week.

@tpltnt tpltnt force-pushed the secure-mktemp branch 5 times, most recently from af1ca2d to 3572f42 Compare March 2, 2018 01:34
@@ -273,12 +312,12 @@ def init_tempdir(self):
# tempfile.TemporaryFile) to put large request bodies in the given
# directory. Without this, the default temp dir is usually /tmp/,
# which is frequently too small.
test_name = tempfile.mktemp()
self.tempfile_fd, test_name = tempfile.mkstemp()
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the only change in addition to switching to tempfile.mkstemp() that is needed to make this work is os.close(tempfile_fd). This temporary file doesn't seem to be used anywhere beyond the next line so there's no reason to keep the descriptor open. It seems the intention is only to verify that temporary files get created in the right directory. If you revert the context manager related changes and just os.close(tempfile_fd) here I would expect things to be in good shape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a similar thought, but wasn't sure. Thank you for helping and pushing.

@tpltnt
Copy link
Contributor Author

tpltnt commented Mar 2, 2018

everything is green \o/ ... thank you @exarkun

@meejah meejah dismissed exarkun’s stale review March 13, 2018 22:10

all comments addressed

@meejah meejah merged commit 1c2ff92 into tahoe-lafs:master Mar 13, 2018
@meejah
Copy link
Contributor

meejah commented Mar 13, 2018

Cool, thanks. Sorry this took a while to get merged!

@tpltnt tpltnt deleted the secure-mktemp branch March 14, 2018 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants