NetBSD Problem Report #52678

From martin@aprisoft.de  Tue Oct 31 07:41:39 2017
Return-Path: <martin@aprisoft.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 0D3F67A1DF
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 31 Oct 2017 07:41:39 +0000 (UTC)
Message-Id: <20171031074129.1E9415CC761@emmas.aprisoft.de>
Date: Tue, 31 Oct 2017 08:41:29 +0100 (CET)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: makemandb crashes
X-Send-Pr-Version: 3.95

>Number:         52678
>Category:       bin
>Synopsis:       makemandb crashes
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    abhinav
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 31 07:45:00 +0000 2017
>Closed-Date:    Tue Oct 31 10:19:27 +0000 2017
>Last-Modified:  Tue Oct 31 10:19:27 +0000 2017
>Originator:     Martin Husemann
>Release:        NetBSD 8.99.5
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD whoever-brings-the-night.aprisoft.de 8.99.5 NetBSD 8.99.5 (WHOEVER) #183: Sat Oct 28 16:48:01 CEST 2017 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/sparc64/compile/WHOEVER sparc64
Architecture: sparc64
Machine: sparc64
>Description:

Running makemandb (like done at system startup) crashes on sparc64 with
a SIGBUS:

Program received signal SIGBUS, Bus error.
0x0000000000134690 in porter_stemmer (pnOut=0xffffffffffffcc8c, 
    zOut=0x42876f60 "x\234+/NJÍ\311\001", nIn=<optimized out>, 
    zIn=<optimized out>)
    at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:625
625     /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c: No such file or directory.
(gdb) bt
#0  0x0000000000134690 in porter_stemmer (pnOut=0xffffffffffffcc8c, 
    zOut=0x42876f60 "x\234+/NJÍ\311\001", nIn=<optimized out>, 
    zIn=<optimized out>)
    at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:625
#1  do_stem (pnOut=0xffffffffffffcc8c, zOut=0x42876f60 "x\234+/NJÍ\311\001", 
    nIn=<optimized out>, zIn=<optimized out>)
    at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:654
#2  aproposPorterNext (pCursor=0x4284af00, pzToken=0xffffffffffffcc90, 
    pnBytes=0xffffffffffffcc8c, piStartOffset=0xffffffffffffcc80, 
    piEndOffset=0xffffffffffffcc84, piPosition=0xffffffffffffcc88)
    at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:719
#3  0x000000004053442c in fts3PendingTermsAdd (p=p@entry=0x4250a408, 
    iLangid=iLangid@entry=0, zText=<optimized out>, iCol=iCol@entry=1, 
    pnWord=pnWord@entry=0x4287c0c4)
    at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:155641
#4  0x00000000405aac54 in fts3InsertTerms (aSz=<optimized out>, 
    apVal=<optimized out>, iLangid=<optimized out>, p=<optimized out>)
    at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:155745
#5  sqlite3Fts3UpdateMethod (pRowid=<optimized out>, apVal=<optimized out>, 
    nArg=<optimized out>, pVtab=0x4250a408)
    at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:29384

the size_t pointer *pnOut is misaligned. It comes from line 719:

 int stemStatus = do_stem(&z[iStartOffset], n, c->zToken, (size_t *) pnBytes);  

and pnBytes only is an int pointer. Either make pnBytes a size_t * as well,
or call with a temporary size_t and assign:

  size_t temp = *pnBytes;
  int stemStatus = do_stem(&z[iStartOffset], n, c->zToken, &temp);  
  *pnBytes = temp;

>How-To-Repeat:

gdb makemandb
run -Q

>Fix:
n/a

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->abhinav
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Tue, 31 Oct 2017 09:17:39 +0000
Responsible-Changed-Why:
Abhinav, could you please have a look?


State-Changed-From-To: open->analyzed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 31 Oct 2017 09:17:39 +0000
State-Changed-Why:
Analyzis provided


