From patchwork Thu Mar 27 18:17:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899211 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1EB23BF540 for ; Thu, 27 Mar 2014 18:18:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4560520253 for ; Thu, 27 Mar 2014 18:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C08420225 for ; Thu, 27 Mar 2014 18:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757077AbaC0SSx (ORCPT ); Thu, 27 Mar 2014 14:18:53 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:52685 "EHLO mail-ee0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756966AbaC0SSw (ORCPT ); Thu, 27 Mar 2014 14:18:52 -0400 Received: by mail-ee0-f45.google.com with SMTP id d17so3246535eek.32 for ; Thu, 27 Mar 2014 11:18:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=mOB5iT99OWTQFIi/koGm/DnqcwlC1/YBAP75+fPpjyk=; b=JrGSabic/bHPuDPDEDNiyn5q/iLlgNVWG8pim0Pp0zLOxW4dzfGRxVZ+J5+ZX8xzkW IjCrUtO1tyz/+SzWcSyG/XJzHWw9RptoKa6HuPYJ34GJxkvQ7/qLFpQYjCOXXEz1cy5o rLeaJ4QLxAstsjocDTbolct2YFGV+Qh+C4XlZrkcw1u/6KBhvlDyzeRQcU7yC51vmF7F Kl21Hc1OZ9Pl+ND3dDUVZWxd/ONM9NDtamulQvP9chKLW+KpNDl2DFUzJe+zl//8vsAj QCVsbGvzUYGp8sSfpesplN9dua0fzkZqQyeMH0cXMMC7nZGGXK81FlTSdOsIbEI+i95g ZK1A== X-Gm-Message-State: ALoCoQlNaT7zh82eE3BYmll1hP+kaU7Zmxsyiz8CCVNWV28JGOGQJ/Obo89d9xpYrvv3Is1xBKb2 X-Received: by 10.15.44.3 with SMTP id y3mr2239010eev.58.1395944331277; Thu, 27 Mar 2014 11:18:51 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id 48sm5992191eee.2.2014.03.27.11.18.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:18:50 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 12/33] libceph: fix and clarify ceph_decode_need() sizes Date: Thu, 27 Mar 2014 20:17:58 +0200 Message-Id: <1395944299-21970-13-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> References: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sum up sizeof(...) results instead of (incorrectly) hard-coding the number of bytes, expressed in ints and longs. Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 75e192e99173..6dd083906a1e 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -706,7 +706,9 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) goto e_inval; } - ceph_decode_need(p, end, 2*sizeof(u64)+6*sizeof(u32), e_inval); + /* fsid, epoch, created, modified */ + ceph_decode_need(p, end, sizeof(map->fsid) + sizeof(u32) + + sizeof(map->created) + sizeof(map->modified), e_inval); ceph_decode_copy(p, &map->fsid, sizeof(map->fsid)); epoch = map->epoch = ceph_decode_32(p); ceph_decode_copy(p, &map->created, sizeof(map->created)); @@ -872,8 +874,9 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, goto e_inval; } - ceph_decode_need(p, end, sizeof(fsid)+sizeof(modified)+2*sizeof(u32), - e_inval); + /* fsid, epoch, modified, new_pool_max, new_flags */ + ceph_decode_need(p, end, sizeof(fsid) + sizeof(u32) + sizeof(modified) + + sizeof(u64) + sizeof(u32), e_inval); ceph_decode_copy(p, &fsid, sizeof(fsid)); epoch = ceph_decode_32(p); BUG_ON(epoch != map->epoch+1); @@ -907,10 +910,8 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, if (new_pool_max >= 0) map->pool_max = new_pool_max; - ceph_decode_need(p, end, 5*sizeof(u32), e_inval); - /* new max? */ - max = ceph_decode_32(p); + ceph_decode_32_safe(p, end, max, e_inval); if (max >= 0) { err = osdmap_set_max_osd(map, max); if (err)