all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: Eli Zaretskii <eliz@gnu.org>, Paul Eggert <eggert@cs.ucla.edu>
Cc: jporterbugs@gmail.com, larsi@gnus.org, bug-gnulib@gnu.org,
	57129@debbugs.gnu.org
Subject: bug#57129: 29.0.50; Improve behavior of conditionals in Eshell
Date: Sun, 21 Aug 2022 18:20:52 +0200	[thread overview]
Message-ID: <1903912.fIoEIV5pvu@nimes> (raw)
In-Reply-To: <2271941c-3ac3-1525-4d9f-62c757641d6c@cs.ucla.edu>

[-- Attachment #1: Type: text/plain, Size: 2604 bytes --]

Paul Eggert wrote:
> > Since this contradicts what you debugged on mingw, I ran the test 10000
> > times on native Windows. Result:
> >    - on 32-bit mingw, no failure.
> >    - on 64-bit mingw, around 30 failures (or around 10 failures with Paul's
> >      newest patch). That is, a probability of ca. 0.3% of getting the same
> >      file name as on the previous call.
> 
> That's odd, for two reasons. First, 64-bit and 32-bit mingw shouldn't 
> differ, as they both use uint_fast64_t which should be the same width on 
> both platforms. Second, I could not reproduce the problem on 64-bit 
> Ubuntu x86-64 (after altering tempname.c to always define 
> HAS_CLOCK_ENTROPY to false) test-tempname always succeeded in 10000 tries.
> 
> Could you investigate further why mingw 64-bit fails?

That's odd indeed, and here are more detailed results.

I changed test-tempname.c to skip the case 1 and execute only case 2, and
added printf statements per the attached tempname.c.diff. Then ran
$ for i in `seq 1000`; do ./test-tempname.exe; done 2>&1 | tee out1000

In 32-bit mingw, the result is fully deterministic: each run behaves the same.
The first file name is always gl-temp-3FXzHa.xyz;
the second file name is always gl-temp-HgtmVy.xyz.

Thus, for a single Emacs process, things will look fine, but as soon as someone
starts to use temporary files in two different Emacs processes, in the way Eli
described, there will be massive collisions.

In 64-bit mingw, the 'tempname 1' value is deterministic. This simply shows
that Windows 10 does not use address space randomization (ASLR).
The 'tempname 2' value is unique 99% of the time:
  $ grep 'tempname 2' out1000-mingw64 | sort | uniq -d | wc -l
  8
The interesting thing is that each of the duplicate values of v is occurring
in the same process:
  $ grep 'tempname 2' out1000-mingw64 | sort | uniq -d
  tempname 2 v=0x00c1efa91fb60900
  tempname 2 v=0x32ccb2946974f2f6
  tempname 2 v=0x5cafcc69e359a147
  tempname 2 v=0x6d0676018e27d771
  tempname 2 v=0x6d95bd6083168079
  tempname 2 v=0x7cb95116ffae8ece
  tempname 2 v=0xe0afc7086808ce33
  tempname 2 v=0xe46a60c28fb0ec7f
  $ grep 'tempname 2' out1000-mingw64 | grep -n 0x00c1efa91fb60900
  560:tempname 2 v=0x00c1efa91fb60900
  561:tempname 2 v=0x00c1efa91fb60900
  $ grep 'tempname 2' out1000-mingw64 | grep -n 0x32ccb2946974f2f6
  1129:tempname 2 v=0x32ccb2946974f2f6
  1130:tempname 2 v=0x32ccb2946974f2f6
  etc.

So, in this environment, different Emacs processes will not conflict. But
within a single Emacs process, with 1% probability, the two resulting file
names are the same.

Bruno

[-- Attachment #2: tempname.c.diff --]
[-- Type: text/x-patch, Size: 817 bytes --]

--- lib/tempname.c	2022-08-16 21:27:10.455608233 +0200
+++ tempname.c	2022-08-17 01:55:47.590241280 +0200
@@ -308,6 +308,7 @@
 
   for (count = 0; count < attempts; ++count)
     {
+fprintf(stderr,"tempname 1 v=0x%016llx\n", v);  fflush(stderr);
       for (size_t i = 0; i < x_suffix_len; i++)
         {
           if (vdigits == 0)
@@ -315,6 +316,7 @@
               do
                 {
                   v = random_bits (v, use_getrandom);
+fprintf(stderr,"tempname 2 v=0x%016llx\n", v);  fflush(stderr);
                   use_getrandom = true;
                 }
               while (unfair_min <= v);
@@ -326,7 +328,7 @@
           v /= 62;
           vdigits--;
         }
-
+fprintf(stderr,"tempname filename=%s\n", tmpl); fflush(stderr);
       fd = tryfunc (tmpl, args);
       if (fd >= 0)
         {

[-- Attachment #3: out1000-mingw32.gz --]
[-- Type: application/gzip, Size: 942 bytes --]

[-- Attachment #4: out1000-mingw64.gz --]
[-- Type: application/gzip, Size: 38377 bytes --]

  reply	other threads:[~2022-08-21 16:20 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11  2:43 bug#57129: 29.0.50; Improve behavior of conditionals in Eshell Jim Porter
2022-08-11  2:46 ` Jim Porter
2022-08-12 15:22   ` Lars Ingebrigtsen
2022-08-13  5:14     ` Jim Porter
2022-08-13  7:01       ` Eli Zaretskii
2022-08-13 18:56         ` Jim Porter
2022-08-14  5:07           ` Eli Zaretskii
2022-08-14  5:37             ` Jim Porter
2022-08-14  7:30               ` Eli Zaretskii
2022-08-14 21:40                 ` Jim Porter
2022-08-15 12:13                   ` Eli Zaretskii
2022-08-15 16:14                     ` Jim Porter
2022-08-15 16:49                       ` Eli Zaretskii
2022-08-15 18:08                         ` Jim Porter
2022-08-15 18:21                           ` Eli Zaretskii
2022-08-15 18:30                             ` Jim Porter
2022-08-15 18:58                               ` Eli Zaretskii
2022-08-15 20:55                                 ` Paul Eggert
     [not found]                                 ` <af0af29b-2362-77db-081e-046158937808@cs.ucla.edu>
2022-08-15 21:22                                   ` Bruno Haible
2022-08-16 11:04                                   ` Eli Zaretskii
     [not found]                                   ` <835yish2l1.fsf@gnu.org>
2022-08-16 13:35                                     ` Bruno Haible
     [not found]                                     ` <1871347.6tgchFWduM@nimes>
2022-08-16 13:51                                       ` Eli Zaretskii
     [not found]                                       ` <838rnofgad.fsf@gnu.org>
2022-08-16 14:40                                         ` Bruno Haible
2022-08-16 16:25                                           ` Eli Zaretskii
     [not found]                                           ` <83wnb8dukz.fsf@gnu.org>
2022-08-16 16:54                                             ` Paul Eggert
     [not found]                                             ` <206e38df-2db4-a46a-e0ff-952bc8ab939c@cs.ucla.edu>
2022-08-16 17:04                                               ` Eli Zaretskii
     [not found]                                               ` <83sflwdsr2.fsf@gnu.org>
2022-08-16 17:30                                                 ` Paul Eggert
2022-08-16 17:41                                                 ` Eli Zaretskii
     [not found]                                                 ` <ceeeaa86-6199-93b1-ff65-bbd3e531e235@cs.ucla.edu>
2022-08-16 17:56                                                   ` Eli Zaretskii
2022-08-16 17:25                                             ` Paul Eggert
2022-08-16 17:29                                             ` Bruno Haible
     [not found]                                             ` <f329244a-cba7-65cd-2e5d-2630eba3e9e9@cs.ucla.edu>
2022-08-16 17:47                                               ` Eli Zaretskii
2022-08-16 19:11                                                 ` Paul Eggert
     [not found]                                                 ` <d95734ab-6bbc-7403-c1f8-fbf742badda4@cs.ucla.edu>
2022-08-16 20:12                                                   ` Bruno Haible
2022-08-17 11:08                                                   ` Eli Zaretskii
     [not found]                                                   ` <83h72bdt4z.fsf@gnu.org>
2022-08-18  6:05                                                     ` Paul Eggert
     [not found]                                                     ` <57b8f10f-8e9b-5951-e5ad-8cba2a8cb569@cs.ucla.edu>
2022-08-18  6:44                                                       ` Eli Zaretskii
     [not found]                                             ` <2594092.Isy0gbHreE@nimes>
2022-08-16 17:52                                               ` Eli Zaretskii
2022-08-16 20:06                                                 ` Bruno Haible
     [not found]                                                 ` <2606289.q0ZmV6gNhb@nimes>
2022-08-17 11:29                                                   ` Eli Zaretskii
2022-08-16 19:59                                         ` Bruno Haible
     [not found]                                         ` <2135151.C4sosBPzcN@nimes>
2022-08-16 20:53                                           ` Paul Eggert
2022-08-21 16:20                                             ` Bruno Haible [this message]
2022-08-21 16:32                                               ` Eli Zaretskii
2022-08-21 17:17                                               ` Bruno Haible
2022-08-22 20:47                                                 ` Paul Eggert
     [not found]                                                 ` <2dc7ede0-eca7-baf5-f89a-f5d292b80808@cs.ucla.edu>
2022-08-23  0:13                                                   ` Bruno Haible
     [not found]                                                   ` <3893771.2iPT33SAM4@nimes>
2022-08-23 11:18                                                     ` Eli Zaretskii
     [not found]                                                     ` <831qt79pjj.fsf@gnu.org>
2022-08-23 14:49                                                       ` Bruno Haible
2022-08-23 16:07                                                         ` Eli Zaretskii
2022-08-20 18:03                                 ` Jim Porter
2022-08-20 18:14                                   ` Eli Zaretskii
2022-08-20 18:49                                     ` Jim Porter
2022-08-24 21:41                                   ` Jim Porter
2022-08-26  5:10                                     ` Jim Porter
2023-03-16  5:35                                       ` Jim Porter
2022-08-14  5:03       ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1903912.fIoEIV5pvu@nimes \
    --to=bruno@clisp.org \
    --cc=57129@debbugs.gnu.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=jporterbugs@gmail.com \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.