public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Peter Bergner <bergner@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ibm/heads/gcc-10-branch)] libstdc++: Fix unnecessary allocations in read_symlink [PR 96484]
Date: Wed, 19 Aug 2020 13:57:27 +0000 (GMT)	[thread overview]
Message-ID: <20200819135727.D71693846405@sourceware.org> (raw)

https://gcc.gnu.org/g:8b7e7fcb5fff8255122a8fa94109f7ae05aeaa81

commit 8b7e7fcb5fff8255122a8fa94109f7ae05aeaa81
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 6 18:44:50 2020 +0100

    libstdc++: Fix unnecessary allocations in read_symlink [PR 96484]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/96484
            * src/c++17/fs_ops.cc (fs::read_symlink): Return an error
            immediately for non-symlinks.
            * src/filesystem/ops.cc (fs::read_symlink): Likewise.
    
    (cherry picked from commit 6a13a4e3f29fc4ce5eff96d74ba965c9fdc02184)

Diff:
---
 libstdc++-v3/src/c++17/fs_ops.cc   | 6 ++++++
 libstdc++-v3/src/filesystem/ops.cc | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 873f93aacfc..c685b1824f9 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -1180,6 +1180,12 @@ fs::path fs::read_symlink(const path& p, error_code& ec)
       ec.assign(errno, std::generic_category());
       return result;
     }
+  else if (!fs::is_symlink(make_file_status(st)))
+    {
+      ec.assign(EINVAL, std::generic_category());
+      return result;
+    }
+
   std::string buf(st.st_size ? st.st_size + 1 : 128, '\0');
   do
     {
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index 29ea9c0ce87..8c8854bf28e 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -998,6 +998,12 @@ fs::path fs::read_symlink(const path& p [[gnu::unused]], error_code& ec)
       ec.assign(errno, std::generic_category());
       return result;
     }
+  else if (!fs::is_symlink(make_file_status(st)))
+    {
+      ec.assign(EINVAL, std::generic_category());
+      return result;
+    }
+
   std::string buf(st.st_size ? st.st_size + 1 : 128, '\0');
   do
     {


                 reply	other threads:[~2020-08-19 13:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200819135727.D71693846405@sourceware.org \
    --to=bergner@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.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).