Re: [hackers] [sbase] [PATCH] *sum: Ignore -b and -t flags

2020-01-02 Thread Michael Forney
On 2020-01-02, Laslo Hunhold  wrote:
> I would print something on stderr. POSIX is ignored often enough and a
> ton of scripts are using the cancerous GNU extensions and other
> extensions. If we just "ignore" them, there is no learning effect or
> push for change for script writers, so maybe we could add a warning
> while we ignore them, so when you run a script that makes use of these
> mostly useless flags (which we could also tell them), then this might a
> push in a good direction. What do you think?

I'm well aware that POSIX is ignored often. I send patches to projects
every time I run into a script using non-POSIX options that break
compatibility with sbase. But in this case, POSIX is not really
relevant since as I mentioned, these are not POSIX tools, and there
aren't many different implementations (BSDs have their own md5(1),
sha256(1), ...), so coreutils is essentially the standard.

Who are we to decide that -b and -t are not be valid flags for sha*sum
and should not be used? I ran into a script that used `sha256sum -b`,
but how could I justify removing that option to upstream?

The flags may be useless on operating systems that sbase supports, but
the "rb" is a valid mode for C99 fopen ("r" opens as a text file), so
there must be operating systems where it makes a difference. Removing
-b may break the script on those operating systems.



Re: [hackers] [sbase] [PATCH] *sum: Ignore -b and -t flags

2020-01-02 Thread Michael Forney
On 2020-01-02, Quentin Rameau  wrote:
> I agree in that silently ignoring commands from the user is bad, as it
> breaks expectations.

Well, in this case ignoring them is a valid implementation, since on
POSIX there is no distinction between opening a file as text or binary
mode. So it will return the correct result with those flags.

> Though as noted in this case, those are not standardized (maybe that
> wasn't a great idea to add them in sbase instead of ubase even if they
> can be implemented in a portable manner), so anything can happen there.

There is http://austingroupbugs.net/view.php?id=1041 which encourages
implementations to provide *some* method of checksum with high
security, but unfortunately still has no specification of what that
looks like.

> I'm not sure we should start adding those kind of half-compability
> parsing with coreutils, where do we stop?

I disagree that it is "half-compatibility", but this is a good point.
It's kind of a similar issue with tar(1), which was removed from
POSIX, but still extremely widely used. I think the best we can do is
implement the options that are commonly expected of the tools. In this
case implementing -b and -t is as simple as adding a case to a switch,
so I don't see much downside to doing so.

> Also for what it's worth:
>
> $ busybox md5sum -b md5sum.c
> md5sum: unrecognized option: b
> BusyBox v1.31.1 (2019-11-29 10:55:12 UTC) multi-call binary.
>
> Usage: md5sum [FILE]...
>
> $ busybox md5sum -t md5sum.c
> md5sum: unrecognized option: t
> BusyBox v1.31.1 (2019-11-29 10:55:12 UTC) multi-call binary.
>
> Usage: md5sum [FILE]...

Looks like with busybox the -b and -t options depend on
ENABLE_FEATURE_MD5_SHA1_SUM_CHECK, which also enables the -c flag.

$ busybox md5sum -b /dev/null
d41d8cd98f00b204e9800998ecf8427e  /dev/null



Re: [hackers] [sbase] [PATCH] *sum: Ignore -b and -t flags

2020-01-02 Thread Quentin Rameau
Hi Laslo,

> > These tools are not standardized, but these flags are supported in all
> > implementations I'm aware of (coreutils, busybox), and are
> > occasionally used in scripts.
> > 
> > These flags are only meaningful on operating systems which
> > differentiate between text and binary files, so just ignore them.  
> 
> I would print something on stderr. POSIX is ignored often enough and a
> ton of scripts are using the cancerous GNU extensions and other
> extensions. If we just "ignore" them, there is no learning effect or
> push for change for script writers, so maybe we could add a warning
> while we ignore them, so when you run a script that makes use of these
> mostly useless flags (which we could also tell them), then this might a
> push in a good direction. What do you think?

