public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 3/5] gconv_conf: Read configuration files in gconv-modules.d
Date: Tue, 08 Jun 2021 19:33:26 -0400	[thread overview]
Message-ID: <xn4ke8dj95.fsf@greed.delorie.com> (raw)
In-Reply-To: <20210607085221.43612-4-siddhesh@sourceware.org>


Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org> writes:
> diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
> +#include <dirent.h>

Ok

> +#include <sys/types.h>

Ok.

>  static const char gconv_conf_filename[] = "gconv-modules";
> +static const char gconv_conf_dirname[] = "gconv-modules.d";

Ok.

>  /* Filename extension for the modules.  */
>  #ifndef MODULE_EXT
> @@ -556,18 +559,52 @@ __gconv_read_conf (void)
>  
>    for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt)
>      {
> +#define BUF_LEN elem_len + sizeof (gconv_conf_dirname)
> +

Includes NUL through sizeof, ok.

>        size_t elem_len = __gconv_path_elem[cnt].len;
> -      char *filename;
> +      char *buf;
>  
>        /* No slash needs to be inserted between elem and gconv_conf_filename;
>  	 elem already ends in a slash.  */
> -      filename = alloca (elem_len + sizeof (gconv_conf_filename));
> -      __mempcpy (__mempcpy (filename, elem, elem_len),
> -		 gconv_conf_filename, sizeof (gconv_conf_filename));
> +      buf = alloca (BUF_LEN);
> +      char *cp = __mempcpy (__mempcpy (buf, elem, elem_len),
> +			    gconv_conf_filename, sizeof (gconv_conf_filename));
> +
> +      /* Read the gconv-modules configuration file first.  */
> +      read_conf_file (buf, elem, elem_len, &modules, &nmodules);
> +
> +      /* Next, see if there is a gconv-modules.d directory containing
> +	 configuration files and if it is non-empty.  */
> +      cp--;

Because cp pointed after the NUL, not after the filename. ok.

> +      cp[0] = '.';
> +      cp[1] = 'd';
> +      cp[2] = '\0';
> +
> +      DIR *confdir = __opendir (buf);
> +      if (confdir != NULL)
> +	{
> +	  struct dirent *ent;
> +	  while ((ent = __readdir (confdir)) != NULL)
> +	    {
> +	      if (ent->d_type != DT_REG)
> +		continue;
> +
> +	      size_t len = strlen (ent->d_name);
> +	      const char *suffix = ".conf";
>  
> -      /* Read the next configuration file.  */
> -      read_conf_file (filename, elem, elem_len, &modules, &nmodules);
> +	      if (len > strlen (suffix)
> +		  && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)

Ok.

> +		{
> +		  /* LEN <= PATH_MAX so this alloca is not unbounded.  */
> +		  char *conf = alloca (BUF_LEN + len + 1);
> +		  cp = stpcpy (conf, buf);
> +		  sprintf (cp, "/%s", ent->d_name);
> +		  read_conf_file (conf, elem, elem_len, &modules, &nmodules);
> +		}
> +	    }
> +	  __closedir (confdir);
> +	}
>      }
>  #endif

Ok.


  reply	other threads:[~2021-06-08 23:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  8:52 [PATCH 0/5] gconv module configuration improvements Siddhesh Poyarekar
2021-06-07  8:52 ` [PATCH 1/5] iconvconfig: Make file handling more general purpose Siddhesh Poyarekar
2021-06-08 20:53   ` DJ Delorie
2021-06-07  8:52 ` [PATCH 2/5] iconvconfig: Read configuration from gconv-modules.d subdirectory Siddhesh Poyarekar
2021-06-07  9:06   ` Andreas Schwab
2021-06-07  9:17     ` Siddhesh Poyarekar
2021-06-08 21:46   ` DJ Delorie
2021-06-07  8:52 ` [PATCH 3/5] gconv_conf: Read configuration files in gconv-modules.d Siddhesh Poyarekar
2021-06-08 23:33   ` DJ Delorie [this message]
2021-06-09  2:07   ` DJ Delorie
2021-06-07  8:52 ` [PATCH 4/5] iconvdata: Move gconv-modules configuration to gconv-modules.conf Siddhesh Poyarekar
2021-06-09  1:33   ` DJ Delorie
2021-06-10 10:23   ` Andreas Schwab
2021-06-10 11:11     ` Siddhesh Poyarekar
2021-06-10 11:24       ` Andreas Schwab
2021-06-10 11:28         ` Siddhesh Poyarekar
2021-06-10 11:58           ` Andreas Schwab
2021-06-07  8:52 ` [PATCH 5/5] iconvdata: Split out non-essential gconv module configuration Siddhesh Poyarekar
2021-06-09  2:00   ` DJ Delorie

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=xn4ke8dj95.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).