File: 13_fix_segfault.patch

package info (click to toggle)
splint 1%3A3.1.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,004 kB
  • sloc: ansic: 150,869; yacc: 3,465; sh: 3,034; makefile: 2,158; lex: 412
file content (44 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download | duplicates (3)
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
From: Carlos Maddela <e7appew@gmail.com>
Date: Wed, 22 Mar 2017 08:52:50 +1100
Subject: Fix segmentation fault.

Description: Fix segmentation fault.
Author: Carlos Maddela <e7appew@gmail.com>
Bug-Debian: https://bugs.debian.org/775917
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
---
 src/exprNode.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/exprNode.c b/src/exprNode.c
index 6ad9ea6..b11b91c 100644
--- a/src/exprNode.c
+++ b/src/exprNode.c
@@ -862,11 +862,23 @@ exprNode_wideStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
 /*@only@*/ exprNode
 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
 {
-  size_t len = size_fromInt (size_toInt (cstring_length (t)) - 2);
+  size_t len = cstring_length (t);
   char *ts = cstring_toCharsSafe (t);
-  char *s = cstring_toCharsSafe (cstring_create (len + 1));
+  char *s;
+
+  if (len >= 2)
+    {
+      len = size_fromInt (size_toInt (len) - 2);
+      llassert (*ts == '\"' && *(ts + len + 1) == '\"');
+    }
+  else if (len == 1)
+    {
+      len = 0;
+      llassert (*ts == '\"');
+    }
+
+  s = cstring_toCharsSafe (cstring_create (len + 1));
 
-  llassert (*ts == '\"' && *(ts + len + 1) == '\"');
   strncpy (s, ts+1, len);
   *(s + len) = '\0';
   cstring_free (t);