File: trust-vsprintf-return.patch

package info (click to toggle)
gmp 2%3A6.3.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,288 kB
  • sloc: ansic: 135,128; asm: 133,235; cpp: 5,534; sh: 5,303; perl: 2,930; makefile: 809; yacc: 226; lisp: 203; lex: 95; fortran: 24
file content (71 lines) | stat: -rw-r--r-- 2,241 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From: Marco Bodrato <bodrato@mail.dm.unipi.it>
Date: Mon Mar 25 17:32:22 2024 +0100
Subject: Trust return value of {v}sprintf, and use it

Forwarded: not-needed

Patch from upstream repo: https://gmplib.org/repo/gmp/raw-rev/4ac76064639e
Related discussion:
* https://gmplib.org/list-archives/gmp-bugs/2023-December/005420.html
* https://gmplib.org/list-archives/gmp-bugs/2024-April/005472.html


# HG changeset patch
# User Marco Bodrato <bodrato@mail.dm.unipi.it>
# Date 1711384509 -3600
# Node ID 4ac76064639e5df52967ea1e15d5a8eec94c107e
# Parent  ecd302aa86e386fb709877c42956979ca7136574
printf/: Trust return value of {v}sprintf, and use it.

diff -r ecd302aa86e3 -r 4ac76064639e printf/doprntf.c
--- a/printf/doprntf.c	Mon Mar 25 17:32:22 2024 +0100
+++ b/printf/doprntf.c	Mon Mar 25 17:35:09 2024 +0100
@@ -267,8 +267,7 @@
 	 mean truncation */
       ASSERT (explen >= 0 && explen < sizeof(exponent)-1);
 #else
-      sprintf (exponent, p->expfmt, expsign, expval);
-      explen = strlen (exponent);
+      explen = sprintf (exponent, p->expfmt, expsign, expval);
       ASSERT (explen < sizeof(exponent));
 #endif
       TRACE (printf ("  expfmt %s gives %s\n", p->expfmt, exponent));
diff -r ecd302aa86e3 -r 4ac76064639e printf/repl-vsnprintf.c
--- a/printf/repl-vsnprintf.c	Mon Mar 25 17:32:22 2024 +0100
+++ b/printf/repl-vsnprintf.c	Mon Mar 25 17:35:09 2024 +0100
@@ -364,16 +364,14 @@
 
   if (total_width <= buf_size)
     {
-      vsprintf (buf, orig_fmt, orig_ap);
-      len = strlen (buf);
+      len = vsprintf (buf, orig_fmt, orig_ap);
     }
   else
     {
       char  *s;
 
       s = __GMP_ALLOCATE_FUNC_TYPE (total_width, char);
-      vsprintf (s, orig_fmt, orig_ap);
-      len = strlen (s);
+      len = vsprintf (s, orig_fmt, orig_ap);
       if (buf_size != 0)
 	{
 	  size_t  copylen = MIN (len, buf_size-1);
diff -r ecd302aa86e3 -r 4ac76064639e printf/sprintffuns.c
--- a/printf/sprintffuns.c	Mon Mar 25 17:32:22 2024 +0100
+++ b/printf/sprintffuns.c	Mon Mar 25 17:35:09 2024 +0100
@@ -53,9 +53,9 @@
 {
   char  *buf = *bufp;
   int   ret;
-  vsprintf (buf, fmt, ap);
-  ret = strlen (buf);
-  *bufp = buf + ret;
+  ret = vsprintf (buf, fmt, ap);
+  if (ret > 0)
+    *bufp = buf + ret;
   return ret;
 }