NetBSD Problem Report #47929

From www@NetBSD.org  Fri Jun 14 20:17:28 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 80F43709EC
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 14 Jun 2013 20:17:28 +0000 (UTC)
Message-Id: <20130614201727.120A2709F8@mollari.NetBSD.org>
Date: Fri, 14 Jun 2013 20:17:27 +0000 (UTC)
From: mpiszczek@ddn.com
Reply-To: mpiszczek@ddn.com
To: gnats-bugs@NetBSD.org
Subject: macro CIRCLEQ_REPLACE in queue.h is incorrect
X-Send-Pr-Version: www-1.0

>Number:         47929
>Category:       misc
>Synopsis:       macro CIRCLEQ_REPLACE in queue.h is incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 14 20:20:00 +0000 2013
>Closed-Date:    Fri Sep 30 08:09:06 +0000 2016
>Last-Modified:  Fri Sep 30 08:09:06 +0000 2016
>Originator:     Michael Piszczek
>Release:        
>Organization:
Datadirect Networks
>Environment:
>Description:
I believe the macro CIRCLEQ_REPLACE in queue.h is incorrect.
The macro should be using a pointer to head. Otherwise CIRCLEQ_END(head) will not be correct.
Please see the diff below.

--- a/src/sys/sys/queue.h
+++ b/src/sys/sys/queue.h
@@ -560,12 +560,12 @@ struct {                                         \
 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                  \
        if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==        \
            CIRCLEQ_END(head))                                         \
-               (head).cqh_last = (elm2);                              \
+               (head)->cqh_last = (elm2);                             \
        else                                                           \
                (elm2)->field.cqe_next->field.cqe_prev = (elm2);       \
        if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==        \
            CIRCLEQ_END(head))                                         \
-               (head).cqh_first = (elm2);                             \
+               (head)->cqh_first = (elm2);                            \
        else                                                           \
                (elm2)->field.cqe_prev->field.cqe_next = (elm2);       \
        _Q_INVALIDATE((elm)->field.cqe_prev);             
>How-To-Repeat:

>Fix:
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do {			\
	if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==		\
	    CIRCLEQ_END(head))						\
		(head)->cqh_last = (elm2);				\
	else								\
		(elm2)->field.cqe_next->field.cqe_prev = (elm2);	\
	if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==		\
	    CIRCLEQ_END(head))						\
		(head)->cqh_first = (elm2);				\
	else								\
		(elm2)->field.cqe_prev->field.cqe_next = (elm2);	\
	_Q_INVALIDATE((elm)->field.cqe_prev);				\
	_Q_INVALIDATE((elm)->field.cqe_next);				\
} while (0)

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 27 Jul 2014 03:52:57 +0000
State-Changed-Why:
What version of queue.h (and from where) are you looking at? This code
is not in the queue.h shipped with any of the currently supported
NetBSD releases.

(also, CIRCLEQs are deprecated)


State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Fri, 30 Sep 2016 08:09:06 +0000
State-Changed-Why:
No response from submitter and report was about some random version of
sys/queue.h that wasn't netbsd's.


>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-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.