SELinux Security Module development
 help / color / mirror / Atom feed
From: Rahul Sandhu <nvraxn@posteo.uk>
To: nvraxn@gmail.com
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v3] libsepol: policydb_read(): use a static string for policydb_str
Date: Fri, 24 Apr 2026 20:40:56 +0000	[thread overview]
Message-ID: <86eck4852p.fsf@posteo.uk> (raw)
In-Reply-To: <20260403065618.2172556-2-nvraxn@posteo.uk> (Rahul Sandhu's message of "Fri, 03 Apr 2026 06:56:31 +0000")


Ping

On Fri Apr 03, 2026 at 07:56 AM BST, Rahul Sandhu wrote:
> We know the maximum possible size of policydb_str at compile time; it's
> POLICYDB_STRING_MAX_LENGTH + 1 (with + 1 accounting for the null term).
> As POLICYDB_STRING_MAX_LENGTH is trivially small, make it a static str,
> avoiding an extra allocation.
>
> Signed-off-by: Rahul Sandhu <nvraxn@posteo.uk>
> ---
>  libsepol/src/policydb.c | 15 +--------------
>  1 file changed, 1 insertion(+), 14 deletions(-)
>
> v3: fix authorship mess
>
> diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c
> index 9760b164..8d290d86 100644
> --- a/libsepol/src/policydb.c
> +++ b/libsepol/src/policydb.c
> @@ -4192,7 +4192,7 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
>  	unsigned int i, j, r_policyvers;
>  	uint32_t buf[5], nprim;
>  	size_t len, nel;
> -	char *policydb_str;
> +	char policydb_str[POLICYDB_STRING_MAX_LENGTH + 1];
>  	const struct policydb_compat_info *info;
>  	unsigned int policy_type, bufindex;
>  	ebitmap_node_t *tnode;
> @@ -4222,16 +4222,9 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
>  		return POLICYDB_ERROR;
>  	}
>  
> -	policydb_str = malloc(len + 1);
> -	if (!policydb_str) {
> -		ERR(fp->handle, "unable to allocate memory for policydb "
> -		    "string of length %zu", len);
> -		return POLICYDB_ERROR;
> -	}
>  	rc = next_entry(policydb_str, fp, len);
>  	if (rc < 0) {
>  		ERR(fp->handle, "truncated policydb string identifier");
> -		free(policydb_str);
>  		return POLICYDB_ERROR;
>  	}
>  	policydb_str[len] = 0;
> @@ -4248,22 +4241,16 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
>  		if (i == POLICYDB_TARGET_SZ) {
>  			ERR(fp->handle, "cannot find a valid target for policy "
>  				"string %s", policydb_str);
> -			free(policydb_str);
>  			return POLICYDB_ERROR;
>  		}
>  	} else {
>  		if (strcmp(policydb_str, POLICYDB_MOD_STRING)) {
>  			ERR(fp->handle, "invalid string identifier %s",
>  				policydb_str);
> -			free(policydb_str);
>  			return POLICYDB_ERROR;
>  		}
>  	}
>  
> -	/* Done with policydb_str. */
> -	free(policydb_str);
> -	policydb_str = NULL;
> -
>  	/* Read the version, config, and table sizes (and policy type if it's a module). */
>  	if (policy_type == POLICY_KERN)
>  		nel = 4;

-- 
Rahul Sandhu

  parent reply	other threads:[~2026-04-24 20:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03  6:53 [PATCH v2] libsepol: policydb_read(): use a static string for policydb_str Rahul Sandhu
2026-04-03  6:56 ` [PATCH v3] " Rahul Sandhu
2026-04-03  6:58   ` Rahul Sandhu
2026-04-24 20:40   ` Rahul Sandhu [this message]
2026-05-12 19:14   ` James Carter
2026-05-13 13:57     ` James Carter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86eck4852p.fsf@posteo.uk \
    --to=nvraxn@posteo.uk \
    --cc=nvraxn@gmail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox