* rpl_unlink sets errno to EPERM on malloc failure
@ 2020-03-20 11:54 Tim Rühsen
2020-03-21 23:15 ` Paul Eggert
0 siblings, 1 reply; 3+ messages in thread
From: Tim Rühsen @ 2020-03-20 11:54 UTC (permalink / raw)
To: bug-gnulib
[-- Attachment #1.1: Type: text/plain, Size: 333 bytes --]
Is this EPERM intended ? If yes, there should be a comment.
lib/unlink.c (rpl_unlink):
/* Trailing NUL will overwrite the trailing slash. */
char *short_name = malloc (len);
if (!short_name)
{
errno = EPERM;
return -1;
}
Regards, Tim
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: rpl_unlink sets errno to EPERM on malloc failure
2020-03-20 11:54 rpl_unlink sets errno to EPERM on malloc failure Tim Rühsen
@ 2020-03-21 23:15 ` Paul Eggert
2020-03-22 1:41 ` Bruno Haible
0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2020-03-21 23:15 UTC (permalink / raw)
To: Tim Rühsen; +Cc: bug-gnulib
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
On 3/20/20 4:54 AM, Tim Rühsen wrote:
> Is this EPERM intended ?
No, it's clearly a typo. Thanks for reporting it. I installed the attached.
[-- Attachment #2: 0001-unlink-fix-malloc-errno-typo.patch --]
[-- Type: text/x-patch, Size: 1613 bytes --]
From 3e89c500a2f17a8a7a278390d48419990ce24bc8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 21 Mar 2020 16:13:28 -0700
Subject: [PATCH] unlink: fix malloc errno typo
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Tim Rühsen in:
https://lists.gnu.org/r/bug-gnulib/2020-03/msg00044.html
* lib/unlink.c (rpl_unlink): Don’t mask malloc errno.
---
ChangeLog | 7 +++++++
lib/unlink.c | 5 +----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0019334ca..9b2a112eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-03-21 Paul Eggert <eggert@cs.ucla.edu>
+
+ unlink: fix malloc errno typo
+ Problem reported by Tim Rühsen in:
+ https://lists.gnu.org/r/bug-gnulib/2020-03/msg00044.html
+ * lib/unlink.c (rpl_unlink): Don’t mask malloc errno.
+
2020-03-16 Bruno Haible <bruno@clisp.org>
*printf-posix: Fix m4 error (regression from 2020-03-08).
diff --git a/lib/unlink.c b/lib/unlink.c
index b7daa7cd3..5e0f4e177 100644
--- a/lib/unlink.c
+++ b/lib/unlink.c
@@ -65,10 +65,7 @@ rpl_unlink (char const *name)
/* Trailing NUL will overwrite the trailing slash. */
char *short_name = malloc (len);
if (!short_name)
- {
- errno = EPERM;
- return -1;
- }
+ return -1;
memcpy (short_name, name, len);
while (len && ISSLASH (short_name[len - 1]))
short_name[--len] = '\0';
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: rpl_unlink sets errno to EPERM on malloc failure
2020-03-21 23:15 ` Paul Eggert
@ 2020-03-22 1:41 ` Bruno Haible
0 siblings, 0 replies; 3+ messages in thread
From: Bruno Haible @ 2020-03-22 1:41 UTC (permalink / raw)
To: bug-gnulib; +Cc: Tim Rühsen, Paul Eggert
Paul Eggert wrote:
--- a/lib/unlink.c
+++ b/lib/unlink.c
@@ -65,10 +65,7 @@ rpl_unlink (char const *name)
/* Trailing NUL will overwrite the trailing slash. */
char *short_name = malloc (len);
if (!short_name)
- {
- errno = EPERM;
- return -1;
- }
+ return -1;
memcpy (short_name, name, len);
while (len && ISSLASH (short_name[len - 1]))
short_name[--len] = '\0';
But while on POSIX systems, malloc() is guaranteed to set errno when it fails,
for native Windows systems we need the 'malloc-posix' module, in order to
guarantee this.
2020-03-21 Bruno Haible <bruno@clisp.org>
unlink: Ensure errno also on native Windows.
* modules/unlink (Depends-on): Add malloc-posix.
diff --git a/modules/unlink b/modules/unlink
index 63720aa..5fc84d9 100644
--- a/modules/unlink
+++ b/modules/unlink
@@ -9,6 +9,7 @@ Depends-on:
unistd
dosname [test $REPLACE_UNLINK = 1]
lstat [test $REPLACE_UNLINK = 1]
+malloc-posix [test $REPLACE_UNLINK = 1]
configure.ac:
gl_FUNC_UNLINK
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-22 1:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 11:54 rpl_unlink sets errno to EPERM on malloc failure Tim Rühsen
2020-03-21 23:15 ` Paul Eggert
2020-03-22 1:41 ` Bruno Haible
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).