public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly
@ 2023-01-03 17:03 himalr at proton dot me
  2023-01-03 17:24 ` [Bug other/108276] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: himalr at proton dot me @ 2023-01-03 17:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

            Bug ID: 108276
           Summary: libiberty unlink_if_ordinary does not handle Windows
                    nul device correctly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: himalr at proton dot me
  Target Milestone: ---

Created attachment 54180
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54180&action=edit
Handle Windows nul device correctly in unlink_if_ordinary function

I reported this as a part of another bug to [Sourceware
Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=29947) and was asked
to report this here.

In Windows, 'stat' function (and in turn, S_ISREG) returns true for null device
as a regular file.

Please note that I'm not a C programmer so let me know if there are any issues
with the patch.

Thanks.

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
@ 2023-01-03 17:24 ` pinskia at gcc dot gnu.org
  2023-01-16 16:23 ` i.nixman at autistici dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-03 17:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patches should be sent to gcc-patches@ after reading
https://gcc.gnu.org/contribute.html

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
  2023-01-03 17:24 ` [Bug other/108276] " pinskia at gcc dot gnu.org
@ 2023-01-16 16:23 ` i.nixman at autistici dot org
  2023-01-16 17:02 ` i.nixman at autistici dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: i.nixman at autistici dot org @ 2023-01-16 16:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #2 from niXman <i.nixman at autistici dot org> ---
@Himal

```
+#ifdef _WIN32
+    if (stricmp (name, "nul") == 0)
+      return 1;
+#else
   struct stat st;

   if (lstat (name, &st) == 0
       && (S_ISREG (st.st_mode) || S_ISLNK (st.st_mode)))
     return unlink (name);
+#endif

```

I don't think the patch is correct because for WIN32 platform `unlink()` will
never be called even for non-"nul" files.

right?

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
  2023-01-03 17:24 ` [Bug other/108276] " pinskia at gcc dot gnu.org
  2023-01-16 16:23 ` i.nixman at autistici dot org
@ 2023-01-16 17:02 ` i.nixman at autistici dot org
  2023-01-16 18:28 ` i.nixman at autistici dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: i.nixman at autistici dot org @ 2023-01-16 17:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #3 from niXman <i.nixman at autistici dot org> ---
and I propose to use `strcasecmp()`

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
                   ` (2 preceding siblings ...)
  2023-01-16 17:02 ` i.nixman at autistici dot org
@ 2023-01-16 18:28 ` i.nixman at autistici dot org
  2023-01-17  1:18 ` himalr at proton dot me
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: i.nixman at autistici dot org @ 2023-01-16 18:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #4 from niXman <i.nixman at autistici dot org> ---
(In reply to niXman from comment #2)

> I don't think the patch is correct because for WIN32 platform `unlink()`
> will never be called even for non-"nul" files.

moreover, according to the man:
https://github.com/MicrosoftDocs/cpp-docs/blob/main/docs/c-runtime-library/reference/unlink-wunlink.md

microsoft's `unlink()/_unlink()` works as just `remove()`.

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
                   ` (3 preceding siblings ...)
  2023-01-16 18:28 ` i.nixman at autistici dot org
@ 2023-01-17  1:18 ` himalr at proton dot me
  2023-01-17  7:06 ` i.nixman at autistici dot org
  2023-01-18  0:53 ` himalr at proton dot me
  6 siblings, 0 replies; 8+ messages in thread
From: himalr at proton dot me @ 2023-01-17  1:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #5 from Himal <himalr at proton dot me> ---
(In reply to niXman from comment #4)
> (In reply to niXman from comment #2)
> 
> > I don't think the patch is correct because for WIN32 platform `unlink()`
> > will never be called even for non-"nul" files.
> 
> moreover, according to the man:
> https://github.com/MicrosoftDocs/cpp-docs/blob/main/docs/c-runtime-library/
> reference/unlink-wunlink.md
> 
> microsoft's `unlink()/_unlink()` works as just `remove()`.

Hi, Thanks for the feedback. I noticed this while looking for
[this](https://sourceware.org/bugzilla/show_bug.cgi?id=29947) bug. 

In MSYS/MinGW, It calls the `unlink` function even for 'nul', but it wasn't
throwing any errors.

I decided to submit this patch because it already has some code checking for
special devices before calling `unlink`. If it's not required then I guess we
can close this.

Thanks.

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
                   ` (4 preceding siblings ...)
  2023-01-17  1:18 ` himalr at proton dot me
@ 2023-01-17  7:06 ` i.nixman at autistici dot org
  2023-01-18  0:53 ` himalr at proton dot me
  6 siblings, 0 replies; 8+ messages in thread
From: i.nixman at autistici dot org @ 2023-01-17  7:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #6 from niXman <i.nixman at autistici dot org> ---
I think you don't understand me.

with your patch after preprocessing the `unlink_if_ordinary()` will look like:
```
int
unlink_if_ordinary (const char *name)
{
  if (stricmp (name, "nul") == 0)
    return 1;

  return 1;
}

```

don't you think it's strange?

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

* [Bug other/108276] libiberty unlink_if_ordinary does not handle Windows nul device correctly
  2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
                   ` (5 preceding siblings ...)
  2023-01-17  7:06 ` i.nixman at autistici dot org
@ 2023-01-18  0:53 ` himalr at proton dot me
  6 siblings, 0 replies; 8+ messages in thread
From: himalr at proton dot me @ 2023-01-18  0:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108276

--- Comment #7 from Himal <himalr at proton dot me> ---
(In reply to niXman from comment #6)
> I think you don't understand me.
> 
> with your patch after preprocessing the `unlink_if_ordinary()` will look
> like:
> ```
> int
> unlink_if_ordinary (const char *name)
> {
>   if (stricmp (name, "nul") == 0)
>     return 1;
> 
>   return 1;
> }
> 
> ```
> 
> don't you think it's strange?

Ah, yes. I noticed that after submitting the patch. I have already posted an
updated version
[here](https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609487.html)

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

end of thread, other threads:[~2023-01-18  0:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 17:03 [Bug other/108276] New: libiberty unlink_if_ordinary does not handle Windows nul device correctly himalr at proton dot me
2023-01-03 17:24 ` [Bug other/108276] " pinskia at gcc dot gnu.org
2023-01-16 16:23 ` i.nixman at autistici dot org
2023-01-16 17:02 ` i.nixman at autistici dot org
2023-01-16 18:28 ` i.nixman at autistici dot org
2023-01-17  1:18 ` himalr at proton dot me
2023-01-17  7:06 ` i.nixman at autistici dot org
2023-01-18  0:53 ` himalr at proton dot me

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