From: Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
To: NetBSD GNATS <gnats-bugs@netbsd.org>
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/52678: makemandb crashes
Date: Tue, 31 Oct 2017 09:20:35 +0000

 On Tue, Oct 31, 2017 at 7:45 AM,  <martin@netbsd.org> wrote:
 >>Number:         52678
 >>Category:       bin
 >>Synopsis:       makemandb crashes
 >>Confidential:   no
 >>Severity:       critical
 >>Priority:       high
 >>Responsible:    bin-bug-people
 >>State:          open
 >>Class:          sw-bug
 >>Submitter-Id:   net
 >>Arrival-Date:   Tue Oct 31 07:45:00 +0000 2017
 >>Originator:     Martin Husemann
 >>Release:        NetBSD 8.99.5
 >>Organization:
 > The NetBSD Foundation, Inc.
 >>Environment:
 > System: NetBSD whoever-brings-the-night.aprisoft.de 8.99.5 NetBSD 8.99.5 =
 (WHOEVER) #183: Sat Oct 28 16:48:01 CEST 2017 martin@seven-days-to-the-wolv=
 es.aprisoft.de:/work/src/sys/arch/sparc64/compile/WHOEVER sparc64
 > Architecture: sparc64
 > Machine: sparc64
 >>Description:
 >
 > Running makemandb (like done at system startup) crashes on sparc64 with
 > a SIGBUS:
 >
 > Program received signal SIGBUS, Bus error.
 > 0x0000000000134690 in porter_stemmer (pnOut=3D0xffffffffffffcc8c,
 >     zOut=3D0x42876f60 "x\234+/NJ=C3=8D\311\001", nIn=3D<optimized out>,
 >     zIn=3D<optimized out>)
 >     at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:625
 > 625     /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c: No such =
 file or directory.
 > (gdb) bt
 > #0  0x0000000000134690 in porter_stemmer (pnOut=3D0xffffffffffffcc8c,
 >     zOut=3D0x42876f60 "x\234+/NJ=C3=8D\311\001", nIn=3D<optimized out>,
 >     zIn=3D<optimized out>)
 >     at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:625
 > #1  do_stem (pnOut=3D0xffffffffffffcc8c, zOut=3D0x42876f60 "x\234+/NJ=C3=
 =8D\311\001",
 >     nIn=3D<optimized out>, zIn=3D<optimized out>)
 >     at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:654
 > #2  aproposPorterNext (pCursor=3D0x4284af00, pzToken=3D0xffffffffffffcc90=
 ,
 >     pnBytes=3D0xffffffffffffcc8c, piStartOffset=3D0xffffffffffffcc80,
 >     piEndOffset=3D0xffffffffffffcc84, piPosition=3D0xffffffffffffcc88)
 >     at /work/src/usr.sbin/makemandb/custom_apropos_tokenizer.c:719
 > #3  0x000000004053442c in fts3PendingTermsAdd (p=3Dp@entry=3D0x4250a408,
 >     iLangid=3DiLangid@entry=3D0, zText=3D<optimized out>, iCol=3DiCol@ent=
 ry=3D1,
 >     pnWord=3DpnWord@entry=3D0x4287c0c4)
 >     at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:1556=
 41
 > #4  0x00000000405aac54 in fts3InsertTerms (aSz=3D<optimized out>,
 >     apVal=3D<optimized out>, iLangid=3D<optimized out>, p=3D<optimized ou=
 t>)
 >     at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:1557=
 45
 > #5  sqlite3Fts3UpdateMethod (pRowid=3D<optimized out>, apVal=3D<optimized=
  out>,
 >     nArg=3D<optimized out>, pVtab=3D0x4250a408)
 >     at /work/src/external/public-domain/sqlite/lib/../dist/sqlite3.c:2938=
 4
 >
 > the size_t pointer *pnOut is misaligned. It comes from line 719:
 >
 >  int stemStatus =3D do_stem(&z[iStartOffset], n, c->zToken, (size_t *) pn=
 Bytes);
 >
 > and pnBytes only is an int pointer. Either make pnBytes a size_t * as wel=
 l,

 We cannot change the type of the function argument since it is the
 interface expected by SQLite.

 > or call with a temporary size_t and assign:
 >
 >   size_t temp =3D *pnBytes;
 >   int stemStatus =3D do_stem(&z[iStartOffset], n, c->zToken, &temp);
 >   *pnBytes =3D temp;

 This sounds better. Since you have proposed this fix, I am guessing it
 works on Sparc64. :)
 Should I commit it?


 Regards
 Abhinav

From: "Abhinav Upadhyay" <abhinav@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52678 CVS commit: src/usr.sbin/makemandb
Date: Tue, 31 Oct 2017 10:14:27 +0000

 Module Name:	src
 Committed By:	abhinav
 Date:		Tue Oct 31 10:14:27 UTC 2017

 Modified Files:
 	src/usr.sbin/makemandb: custom_apropos_tokenizer.c

 Log Message:
 Casting variable of type int *  to size_t *, may cause
 alignment issues on some platforms (e.g. Sparc64)
 So, Use a temporary variable to avoid the cast.

 Thanks to Martin@ for noticing the issue and also suggesting the issue.
 Fixes PR bin/52678


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/makemandb/custom_apropos_tokenizer.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: analyzed->closed
State-Changed-By: abhinav@NetBSD.org
State-Changed-When: Tue, 31 Oct 2017 10:19:27 +0000
State-Changed-Why:
Fix applied as suggested in the PR by Martin
(Also verified by him that it works)
Thanks for reporting it
(and sorry about the typo in the commit message :))


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.