Hi Richard,

Thanks for the patch. Can you clarify if this change fixes `-d "\0"`,
`-d ""` or `-d""`?

Looking at POSIX, I see that `-d '\0'` must be supported, `-d ""` is
unspecified, and `-d""` is invalid, since paste(1) must follow the
utility syntax guidelines (guideline 7).

I recently investigated a similar issue to this in tr(1). I think a
proper solution would be to add length parameters to utflen and
utftorunestr so that they can handle 0-bytes in the strings.

On 2020-03-02, Richard Ipsum <richardip...@vx21.xyz> wrote:
> ---
>  paste.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/paste.c b/paste.c
> index b0ac761..0159fe0 100644
> --- a/paste.c
> +++ b/paste.c
> @@ -53,7 +53,8 @@ nextline:
>
>               for (; efgetrune(&c, dsc[i].fp, dsc[i].name) ;) {
>                       for (m = last + 1; m < i; m++)
> -                             efputrune(&(delim[m % delimlen]), stdout, 
> "<stdout>");
> +                             if (delim[m % delimlen] != '\0')
> +                                     efputrune(&(delim[m % delimlen]), 
> stdout, "<stdout>");
>                       last = i;
>                       if (c == '\n') {
>                               if (i != fdescrlen - 1)
> @@ -68,7 +69,8 @@ nextline:
>                       if (i == fdescrlen - 1)
>                               putchar('\n');
>                       else
> -                             efputrune(&d, stdout, "<stdout>");
> +                             if (d != '\0')
> +                                     efputrune(&d, stdout, "<stdout>");
>                       last++;
>               }
>       }
> @@ -96,7 +98,7 @@ main(int argc, char *argv[])
>               seq = 1;
>               break;
>       case 'd':
> -             adelim = EARGF(usage());
> +             adelim = ARGF();

I think allowing missing option-argument here breaks POSIX compatibility.

>               unescape(adelim);
>               break;
>       default:
> @@ -109,8 +111,12 @@ main(int argc, char *argv[])
>       /* populate delimiters */
>       /* TODO: fix libutf to accept sizes */
>       delim = ereallocarray(NULL, utflen(adelim) + 1, sizeof(*delim));
> -     if (!(delimlen = utftorunestr(adelim, delim)))
> +     if (*adelim == '\0') {
> +             delimlen = 1;
> +             *delim = '\0';
> +     } else if (!(delimlen = utftorunestr(adelim, delim))) {
>               usage();
> +     }
>
>       /* populate file list */
>       dsc = ereallocarray(NULL, argc, sizeof(*dsc));
> --
> 2.25.1

Reply via email to