File: 01-fix-seg-fault.patch

package info (click to toggle)
ascd 0.13.2-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,596 kB
  • sloc: ansic: 14,363; sh: 182; makefile: 37
file content (31 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download
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
Author: Nathan Rutman <nathan@gordian.com>
Last-update: 2025-11-02
Description: prevent buffer overrun

--- a/ascd/faktory.c
+++ b/ascd/faktory.c
@@ -56,13 +56,19 @@
 int fak_parse_line(char *ligne, char *key, char *arguments)
 {
     unsigned int pos = 0;
+    unsigned int len = strlen(ligne);
 
-    if ((strlen(ligne) > 0) && (ligne[0] != '#')) {
-	while ((ligne[pos] != ' ') && (ligne[pos] != 9)) pos++;
+    if ((len > 0) && (ligne[0] != '#')) {
+	while ((ligne[pos] != ' ') && (ligne[pos] != 9) && (pos < len))
+	    pos++;
 	tes_sncpy(key, ligne, pos);
-	while (((ligne[pos] == ' ') || (ligne[pos] == 9)) && (pos < strlen(ligne))) pos++;
-	if (pos < strlen(ligne)) strcpy(arguments, ligne + pos);
-	else strcpy(arguments, "");
+	while (((ligne[pos] == ' ') || (ligne[pos] == 9))
+	       && (pos < len))
+	    pos++;
+	if (pos < len)
+	    strcpy(arguments, ligne + pos);
+	else
+	    strcpy(arguments, "");
 	if (debug > 2) fprintf(stderr,"++ input: [%s]\n   key:   [%s]\n   args:  [%s]\n", ligne, key, arguments);
 	return TRUE;
     } else {