From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f44.google.com (mail-pl0-f44.google.com [209.85.160.44]) by dpdk.org (Postfix) with ESMTP id 74A94271 for ; Tue, 19 Dec 2017 00:59:50 +0100 (CET) Received: by mail-pl0-f44.google.com with SMTP id b96so5838040pli.2 for ; Mon, 18 Dec 2017 15:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9VFSlMOiU4tpJ5t+UIkrFKfbBjJMyQJ+7rAabdi2L10=; b=UvqPss5vZVIpYeRHGR5vNCr0aJMAuY3/j7PrSbfIgct8kwpskd0pfktyWHlth/Zc9h Yn+Gr+SX88YQIYHCZ0kBmbSP0IJgOW/K6JEzhYfRsUu7opG70YrvYJ9zeyc6Yxus9AHw NGOsbC30sRN7lbpiznENLoKPAA9bicHEeNGznQl+N8qsxMAoV5MLJAwZe2Bqkw674HRP lfgrXdrxH03f9e1l9bELuoRGL6oqgWEfuWByslUJWl5C7d8yVtNrdMdS7yRtVTgFFcpB zWjeKGoktadBmr8E8x/UiHYWz97HIxem2oDBk3Ly8t7wdXkMXai4lPLWnsblvYVqvPpQ pcIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9VFSlMOiU4tpJ5t+UIkrFKfbBjJMyQJ+7rAabdi2L10=; b=mgYHTwFRd14GQI/siXgJCvBz0C2ULFW1YMIvMs3CKVl/EVUdV2sC4w+AYYEh6hbJkp iip6SauVGo2futXX29JrF9YhfXI94PD8NmO+d038C5U8IZHNvs/KRjX5yshAdT4BVNbw vAw9zLJJQlkRELYi7QMxuMKY96hbP9yxLzsnP1zoPUAyRe52NJreI3PgFJDyV4humzYu S14y7z0DtLecKKpAGqIy/WwEzgSYPGW0PBq5LviusVj1q0CVK49n8cTBKpCao5I21eta VAaCsUYVQS/UEOscRXBnV3B9uVXDS9uNETRviOkhutDw+6p5y8NYZW1WTzXc5rUwMPbq q14Q== X-Gm-Message-State: AKGB3mJ6pSg0Gl3wucx+rdt3iPK64RUjnJEyVWt9UguDE9b6Bk2qz8yP PsL06R99k3qh0fLF0ItvVwg7XKI8BBQ= X-Google-Smtp-Source: ACJfBouMdy13RnkNgeWnGc5vnfAQd3WCgGHgvR4fzs7zfzEYNxcGcSgUFiQyWC+qL5UXUyrTrSNlBw== X-Received: by 10.84.143.129 with SMTP id 1mr1375459plz.126.1513641589569; Mon, 18 Dec 2017 15:59:49 -0800 (PST) Received: from xeon-e3 (204-195-18-133.wavecable.com. [204.195.18.133]) by smtp.gmail.com with ESMTPSA id b10sm26005474pfj.20.2017.12.18.15.59.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Dec 2017 15:59:49 -0800 (PST) Date: Mon, 18 Dec 2017 15:59:46 -0800 From: Stephen Hemminger To: Adrien Mazarguil Cc: Ferruh Yigit , dev@dpdk.org Message-ID: <20171218155946.5806589a@xeon-e3> In-Reply-To: <20171218162443.12971-3-adrien.mazarguil@6wind.com> References: <20171124172132.GW4062@6wind.com> <20171218162443.12971-1-adrien.mazarguil@6wind.com> <20171218162443.12971-3-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v1 2/3] net/hyperv: implement core functionality X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Dec 2017 23:59:50 -0000 On Mon, 18 Dec 2017 17:46:23 +0100 Adrien Mazarguil wrote: > +static int > +ether_addr_from_str(struct ether_addr *eth_addr, const char *str) > +{ > + static const uint8_t conv[0x100] = { > + ['0'] = 0x80, ['1'] = 0x81, ['2'] = 0x82, ['3'] = 0x83, > + ['4'] = 0x84, ['5'] = 0x85, ['6'] = 0x86, ['7'] = 0x87, > + ['8'] = 0x88, ['9'] = 0x89, ['a'] = 0x8a, ['b'] = 0x8b, > + ['c'] = 0x8c, ['d'] = 0x8d, ['e'] = 0x8e, ['f'] = 0x8f, > + ['A'] = 0x8a, ['B'] = 0x8b, ['C'] = 0x8c, ['D'] = 0x8d, > + ['E'] = 0x8e, ['F'] = 0x8f, [':'] = 0x40, ['-'] = 0x40, > + ['\0'] = 0x60, > + }; > + uint64_t addr = 0; > + uint64_t buf = 0; > + unsigned int i = 0; > + unsigned int n = 0; > + uint8_t tmp; > + > + do { > + tmp = conv[(int)*(str++)]; Cast to int will cause out of bounds reference on non-ascii strings. The parser will get confused by: 001:aa:bb:cc:dd:ee:ff or invalid strings. Why not use sscanf which would be safer in this case. /** * Parse 48bits Ethernet address in pattern xx:xx:xx:xx:xx:xx. * * @param eth_addr * A pointer to a ether_addr structure. * @param str * A pointer to string contains the formatted MAC address. * @return * 0 if the address is valid * -EINVAL if address is not formatted properly */ static inline int ether_parse_addr(struct ether_addr *eth_addr, const char *str) { int n; n = sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", ð_addr->addr_bytes[0], ð_addr->addr_bytes[1], ð_addr->addr_bytes[2], ð_addr->addr_bytes[3], ð_addr->addr_bytes[4], ð_addr->addr_bytes[5]); return (n == ETHER_ADDR_LEN) ? 0 : -EINVAL; } > + if (!tmp) > + return -EINVAL; > + if (tmp & 0x40) { > + i += (i & 1) + (!i << 1); > + addr = (addr << (i << 2)) | buf; > + n += i; > + buf = 0; > + i = 0; > + } else { > + buf = (buf << 4) | (tmp & 0xf); > + ++i; > + } > + } while (!(tmp & 0x20)); > + if (n > 12) > + return -EINVAL; > + i = RTE_DIM(eth_addr->addr_bytes); > + while (i) { > + eth_addr->addr_bytes[--i] = addr & 0xff; > + addr >>= 8; > + } > + return 0; > +} > +