public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Handle DT_UNKNOWN in gconv-modules.d
@ 2021-06-09  4:38 Siddhesh Poyarekar
  2021-06-09 17:21 ` Adhemerval Zanella
  0 siblings, 1 reply; 5+ messages in thread
From: Siddhesh Poyarekar @ 2021-06-09  4:38 UTC (permalink / raw)
  To: libc-alpha; +Cc: dj, schwab

On filesystems that do not support dt_type, a regular file shows up as
DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
such cases.
---
 iconv/gconv_conf.c  | 9 ++++++++-
 iconv/iconvconfig.c | 8 +++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
index c8ad8099a4..7fc3a810af 100644
--- a/iconv/gconv_conf.c
+++ b/iconv/gconv_conf.c
@@ -587,7 +587,7 @@ __gconv_read_conf (void)
 	  struct dirent *ent;
 	  while ((ent = __readdir (confdir)) != NULL)
 	    {
-	      if (ent->d_type != DT_REG)
+	      if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
 		continue;
 
 	      size_t len = strlen (ent->d_name);
@@ -596,10 +596,17 @@ __gconv_read_conf (void)
 	      if (len > strlen (suffix)
 		  && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
 		{
+		  struct stat64 st;
 		  /* 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);
+
+		  if (ent->d_type == DT_UNKNOWN
+		      && (__lstat64 (conf, &st) == -1
+			  || !S_ISREG (st.st_mode)))
+		    continue;
+
 		  read_conf_file (conf, elem, elem_len, &modules, &nmodules);
 		}
 	    }
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
index b2a868919c..8f10f4aba8 100644
--- a/iconv/iconvconfig.c
+++ b/iconv/iconvconfig.c
@@ -747,7 +747,7 @@ handle_dir (const char *dir)
       struct dirent *ent;
       while ((ent = readdir (confdir)) != NULL)
 	{
-	  if (ent->d_type != DT_REG)
+	  if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
 	    continue;
 
 	  size_t len = strlen (ent->d_name);
@@ -756,10 +756,16 @@ handle_dir (const char *dir)
 	  if (len > strlen (suffix)
 	      && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
 	    {
+	      struct stat64 st;
 	      /* 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);
+
+	      if (ent->d_type == DT_UNKNOWN
+		  && (lstat64 (conf, &st) == -1 || !S_ISREG (st.st_mode)))
+		continue;
+
 	      found |= handle_file (dir, conf);
 	    }
 	}
-- 
2.31.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle DT_UNKNOWN in gconv-modules.d
  2021-06-09  4:38 [PATCH] Handle DT_UNKNOWN in gconv-modules.d Siddhesh Poyarekar
@ 2021-06-09 17:21 ` Adhemerval Zanella
  2021-06-09 18:08   ` Siddhesh Poyarekar
  0 siblings, 1 reply; 5+ messages in thread
From: Adhemerval Zanella @ 2021-06-09 17:21 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: schwab



On 09/06/2021 01:38, Siddhesh Poyarekar via Libc-alpha wrote:
> On filesystems that do not support dt_type, a regular file shows up as
> DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
> such cases.

The patch looks ok, but two things raised checking on this code: 1.
the code is essentially the same on both places and 2. the use of 
alloca() even when it is assured that is bounded and 2. 

The former would be nice if could consolidate it (even by adding
a file where both iconvconfig and iconv could include or even
by a GLIBC_PRIVATE symbol), but it is not a deal breaker.

But I think we should move away from alloca, even when we know it
is bounded (sorry if I didn't catch on the previous patch).  For
this specific usage we can use asprintf to create the path or use
a static PATH_MAX buffer.

> ---
>  iconv/gconv_conf.c  | 9 ++++++++-
>  iconv/iconvconfig.c | 8 +++++++-
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
> index c8ad8099a4..7fc3a810af 100644
> --- a/iconv/gconv_conf.c
> +++ b/iconv/gconv_conf.c
> @@ -587,7 +587,7 @@ __gconv_read_conf (void)
>  	  struct dirent *ent;
>  	  while ((ent = __readdir (confdir)) != NULL)
>  	    {
> -	      if (ent->d_type != DT_REG)
> +	      if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
>  		continue;
>  
>  	      size_t len = strlen (ent->d_name);
> @@ -596,10 +596,17 @@ __gconv_read_conf (void)
>  	      if (len > strlen (suffix)
>  		  && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
>  		{
> +		  struct stat64 st;
>  		  /* 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);
> +
> +		  if (ent->d_type == DT_UNKNOWN
> +		      && (__lstat64 (conf, &st) == -1
> +			  || !S_ISREG (st.st_mode)))
> +		    continue;
> +
>  		  read_conf_file (conf, elem, elem_len, &modules, &nmodules);
>  		}
>  	    }
> diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
> index b2a868919c..8f10f4aba8 100644
> --- a/iconv/iconvconfig.c
> +++ b/iconv/iconvconfig.c
> @@ -747,7 +747,7 @@ handle_dir (const char *dir)
>        struct dirent *ent;
>        while ((ent = readdir (confdir)) != NULL)
>  	{
> -	  if (ent->d_type != DT_REG)
> +	  if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
>  	    continue;
>  
>  	  size_t len = strlen (ent->d_name);
> @@ -756,10 +756,16 @@ handle_dir (const char *dir)
>  	  if (len > strlen (suffix)
>  	      && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
>  	    {
> +	      struct stat64 st;
>  	      /* 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);
> +
> +	      if (ent->d_type == DT_UNKNOWN
> +		  && (lstat64 (conf, &st) == -1 || !S_ISREG (st.st_mode)))
> +		continue;
> +
>  	      found |= handle_file (dir, conf);
>  	    }
>  	}
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle DT_UNKNOWN in gconv-modules.d
  2021-06-09 17:21 ` Adhemerval Zanella
