Return-path: Received: from mail-qy0-f174.google.com ([209.85.216.174]:52218 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754957Ab1JKSAC (ORCPT ); Tue, 11 Oct 2011 14:00:02 -0400 Received: by qyk30 with SMTP id 30so3793673qyk.19 for ; Tue, 11 Oct 2011 11:00:01 -0700 (PDT) From: "Luis R. Rodriguez" To: linville@tuxdriver.com, johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH 3/4] crda: fix null string assumption for alpha2 Date: Tue, 11 Oct 2011 10:59:00 -0700 Message-Id: <1318355944-24708-4-git-send-email-mcgrof@qca.qualcomm.com> (sfid-20111011_200006_711188_DFF9F8FC) In-Reply-To: <1318355944-24708-1-git-send-email-mcgrof@qca.qualcomm.com> References: <1318355944-24708-1-git-send-email-mcgrof@qca.qualcomm.com> Sender: linux-wireless-owner@vger.kernel.org List-ID: The wireless-regdb only accounts for two bytes for the country code but CRDA defined the alpha2 to be as a string of length 2, and so does the nl80211 attribute policy: [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, The meaning of a string is it'll be null terminated, so if you do not add the null termination a country without the null termination will not match up with the nl80211 attribute policy. This has no impact for us unless we want to use the next available pad byte on the wireless-regdb. This fixes CRDA by using a local copy of the regdb's alpha2 that is properly null terminated and sending it. The implications of this change is that new wirelesss-regdb's that make use of the next pad byte for a country will get that country ignored for regulatory hints sent to the kernel. At this point we don't yet know what the next byte will be used for though so this has no impact. The second pad byte is being used for DFS and that is not impacted by this nor is this change required for it. Distributions should upgrade though in case we ever do decide to use this last precious country byte. I've tested that this indeed fixes the bogus issue I saw when instead of using the second pad byte we use the first pad byte. Thanks to Johannes for spotting the issue. Signed-off-by: Johannes Berg Signed-off-by: Luis R. Rodriguez --- crda.c | 4 ++-- reglib.h | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/crda.c b/crda.c index 6857e3f..fcb0c11 100644 --- a/crda.c +++ b/crda.c @@ -149,7 +149,7 @@ int main(int argc, char **argv) struct regdb_file_header *header; struct regdb_file_reg_country *countries; int dblen, siglen, num_countries, i, j, r; - char alpha2[2]; + char alpha2[3] = {}; /* NUL-terminate */ char *env_country; struct nl80211_state nlstate; struct nl_cb *cb = NULL; @@ -279,7 +279,7 @@ int main(int argc, char **argv) sizeof(*rcoll) + num_rules * sizeof(__be32), country->reg_collection_ptr); - NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, (char *) country->alpha2); + NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); if (!nl_reg_rules) { diff --git a/reglib.h b/reglib.h index f3a76ef..9fe5d8b 100644 --- a/reglib.h +++ b/reglib.h @@ -53,21 +53,8 @@ static inline int is_alpha2(const char *alpha2) return 0; } -/* Avoid stdlib */ -static inline int is_len_2(const char *alpha2) -{ - if (alpha2[0] == '\0' || (alpha2[1] == '\0')) - return 0; - if (alpha2[2] == '\0') - return 1; - return 0; -} - static inline int is_valid_regdom(const char *alpha2) { - if (!is_len_2(alpha2)) - return 0; - if (!is_alpha2(alpha2) && !is_world_regdom(alpha2)) return 0; -- 1.7.4.15.g7811d