From dffc24ecb5d0cc1d89f1ad0d6baa88bc201f926b Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 22 Dec 2023 17:12:13 +0000 Subject: [PATCH] xargs: fix parsing of empty fields when "xargs -0" is used. Previously, these fields would be skipped. From Hiltjo Posthuma. --- regress/usr.bin/xargs/xargs-L.sh | 10 +++++++++- usr.bin/xargs/xargs.c | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/regress/usr.bin/xargs/xargs-L.sh b/regress/usr.bin/xargs/xargs-L.sh index 50477de3f44..7f4a329705f 100755 --- a/regress/usr.bin/xargs/xargs-L.sh +++ b/regress/usr.bin/xargs/xargs-L.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: xargs-L.sh,v 1.3 2017/10/16 13:48:22 anton Exp $ +# $OpenBSD: xargs-L.sh,v 1.4 2023/12/22 17:12:13 millert Exp $ # # written by Ingo Schwarze 2010 # and placed in the public domain @@ -97,3 +97,11 @@ test_xargs 'a\n\\\nb\0c' '-0 -L 1' 'a\n\\\nb|\nc|' test_xargs 'a \\\nb\0c' '-0 -L 1' 'a \\\nb|\nc|' test_xargs 'a\\\n b\0c' '-0 -L 1' 'a\\\n b|\nc|' test_xargs 'a \\\n b\0c' '-0 -L 1' 'a \\\n b|\nc|' + +test_xargs 'a' '-0 -L 1' 'a|\n' +test_xargs 'a\0' '-0 -L 1' 'a|\n' +test_xargs 'a\0\0' '-0 -L 1' 'a|\n|\n' +test_xargs 'a\0\0b' '-0 -L 2' 'a||\nb|' +test_xargs 'a\0\0b' '-0 -L 1' 'a|\n|\nb|' +test_xargs 'a\0\0b' '-0 -L 3' 'a||b|' +test_xargs 'a\0\0b' '-0 -L 9' 'a||b|' diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index ff17caaf436..70f9d9d9816 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xargs.c,v 1.36 2022/12/04 23:50:50 cheloha Exp $ */ +/* $OpenBSD: xargs.c,v 1.37 2023/12/22 17:12:13 millert Exp $ */ /* $FreeBSD: xargs.c,v 1.51 2003/05/03 19:09:11 obrien Exp $ */ /*- @@ -297,7 +297,7 @@ arg2: strcmp(argp, eofstr) == 0; /* Do not make empty args unless they are quoted */ - if ((argp != p || wasquoted) && !foundeof) { + if ((zflag || argp != p || wasquoted) && !foundeof) { *p++ = '\0'; *xp++ = argp; if (Iflag) { -- 2.20.1