]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
assert: Remove the use of %n from __assert_fail_base (BZ #32456)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 30 Dec 2024 19:36:18 +0000 (16:36 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 2 Jan 2025 13:19:42 +0000 (10:19 -0300)
The require size for mmap can be inferred from __vasprintf return
value.  It also fixes tst-assert-2 when building with --enable-fortify,
where even if the format is not translated, __readonly_area fails
because malloc can not be used.

Checked on aarch64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
assert/assert-perr.c
assert/assert.c
po/libc.pot

index 80cae4d00dd5d54dfab21bb88e2f98fcc5d4fe93..83f0b3a76fd2e39b2399cdb9d60ad6689e23ccab 100644 (file)
@@ -32,7 +32,7 @@ __assert_perror_fail (int errnum,
   char errbuf[1024];
 
   char *e = __strerror_r (errnum, errbuf, sizeof errbuf);
-  __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n%n"),
+  __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n"),
                      e, file, line, function);
 }
 libc_hidden_def (__assert_perror_fail)
index 47b06ec7fd96a848b8635df438471864b4dc7ed6..db90b8d7ef57ba679ed7b3a77785b3e46abfb26d 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
-#include <atomic.h>
+#include <intprops.h>
 #include <ldsodefs.h>
 #include <libintl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sysdep.h>
-#include <unistd.h>
-#include <sys/mman.h>
+#include <libio/iolibio.h>
 #include <setvmaname.h>
 #include <sys/uio.h>
-#include <intprops.h>
+#include <unistd.h>
 
 
 extern const char *__progname;
 
-#include <wchar.h>
-#include <libio/iolibio.h>
 #define fflush(s) _IO_fflush (s)
 
 /* This function, when passed a string containing an asserted
@@ -56,12 +49,12 @@ __assert_fail_base (const char *fmt, const char *assertion, const char *file,
   FATAL_PREPARE;
 #endif
 
-  int total;
-  if (__asprintf (&str, fmt,
-                 __progname, __progname[0] ? ": " : "",
-                 file, line,
-                 function ? function : "", function ? ": " : "",
-                 assertion, &total) >= 0)
+  int total = __asprintf (&str, fmt,
+                         __progname, __progname[0] ? ": " : "",
+                         file, line,
+                         function ? function : "", function ? ": " : "",
+                         assertion);
+  if (total >= 0)
     {
       /* Print the message.  */
       (void) __fxprintf (NULL, "%s", str);
@@ -129,6 +122,6 @@ void
 __assert_fail (const char *assertion, const char *file, unsigned int line,
               const char *function)
 {
-  __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"),
+  __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n"),
                      assertion, file, line, function);
 }
index d66bd04122e2fc8da7c1f821fd8c2867bb0b7a57..c8193f53c7333dd6f130de0eb8cf808f8efb2d1e 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: libc 2.40.9000\n"
-"POT-Creation-Date: 2024-12-30 16:29-0300\n"
+"POT-Creation-Date: 2024-12-30 16:34-0300\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -102,16 +102,12 @@ msgstr ""
 
 #: assert/assert-perr.c:35
 #, c-format
-msgid ""
-"%s%s%s:%u: %s%sUnexpected error: %s.\n"
-"%n"
+msgid "%s%s%s:%u: %s%sUnexpected error: %s.\n"
 msgstr ""
 
-#: assert/assert.c:132
+#: assert/assert.c:125
 #, c-format
-msgid ""
-"%s%s%s:%u: %s%sAssertion `%s' failed.\n"
-"%n"
+msgid "%s%s%s:%u: %s%sAssertion `%s' failed.\n"
 msgstr ""
 
 #: catgets/gencat.c:111