I agree in that silently ignoring commands from the user is bad, as it
breaks expectations.

Though as noted in this case, those are not standardized (maybe that
wasn't a great idea to add them in sbase instead of ubase even if they
can be implemented in a portable manner), so anything can happen there.

I'm not sure we should start adding those kind of half-compability
parsing with coreutils, where do we stop?

Also for what it's worth:

$ busybox md5sum -b md5sum.c
md5sum: unrecognized option: b
BusyBox v1.31.1 (2019-11-29 10:55:12 UTC) multi-call binary.

Usage: md5sum [FILE]...

$ busybox md5sum -t md5sum.c
md5sum: unrecognized option: t
BusyBox v1.31.1 (2019-11-29 10:55:12 UTC) multi-call binary.

Usage: md5sum [FILE]...



Re: [hackers] [sbase] [PATCH] *sum: Ignore -b and -t flags

2020-01-02 Thread Laslo Hunhold
On Wed,  1 Jan 2020 22:04:47 -0800
Michael Forney  wrote:

Dear Michael,

> These tools are not standardized, but these flags are supported in all
> implementations I'm aware of (coreutils, busybox), and are
> occasionally used in scripts.
> 
> These flags are only meaningful on operating systems which
> differentiate between text and binary files, so just ignore them.

I would print something on stderr. POSIX is ignored often enough and a
ton of scripts are using the cancerous GNU extensions and other
extensions. If we just "ignore" them, there is no learning effect or
push for change for script writers, so maybe we could add a warning
while we ignore them, so when you run a script that makes use of these
mostly useless flags (which we could also tell them), then this might a
push in a good direction. What do you think?

With best regards

Laslo



[hackers] [sbase] [PATCH] *sum: Ignore -b and -t flags

2020-01-01 Thread Michael Forney
These tools are not standardized, but these flags are supported in all
implementations I'm aware of (coreutils, busybox), and are occasionally
used in scripts.

These flags are only meaningful on operating systems which differentiate
between text and binary files, so just ignore them.
---
 md5sum.c| 4 
 sha1sum.c   | 4 
 sha224sum.c | 4 
 sha256sum.c | 4 
 sha384sum.c | 4 
 sha512-224sum.c | 4 
 sha512-256sum.c | 4 
 sha512sum.c | 4 
 8 files changed, 32 insertions(+)

diff --git a/md5sum.c b/md5sum.c
index 86fb40f..224b20e 100644
--- a/md5sum.c
+++ b/md5sum.c
@@ -28,6 +28,10 @@ main(int argc, char *argv[])
uint8_t md[MD5_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha1sum.c b/sha1sum.c
index 4f3ae77..cc8dcae 100644
--- a/sha1sum.c
+++ b/sha1sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA1_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha224sum.c b/sha224sum.c
index 5c4a6cb..e9a10cf 100644
--- a/sha224sum.c
+++ b/sha224sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA224_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha256sum.c b/sha256sum.c
index d863539..686c70f 100644
--- a/sha256sum.c
+++ b/sha256sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA256_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha384sum.c b/sha384sum.c
index f975b61..c76947e 100644
--- a/sha384sum.c
+++ b/sha384sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA384_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha512-224sum.c b/sha512-224sum.c
index 6e4a9d6..53f2e62 100644
--- a/sha512-224sum.c
+++ b/sha512-224sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA512_224_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha512-256sum.c b/sha512-256sum.c
index c2d582e..ea556b8 100644
--- a/sha512-256sum.c
+++ b/sha512-256sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA512_256_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
diff --git a/sha512sum.c b/sha512sum.c
index 65a0c2c..a76e685 100644
--- a/sha512sum.c
+++ b/sha512sum.c
@@ -27,6 +27,10 @@ main(int argc, char *argv[])
uint8_t md[SHA512_DIGEST_LENGTH];
 
ARGBEGIN {
+   case 'b':
+   case 't':
+   /* ignore */
+   break;
case 'c':
cryptfunc = cryptcheck;
break;
-- 
2.24.1