Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
On 12/7/18 10:15 AM, David Seikel wrote: >> Sorry for the delay replying, gmail unsubscribed everybody from the >> list again and I had to do the web gui dance. > > I had left my read only gmail account on this list as a comparison to > my account on my own email server. As expected, the gmail one did the > bouncy spam thing, mine didn't. So I'll go and properly remove my > gmail one now, should not be any of my gmail accounts left in your > mailing lists anymore. That's one less to dance for next time. There's a little over 100 gmail accounts subscribed to the list. And the dreamhost web interface can't _not_ sort them alphabetically, so I have to click on every letter one at a time to bring up _that_ page of accounts and unclick the ones with "B" as their disabled reason, then submit to reload the page, then click on the next letter. (And there used to be some starting with digits, but those apparently dropped off...) My internet here in milwaukee is via phone tethering (never got a cable modem for the apartment and I don't connect personal devices to the $DAYJOB network), and since dreamhost's https support is only for the main website and _not_ the lists.landley.net server, I prefer to do the unavoidably plaintext password admin stuff via USB cable rather than wireless access point (so at least _one_ less hop is insecurely encrypted), and I didn't have a working USB cable with me. (The little short one is a "charge but not carry data" cable, which I prefer whem plugging into who knows what USB power to keep my phone charged, but didn't have the other one in my backpack so had to do it when I got home.) Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
> Sorry for the delay replying, gmail unsubscribed everybody from the > list again and I had to do the web gui dance. I had left my read only gmail account on this list as a comparison to my account on my own email server. As expected, the gmail one did the bouncy spam thing, mine didn't. So I'll go and properly remove my gmail one now, should not be any of my gmail accounts left in your mailing lists anymore. That's one less to dance for next time. -- A big old stinking pile of genius that no one wants coz there are too many silver coated monkeys in the world. ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
On 12/6/18 10:55 AM, enh wrote: > it occurred to me overnight that the passwd code allows '/'. plus, as > i've said, it seems to be slightly wrong. so i've just sent a > replacement for my second patch (to be applied on top of the first > patch) that just does the simplest xgetrandom + convert to valid > character loop. > > can we at least get the first patch in, since mktemp is pretty broken > right now (_except_ for -u, which was all the old tests exercised)? Can you send me just a tests/mktemp.test patch to demonstrate the failures? I'll try to fix it this evening. (Too many changes at once, I need to know what success looks like...) Thanks, Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
it occurred to me overnight that the passwd code allows '/'. plus, as i've said, it seems to be slightly wrong. so i've just sent a replacement for my second patch (to be applied on top of the first patch) that just does the simplest xgetrandom + convert to valid character loop. can we at least get the first patch in, since mktemp is pretty broken right now (_except_ for -u, which was all the old tests exercised)? On Wed, Dec 5, 2018 at 5:34 PM enh wrote: > > (sent. you can just run `./toybox mktemp -u > tmp.XXX` to see the effect.) > On Wed, Dec 5, 2018 at 5:27 PM enh wrote: > > > > which seems to have found a bug in the password code? > > > > i'll send you that patch as a follow up to this one, and you can look at > > why if mktemp reuses that code, long enough templates end in a string of > > '.'s... > > > > On Wed, Dec 5, 2018 at 4:08 PM enh wrote: > >> > >> note that you've already got "random ascii" code in password.c --- i have > >> a half-finished patch that switches mktemp over to reusing that instead... > >> > >> On Wed, Dec 5, 2018 at 3:40 PM Rob Landley wrote: > >>> > >>> On 12/5/18 5:03 PM, enh via Toybox wrote: > >>> > Multiple bugs: > >>> > > >>> > * We weren't outputting anything in the case where we actually create a > >>> > file or directory (but all the tests were for the -u case). > >>> > > >>> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The > >>> > new tests cover these. > >>> > >>> Sigh. (See attached...) > >>> > >>> Lemme try to reconcile them... > >>> > >>> Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
(sent. you can just run `./toybox mktemp -u tmp.XXX` to see the effect.) On Wed, Dec 5, 2018 at 5:27 PM enh wrote: > > which seems to have found a bug in the password code? > > i'll send you that patch as a follow up to this one, and you can look at why > if mktemp reuses that code, long enough templates end in a string of '.'s... > > On Wed, Dec 5, 2018 at 4:08 PM enh wrote: >> >> note that you've already got "random ascii" code in password.c --- i have a >> half-finished patch that switches mktemp over to reusing that instead... >> >> On Wed, Dec 5, 2018 at 3:40 PM Rob Landley wrote: >>> >>> On 12/5/18 5:03 PM, enh via Toybox wrote: >>> > Multiple bugs: >>> > >>> > * We weren't outputting anything in the case where we actually create a >>> > file or directory (but all the tests were for the -u case). >>> > >>> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The >>> > new tests cover these. >>> >>> Sigh. (See attached...) >>> >>> Lemme try to reconcile them... >>> >>> Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
which seems to have found a bug in the password code? i'll send you that patch as a follow up to this one, and you can look at why if mktemp reuses that code, long enough templates end in a string of '.'s... On Wed, Dec 5, 2018 at 4:08 PM enh wrote: > note that you've already got "random ascii" code in password.c --- i have > a half-finished patch that switches mktemp over to reusing that instead... > > On Wed, Dec 5, 2018 at 3:40 PM Rob Landley wrote: > >> On 12/5/18 5:03 PM, enh via Toybox wrote: >> > Multiple bugs: >> > >> > * We weren't outputting anything in the case where we actually create a >> > file or directory (but all the tests were for the -u case). >> > >> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The >> > new tests cover these. >> >> Sigh. (See attached...) >> >> Lemme try to reconcile them... >> >> Rob >> > ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
note that you've already got "random ascii" code in password.c --- i have a half-finished patch that switches mktemp over to reusing that instead... On Wed, Dec 5, 2018 at 3:40 PM Rob Landley wrote: > On 12/5/18 5:03 PM, enh via Toybox wrote: > > Multiple bugs: > > > > * We weren't outputting anything in the case where we actually create a > > file or directory (but all the tests were for the -u case). > > > > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The > > new tests cover these. > > Sigh. (See attached...) > > Lemme try to reconcile them... > > Rob > ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.
On 12/5/18 5:03 PM, enh via Toybox wrote: > Multiple bugs: > > * We weren't outputting anything in the case where we actually create a > file or directory (but all the tests were for the -u case). > > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The > new tests cover these. Sigh. (See attached...) Lemme try to reconcile them... Rob diff --git a/lib/portability.c b/lib/portability.c index a80ca56..5c754d7 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -30,18 +30,20 @@ pid_t xfork(void) } #endif -void xgetrandom(void *buf, unsigned buflen, unsigned flags) +int xgetrandom(void *buf, unsigned buflen, unsigned flags) { int fd; #if CFG_TOYBOX_GETRANDOM - if (buflen == getrandom(buf, buflen, flags)) return; - if (!CFG_TOYBOX_ON_ANDROID || errno!=ENOSYS) perror_exit("getrandom"); + if (buflen == getrandom(buf, buflen, flags&~WARN_ONLY)) return 1; + if (errno!=ENOSYS && !(flags_ONLY)) perror_exit("getrandom"); #endif - - fd = xopen(flags ? "/dev/random" : "/dev/urandom", O_RDONLY); + fd = xopen(flags ? "/dev/random" : "/dev/urandom",O_RDONLY|(flags_ONLY)); + if (fd == -1) return 0; xreadall(fd, buf, buflen); close(fd); + + return 1; } #if defined(__APPLE__) diff --git a/lib/portability.h b/lib/portability.h index 21d0b8a..60d4049 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -266,7 +266,7 @@ extern CODE prioritynames[], facilitynames[]; #if CFG_TOYBOX_GETRANDOM #include #endif -void xgetrandom(void *buf, unsigned len, unsigned flags); +int xgetrandom(void *buf, unsigned len, unsigned flags); // Android's bionic libc doesn't have confstr. #ifdef __BIONIC__ diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c index 112f84c..6d159d6 100644 --- a/toys/lsb/mktemp.c +++ b/toys/lsb/mktemp.c @@ -34,12 +34,9 @@ GLOBALS( void mktemp_main(void) { char *template = *toys.optargs; - int use_dir = (toys.optflags & (FLAG_p|FLAG_t)); + int use_dir = (toys.optflags & (FLAG_p|FLAG_t)), len; - if (!template) { -template = "tmp.XX"; -use_dir = 1; - } + if (!template) template = "tmp.XX"; // Normally, the precedence is DIR (if set), $TMPDIR (if set), /tmp. // With -t it's $TMPDIR, DIR, /tmp. @@ -48,17 +45,38 @@ void mktemp_main(void) if (toys.optflags & FLAG_t) { if (tmpdir && *tmpdir) TT.p = tmpdir; -} else { - if (!TT.p || !*TT.p) TT.p = tmpdir; -} +} else if (!TT.p || !*TT.p) TT.p = tmpdir; if (!TT.p || !*TT.p) TT.p = "/tmp"; } // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx... template = use_dir ? xmprintf("%s/%s", TT.p, template) : xstrdup(template); + len = strlen(template); + if (len<3 || strcmp(template+len-3, "XXX")) perror_exit("need XXX"); + // In theory you just xputs(mktemp(template)) for -u, in practice there's + // link-time deprecation warnings if you do that. So we fake up our own: if (toys.optflags & FLAG_u) { -xputs(mktemp(template)); +long long rr; +char *s = template+len; + +// Fall back to random-ish if xgetrandom fails. +if (!xgetrandom(, sizeof(rr), WARN_ONLY)) { + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, ); + rr = ts.tv_nsec*65537+(long)template+getpid()+(long) +} +// Replace X with 64 chars from posix portable character set (all but "_"). +while (--s>template) { + if (*s != 'X') break; + *s = '-'+(rr&63); + if (*s>'.') ++*s; + if (*s>'9') (*s) += 7; + if (*s>'Z') (*s) += 6; + rr>>=6; +} +xputs(template); } else if (toys.optflags & FLAG_d ? !mkdtemp(template) : mkstemp(template) == -1) { if (toys.optflags & FLAG_q) toys.exitval = 1; else perror_exit("Failed to create %s %s/%s", ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net