@ 2021-06-09 18:08   ` Siddhesh Poyarekar
  2021-06-09 18:27     ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Siddhesh Poyarekar @ 2021-06-09 18:08 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha; +Cc: schwab

On 6/9/21 10:51 PM, Adhemerval Zanella wrote:
> 
> 
> On 09/06/2021 01:38, Siddhesh Poyarekar via Libc-alpha wrote:
>> On filesystems that do not support dt_type, a regular file shows up as
>> DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
>> such cases.
> 
> The patch looks ok, but two things raised checking on this code: 1.
> the code is essentially the same on both places and 2. the use of
> alloca() even when it is assured that is bounded and 2.
> 
> The former would be nice if could consolidate it (even by adding
> a file where both iconvconfig and iconv could include or even
> by a GLIBC_PRIVATE symbol), but it is not a deal breaker.

I tried to do this but the code came out clumsier because the result 
(call to handle_file vs read_conf_file) have different semantics.

> But I think we should move away from alloca, even when we know it
> is bounded (sorry if I didn't catch on the previous patch).  For
> this specific usage we can use asprintf to create the path or use
> a static PATH_MAX buffer.

I agree, a static PATH_MAX makes sense, I'll do that.

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle DT_UNKNOWN in gconv-modules.d
  2021-06-09 18:08   ` Siddhesh Poyarekar
@ 2021-06-09 18:27     ` Florian Weimer
  2021-06-09 18:28       ` Siddhesh Poyarekar
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2021-06-09 18:27 UTC (permalink / raw)
  To: Siddhesh Poyarekar via Libc-alpha
  Cc: Adhemerval Zanella, Siddhesh Poyarekar, schwab

* Siddhesh Poyarekar via Libc-alpha:

>> But I think we should move away from alloca, even when we know it
>> is bounded (sorry if I didn't catch on the previous patch).  For
>> this specific usage we can use asprintf to create the path or use
>> a static PATH_MAX buffer.
>
> I agree, a static PATH_MAX makes sense, I'll do that.

PATH_MAX is not available on Hurd.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle DT_UNKNOWN in gconv-modules.d
  2021-06-09 18:27     ` Florian Weimer
@ 2021-06-09 18:28       ` Siddhesh Poyarekar
  0 siblings, 0 replies; 5+ messages in thread
From: Siddhesh Poyarekar @ 2021-06-09 18:28 UTC (permalink / raw)
  To: Florian Weimer, Siddhesh Poyarekar via Libc-alpha; +Cc: schwab

On 6/9/21 11:57 PM, Florian Weimer via Libc-alpha wrote:
> * Siddhesh Poyarekar via Libc-alpha:
> 
>>> But I think we should move away from alloca, even when we know it
>>> is bounded (sorry if I didn't catch on the previous patch).  For
>>> this specific usage we can use asprintf to create the path or use
>>> a static PATH_MAX buffer.
>>
>> I agree, a static PATH_MAX makes sense, I'll do that.
> 
> PATH_MAX is not available on Hurd.

(grumbling redacted)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-09 18:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  4:38 [PATCH] Handle DT_UNKNOWN in gconv-modules.d Siddhesh Poyarekar
2021-06-09 17:21 ` Adhemerval Zanella
2021-06-09 18:08   ` Siddhesh Poyarekar
2021-06-09 18:27     ` Florian Weimer
2021-06-09 18:28       ` Siddhesh Poyarekar

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).