Re: Bug in OpenBSD 6.3 /usr/bin/wc

2018-09-29 Thread Scott Cheloha
On Thu, Sep 27, 2018 at 05:09:22PM -0500, Scott Cheloha wrote:
> > On Sep 27, 2018, at 10:26, Todd C. Miller  wrote:
> > 
> >> On Thu, 27 Sep 2018 16:19:46 +0100, Dave Hines wrote:
> >> 
> >> Oops - my patch contained a bug (though it worked on my machine).
> >> Here is a corrected patch for /usr/src/usr.bin/wc/wc.c
> > 
> > That fix looks correct to me.
> 
> Ditto, works here. I will commit tonight if someone else doesn't
> chime in.
> 
> (ok cheloha@ if someone else commits first)

Committed, thanks!



Re: Bug in OpenBSD 6.3 /usr/bin/wc

2018-09-27 Thread Scott Cheloha
> On Sep 27, 2018, at 10:26, Todd C. Miller  wrote:
> 
>> On Thu, 27 Sep 2018 16:19:46 +0100, Dave Hines wrote:
>> 
>> Oops - my patch contained a bug (though it worked on my machine).
>> Here is a corrected patch for /usr/src/usr.bin/wc/wc.c
> 
> That fix looks correct to me.

Ditto, works here. I will commit tonight if someone else doesn't
chime in.

(ok cheloha@ if someone else commits first)



Re: Bug in OpenBSD 6.3 /usr/bin/wc

2018-09-27 Thread Todd C. Miller
On Thu, 27 Sep 2018 16:19:46 +0100, Dave Hines wrote:

> Oops - my patch contained a bug (though it worked on my machine).
> Here is a corrected patch for /usr/src/usr.bin/wc/wc.c

That fix looks correct to me.

 - todd



Re: Bug in OpenBSD 6.3 /usr/bin/wc

2018-09-27 Thread Dave Hines
Oops - my patch contained a bug (though it worked on my machine).
Here is a corrected patch for /usr/src/usr.bin/wc/wc.c

diff -r a60ac28f79ee wc.c
--- a/wc.c  Wed Sep 26 17:49:53 2018 +0100
+++ b/wc.c  Thu Sep 27 16:16:02 2018 +0100
@@ -208,7 +208,8 @@
gotsp = 1;
while ((len = getline(, , stream)) > 0) {
if (multibyte) {
-   for (C = buf; *C != '\0'; C += len) {
+   const char *end = buf + len;
+   for (C = buf; C < end; C += len) {
++charct;
len = mbtowc(, C, MB_CUR_MAX);
if (len == -1) {
@@ -228,7 +229,7 @@
}
} else {
charct += len;
-   for (C = buf; *C != '\0'; ++C) {
+   for (C = buf; len--; ++C) {
if (isspace((unsigned char)*C)) {
gotsp = 1;
if (*C == '\n')



Bug in OpenBSD 6.3 /usr/bin/wc

2018-09-26 Thread openbsd
>Synopsis: /usr/bin/wc incorrect line counts for files containing nil
>Category: bug in /usr/bin/wc
>Environment:
System  : OpenBSD 6.3
Details : OpenBSD 6.3 (GENERIC.MP) #11: Thu Sep 20 16:05:37 CEST 
2018
 
r...@syspatch-63-amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

Architecture: OpenBSD.amd64
Machine : amd64
>Description:
The line count produced by "wc file" when file contains lines
with embedded nil ('\0') characters is incorrect, and differes
from the count produced by "wc -l file"

>How-To-Repeat:
echo 'hello world0' | tr '0' '\0' >file# Create file containing '\0'
wc file # Note wc reports no lines in file: 0   2  
13 file
wc -l file  # while wc -l file reports 1 line:  1 file

>Fix:
# Suggested patch for /usr/src/usr.bin/wc/wc.c
diff -r a60ac28f79ee wc.c
--- a/wc.c  Wed Sep 26 17:49:53 2018 +0100
+++ b/wc.c  Wed Sep 26 18:09:51 2018 +0100
@@ -208,7 +208,8 @@
gotsp = 1;
while ((len = getline(, , stream)) > 0) {
if (multibyte) {
-   for (C = buf; *C != '\0'; C += len) {
+   char *end = C + len;
+   for (C = buf; C < end; C += len) {
++charct;
len = mbtowc(, C, MB_CUR_MAX);
if (len == -1) {
@@ -228,7 +229,7 @@
}
} else {
charct += len;
-   for (C = buf; *C != '\0'; ++C) {
+   for (C = buf; len--; ++C) {
if (isspace((unsigned char)*C)) {
gotsp = 1;
if (*C == '\n')


dmesg:
OpenBSD 6.3 (GENERIC.MP) #11: Thu Sep 20 16:05:37 CEST 2018

r...@syspatch-63-amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8448847872 (8057MB)
avail mem = 8185704448 (7806MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.6 @ 0xf2340 (70 entries)
bios0: vendor Dell Inc. version "A06" date 07/25/2011
bios0: Dell Inc. OptiPlex 790
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC TCPA SSDT MCFG HPET BOOT SSDT SSDT
acpi0: wakeup devices EHC1(S3) EHC2(S3) HDEF(S4) GLAN(S4) PXSX(S4) RP01(S4) 
PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4) PXSX(S4) RP05(S4) 
PXSX(S4) RP06(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz, 3093.40 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,DEADLINE,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
acpitimer0: recalibrated TSC frequency 3092995880 Hz
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz, 3092.98 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,DEADLINE,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpihpet0 at acpi0: 14318179 Hz
acpihpet0: recalibrated TSC frequency 3092963190 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 1 (RP01)
acpiprt2 at acpi0: bus -1 (RP02)
acpiprt3 at acpi0: bus 2 (RP03)
acpiprt4 at acpi0: bus -1 (RP04)
acpiprt5 at acpi0: bus -1 (RP05)
acpiprt6 at acpi0: bus -1 (RP06)
acpiprt7 at acpi0: bus -1 (RP07)
acpiprt8 at acpi0: bus -1 (RP08)
acpiprt9 at acpi0: bus -1 (PEG0)
acpiprt10 at acpi0: bus -1 (PEG1)
acpiprt11 at acpi0: bus -1 (PEG2)
acpiprt12 at acpi0: bus -1 (PEG3)
acpiprt13 at acpi0: bus 3 (P0P1)
acpicpu0 at acpi0: C3(350@104 mwait.1@0x20), C2(500@80 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
acpicpu1 at acpi0: C3(350@104 mwait.1@0x20), C2(500@80 mwait.1@0x10), C1(1000@1 
mwait.1), PSS
"INT3F0D" at acpi0 not configured
"PNP0A05" at acpi0 not configured
acpibtn0 at acpi0: PWRB
acpivideo0 at acpi0: GFX0
acpivout0 at acpivideo0: DD02
cpu0: Enhanced