From patchwork Wed Nov 9 20:09:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13038015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E7ECC433FE for ; Wed, 9 Nov 2022 20:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiKIUJx (ORCPT ); Wed, 9 Nov 2022 15:09:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiKIUJw (ORCPT ); Wed, 9 Nov 2022 15:09:52 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10710DEBB for ; Wed, 9 Nov 2022 12:09:48 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id f27so49921341eje.1 for ; Wed, 09 Nov 2022 12:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Ry5PNnAbiJxq8NNqb+nL9MTL5scPcOFNyhWrJ0VFPOw=; b=pDhH5TfgbHZG0iD1m5P5cSCQibrZv1xwBY6v6Wf6iHV3nQyP++66ci5x/+TXlbLca2 LcTsOrmuNB1CCjX12HmEz+COeww/5xHglrl9+8rrs/CLLKI6sjo+mX+2aJJg7gSgqKe4 jbLIQUy8eFo0ln70F+D6LfH4aJla9Vp82O+8VaB72AbpEfE1OncWhpUL29PCQ60FT0Nu qa84xbHf5wn6kKqz6vfpmmH4BjWQHhl6q+u9NCTmlZR7mS2j1MwuOrveciu4LvRBaoOn j4A7/tfsojAwJmE4eEaqc2FyvTS2EzTuoukiIcmWIL4YLnTgae+kcb5PjZrBAdxGyng6 MI8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ry5PNnAbiJxq8NNqb+nL9MTL5scPcOFNyhWrJ0VFPOw=; b=fognajI/taPQVQxgspPJsG45B8TbeSFAzJj6sNMYJyol0g+Sk2yCp8dC3oFIlfXDxg YLybKr/G8QQUDsyBcw9svtUtKDIzZVanq7nWgjWC1KzYLxpQNa4F9ExEgh5pAF/VyHqs 3Js/QQWRkSRU8fkqF8mGdT5PsCemEahLfrDzYNMKcV0V3YaitUBk88cxRyjFxoaYiCTo mQXFJVyvyIMZ9DKnb79O/WEy2ZvqttOSbBhdZgNsKqmJmuCr3mx6S5t/SdHMND0PABaE FRDxGj/ksSRxm7dRWc6tamood32LLnOHKTbZA/wVkTxTnt+hShrysqS2p3nYmBttBJtb WrJQ== X-Gm-Message-State: ACrzQf0NlhR17BAGS12qRmMEa3VDsD7YztleuP8uY5rz41oXfrugOkLg 3J3hOp7AFWxXvETpLODyEQa8R1d0X2A= X-Google-Smtp-Source: AMsMyM4sQEzyShilt9x/6p/BKYuH9bmFLBxPHgVwJQN2k1tRa0Bkgo4ZXPcx3ALIZM8lFaB1uI6o6A== X-Received: by 2002:a17:906:846b:b0:7ad:88f8:469a with SMTP id hx11-20020a170906846b00b007ad88f8469amr57900821ejc.519.1668024586550; Wed, 09 Nov 2022 12:09:46 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-010-185-019.77.10.pool.telefonica.de. [77.10.185.19]) by smtp.gmail.com with ESMTPSA id l2-20020a1709063d2200b007adbd01c566sm6386115ejf.146.2022.11.09.12.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:09:46 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 1/3] libselinux: simplify string copying Date: Wed, 9 Nov 2022 21:09:37 +0100 Message-Id: <20221109200939.62525-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Use strdup(3)/strndup(3) instead of allocating memory and then manually copying the content. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libselinux/src/context.c | 11 +++++------ libselinux/src/get_default_type.c | 3 +-- libselinux/src/matchpathcon.c | 9 +++------ libselinux/utils/selabel_lookup_best_match.c | 10 ++++------ 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/libselinux/src/context.c b/libselinux/src/context.c index 9dddbc5a..8830bf42 100644 --- a/libselinux/src/context.c +++ b/libselinux/src/context.c @@ -149,19 +149,18 @@ static int set_comp(context_private_t * n, int idx, const char *str) char *t = NULL; const char *p; if (str) { - t = (char *)malloc(strlen(str) + 1); - if (!t) { - return -1; - } for (p = str; *p; p++) { if (*p == '\t' || *p == '\n' || *p == '\r' || ((*p == ':' || *p == ' ') && idx != COMP_RANGE)) { - free(t); errno = EINVAL; return -1; } } - strcpy(t, str); + + t = strdup(str); + if (!t) { + return -1; + } } conditional_free(&n->component[idx]); n->component[idx] = t; diff --git a/libselinux/src/get_default_type.c b/libselinux/src/get_default_type.c index dd7b5d79..766ea4b7 100644 --- a/libselinux/src/get_default_type.c +++ b/libselinux/src/get_default_type.c @@ -62,10 +62,9 @@ static int find_default_type(FILE * fp, const char *role, char **type) return -1; } - t = malloc(strlen(buf) - len); + t = strndup(ptr, strlen(buf) - len - 1); if (!t) return -1; - strcpy(t, ptr); *type = t; return 0; } diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c index ea78a23e..bf2da083 100644 --- a/libselinux/src/matchpathcon.c +++ b/libselinux/src/matchpathcon.c @@ -215,10 +215,9 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file) if (ret < 0 || sb.st_ino != ino) { fl->specind = specind; free(fl->file); - fl->file = malloc(strlen(file) + 1); + fl->file = strdup(file); if (!fl->file) goto oom; - strcpy(fl->file, file); return fl->specind; } @@ -232,10 +231,9 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file) __FUNCTION__, file, fl->file, con_array[fl->specind]); free(fl->file); - fl->file = malloc(strlen(file) + 1); + fl->file = strdup(file); if (!fl->file) goto oom; - strcpy(fl->file, file); return fl->specind; } @@ -248,10 +246,9 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file) goto oom; fl->ino = ino; fl->specind = specind; - fl->file = malloc(strlen(file) + 1); + fl->file = strdup(file); if (!fl->file) goto oom_freefl; - strcpy(fl->file, file); fl->next = prevfl->next; prevfl->next = fl; return fl->specind; diff --git a/libselinux/utils/selabel_lookup_best_match.c b/libselinux/utils/selabel_lookup_best_match.c index a4af0679..e816c04b 100644 --- a/libselinux/utils/selabel_lookup_best_match.c +++ b/libselinux/utils/selabel_lookup_best_match.c @@ -30,7 +30,7 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname) exit(1); } -static mode_t string_to_mode(char *s) +static mode_t string_to_mode(const char *s) { switch (s[0]) { case 'b': @@ -53,7 +53,7 @@ static mode_t string_to_mode(char *s) int main(int argc, char **argv) { - int raw = 0, mode = 0, rc, opt, i, num_links, string_len; + int raw = 0, mode = 0, rc, opt, i, num_links; char *validate = NULL, *path = NULL, *context = NULL, *file = NULL; char **links = NULL; @@ -101,13 +101,11 @@ int main(int argc, char **argv) } for (i = optind, num_links = 0; i < argc; i++, num_links++) { - string_len = strlen(argv[i]) + 1; - links[num_links] = malloc(string_len); + links[num_links] = strdup(argv[i]); if (!links[num_links]) { - fprintf(stderr, "ERROR: malloc failed.\n"); + fprintf(stderr, "ERROR: strdup failed.\n"); exit(1); } - strcpy(links[num_links], argv[i]); } } From patchwork Wed Nov 9 20:09:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13038016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F245C4332F for ; Wed, 9 Nov 2022 20:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbiKIUJy (ORCPT ); Wed, 9 Nov 2022 15:09:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbiKIUJx (ORCPT ); Wed, 9 Nov 2022 15:09:53 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C36412AC0 for ; Wed, 9 Nov 2022 12:09:48 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id 13so49982269ejn.3 for ; Wed, 09 Nov 2022 12:09:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=G28Wq5r7lgIxHleW9iOgrQewl6BMYxNWJrQnl86zz9Y=; b=f357tF30k5sSsNLO3fLQm4YCAuyS/LEhlIWunVdomyyRq5myNJdJ5QlBNEUQc/p4q7 3SE8SrRpwfaO+i7MiqkyQXtCCWXlAyFKKLB0v7j4R+Ju+H7wHakckcoV0nApIHHZLkOV BgY7SFrsg3ELyAg8DqoP7f9qf5I+3iDO4+tKu3+gDQbL1PCdpitbHmwf2SewmCdAoYBc l31eon0WabU+jnX1NA41Vpsx+/IHVIF+Q5rCxFw8pRJyaoUSNRR9rJ3s3Jci0ZkuCZxf reeIhl0H+KfMMYZtVKQNDGlXmG+/HjbORIaby5kj+xFpH6AX5Fw4MFIsVK0HP7snMsil fNhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G28Wq5r7lgIxHleW9iOgrQewl6BMYxNWJrQnl86zz9Y=; b=LFhIF6zvwWH9zQb1WmdZpaZv4jXBrcAGewkmu/ZNZeDmDOWNLNt3dBgaV8+msCBomw 3XAMRpZNFQUjM0TsK1wTg9ClTEBIbItpifM6kKbTbiei8i1DOP0+7S4vBgPxzVhi4yVk EfzbiIn6Dqvbq1jfHxe3ikCaPBhy/EEboOd60y6LeJewmibMCdEZKeKEFt78xMOSH73n YQhPL0WTF78j9Fa0Dpt0f2G7wblzFBNIxCOSOguknnZvd++XVSRBC9v8vYwL2bNG48qF C+A64gb0PHw30jMZdM10XxV9BUXiOi9bmSPTwFFpys2jAQc2Vh8Xr1esKTKfQMAoQPZj UvpQ== X-Gm-Message-State: ACrzQf1APNXBAkqVpjQhAgiIDt2Fh9Vep9u8dC/7vECCpw8fXumg/V96 34xNTYXEFhsQ2k2Qfs9JYRe95kw/tdQ= X-Google-Smtp-Source: AMsMyM7SohpInpGJ/yxbOyKiuqXn3fhtn5B3hMS3Htn7CdMbSi9fXRpLIFTaizbfES/NaC+QbM4utQ== X-Received: by 2002:a17:906:5a4b:b0:7ad:ba84:faf0 with SMTP id my11-20020a1709065a4b00b007adba84faf0mr54278167ejc.753.1668024587150; Wed, 09 Nov 2022 12:09:47 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-010-185-019.77.10.pool.telefonica.de. [77.10.185.19]) by smtp.gmail.com with ESMTPSA id l2-20020a1709063d2200b007adbd01c566sm6386115ejf.146.2022.11.09.12.09.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:09:46 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 2/3] checkpolicy: simplify string copying Date: Wed, 9 Nov 2022 21:09:38 +0100 Message-Id: <20221109200939.62525-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109200939.62525-1-cgzones@googlemail.com> References: <20221109200939.62525-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Use strdup(3) instead of allocating memory and then manually copying the content. Signed-off-by: Christian Göttsche --- checkpolicy/checkpolicy.c | 10 ++++------ checkpolicy/policy_define.c | 3 +-- checkpolicy/test/dispol.c | 5 ++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c index 926ce72c..48c31261 100644 --- a/checkpolicy/checkpolicy.c +++ b/checkpolicy/checkpolicy.c @@ -1148,12 +1148,11 @@ int main(int argc, char **argv) FGETS(ans, sizeof(ans), stdin); ans[strlen(ans) - 1] = 0; - name = malloc((strlen(ans) + 1) * sizeof(char)); + name = strdup(ans); if (name == NULL) { - fprintf(stderr, "couldn't malloc string.\n"); + fprintf(stderr, "couldn't strdup string.\n"); break; } - strcpy(name, ans); printf("state? "); FGETS(ans, sizeof(ans), stdin); @@ -1296,12 +1295,11 @@ int main(int argc, char **argv) FGETS(ans, sizeof(ans), stdin); ans[strlen(ans) - 1] = 0; - name = malloc((strlen(ans) + 1) * sizeof(char)); + name = strdup(ans); if (!name) { - fprintf(stderr, "couldn't malloc string.\n"); + fprintf(stderr, "couldn't strdup string.\n"); break; } - strcpy(name, ans); printf("port? "); FGETS(ans, sizeof(ans), stdin); diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c index 54bb304b..41e44631 100644 --- a/checkpolicy/policy_define.c +++ b/checkpolicy/policy_define.c @@ -117,12 +117,11 @@ int insert_id(const char *id, int push) char *newid = 0; int error; - newid = (char *)malloc(strlen(id) + 1); + newid = strdup(id); if (!newid) { yyerror("out of memory"); return -1; } - strcpy(newid, id); if (push) error = queue_push(id_queue, (queue_element_t) newid); else diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c index 8ddefb04..36a3362c 100644 --- a/checkpolicy/test/dispol.c +++ b/checkpolicy/test/dispol.c @@ -486,12 +486,11 @@ int main(int argc, char **argv) } ans[strlen(ans) - 1] = 0; - name = malloc((strlen(ans) + 1) * sizeof(char)); + name = strdup(ans); if (name == NULL) { - fprintf(stderr, "couldn't malloc string.\n"); + fprintf(stderr, "couldn't strdup string.\n"); break; } - strcpy(name, ans); printf("state? "); if (fgets(ans, sizeof(ans), stdin) == NULL) { From patchwork Wed Nov 9 20:09:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13038017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2976DC4332F for ; Wed, 9 Nov 2022 20:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230265AbiKIUJz (ORCPT ); Wed, 9 Nov 2022 15:09:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbiKIUJz (ORCPT ); Wed, 9 Nov 2022 15:09:55 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1D013FAF for ; Wed, 9 Nov 2022 12:09:49 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id y14so49902944ejd.9 for ; Wed, 09 Nov 2022 12:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=88dkEESf74uOPQD+Ep7kFRL7dhGn1rE7tgjTDSD876g=; b=A+VEqpO3v1pdzTSFBgKpFe9PtM8FSnKxDmY55XYH8g91DH4tpC3sJ/zGYZgSM2t9MC 5L3vrqMsA8ByZJFbT7UGxqDC/6RQaXu68iVBMyw0t6ka7TRQsvolcriW72kFr4wFeSJi s5b/mqcLLYIBMZkyLC1HfIvVBTiasSmoI8WNFSFu3RQkorhEUaKuvAOdKAYK9hQB9209 B8crGJF9mmP1xRkwRJwMEwOIHUH5g3/qHPEvYTFD3G5SJuUi1rwGDHEvkgdEuyx9YTtt eaLM71Kv3ixW+i1ezTLS5UAF0/r8rgDCwtzBwDHOfjwEvO+QhNooXn4VaHkGqfWjIczd zraA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=88dkEESf74uOPQD+Ep7kFRL7dhGn1rE7tgjTDSD876g=; b=O6PY9FAiJr60rTSRmFkxrqs/chEJLwf7dmMZjt2LFsiLBjpMP5c/kNbYXLni3NAJii ZlDzEvZiYmDDu2VnbtSlFYXGlEMKfKJ568W/C2T3tyFNgVqDipMuRblF7ox6Arva+S3F 6szU7kE6H3Ke6AHurkirR4n66C9gvMuv/p9cGAC/nZPxtpeigLZSNL6M3yB84QXZ4VyP kiH8Q4voyFw9s3qzdpdVzEmkIPAQLx5k537WSQ88/YM6GJnTOBBuVkfFhyaUGIdLbw4R XhspC4v9kjdRy8qmMWqbWsEElTv+83kXpcaLWxpPjQDlZB49c4sdsAlU+baCpBalvRzI UYCg== X-Gm-Message-State: ACrzQf1ZSZLnfjXfoC9cepTNko5RyeT51YAhN07C3FtrBJ1agyaScjbG 2G/ST+Vm6xiZT1gb3GsMnIAf7SfLebk= X-Google-Smtp-Source: AMsMyM5qOtV2YgT+hkJoEKLxGLAmBrsJtJTVW36e8tMr05P5hPKAfo+g/UO7bnpuabA4KjPg0vFO8Q== X-Received: by 2002:a17:906:1c52:b0:7ad:c6c5:eae8 with SMTP id l18-20020a1709061c5200b007adc6c5eae8mr51653469ejg.439.1668024587709; Wed, 09 Nov 2022 12:09:47 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-010-185-019.77.10.pool.telefonica.de. [77.10.185.19]) by smtp.gmail.com with ESMTPSA id l2-20020a1709063d2200b007adbd01c566sm6386115ejf.146.2022.11.09.12.09.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:09:47 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 3/3] libsepol: simplify string copying Date: Wed, 9 Nov 2022 21:09:39 +0100 Message-Id: <20221109200939.62525-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109200939.62525-1-cgzones@googlemail.com> References: <20221109200939.62525-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Use strdup(3) instead of allocating memory and then manually copying the content. Signed-off-by: Christian Göttsche --- libsepol/src/policydb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index 8a65df05..b79c19b9 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -776,12 +776,11 @@ static int roles_init(policydb_t * p) rc = -ENOMEM; goto out; } - key = malloc(strlen(OBJECT_R) + 1); + key = strdup(OBJECT_R); if (!key) { rc = -ENOMEM; goto out_free_role; } - strcpy(key, OBJECT_R); rc = symtab_insert(p, SYM_ROLES, key, role, (p->policy_type == POLICY_MOD ? SCOPE_REQ : SCOPE_DECL), 1,