]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Fix wrong fscanf usage on tst-pldd
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 5 Jul 2022 15:58:40 +0000 (12:58 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 15 Jul 2022 13:07:55 +0000 (10:07 -0300)
The fix done b2cd93fce666fdc8c9a5c64af2741a8a6940ac99 does not really
work since macro strification does not expand the sizeof nor the
arithmetic operation.

Checked on x86_64-linux-gnu.

elf/tst-pldd.c

index 0616545b1d92f286b29d66e0453bb122aca96df4..9f633d41a2b3a9c04e4c6fa9e6f6ddaccd042619 100644 (file)
@@ -108,15 +108,16 @@ do_test (void)
      loader and libc.  */
   {
     pid_t pid;
-    char buffer[512];
-#define STRINPUT(size) "%" # size "s"
+#define BUFFERLEN 511
+    char buffer[BUFFERLEN + 1];
+#define STRINPUT(size)  XSTRINPUT(size)
+#define XSTRINPUT(size) "%" # size "s"
 
     FILE *out = fmemopen (pldd.out.buffer, pldd.out.length, "r");
     TEST_VERIFY (out != NULL);
 
     /* First line is in the form of <pid>: <full path of executable>  */
-    TEST_COMPARE (fscanf (out, "%u: " STRINPUT (sizeof (buffer) - 1), &pid,
-                         buffer), 2);
+    TEST_COMPARE (fscanf (out, "%u: " STRINPUT (BUFFERLEN), &pid, buffer), 2);
 
     TEST_COMPARE (pid, *target_pid_ptr);
     TEST_COMPARE (strcmp (basename (buffer), "tst-pldd"), 0);