summaryrefslogtreecommitdiff
path: root/graphics/radiance/patches/patch-src_rt_devcomm.c
blob: b0ae7bfdb1f47c9daf868efcf45d5ff7843822b5 (plain)
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
$NetBSD: patch-src_rt_devcomm.c,v 1.1 2012/12/27 00:23:21 dholland Exp $

Pass around input buffer lengths.

--- src/rt/devcomm.c~	2004-10-01 07:43:05.000000000 +0000
+++ src/rt/devcomm.c
@@ -24,7 +24,7 @@ FILE	*devin, *devout;
 int	devchild;
 
 static struct driver * final_connect(void);
-static void mygets(char	*s, FILE	*fp);
+static void mygets(char	*s, size_t, FILE	*fp);
 static void myputs(char	*s, FILE	*fp);
 static void reply_error(char	*routine);
 static void getstate(void);
@@ -223,6 +223,7 @@ comm_comout(			/* print string to comman
 static void
 comm_comin(			/* read string from command line */
 	char	*buf,
+	size_t	max,
 	char	*prompt
 )
 {
@@ -236,7 +237,7 @@ comm_comin(			/* read string from comman
 	fflush(devout);
 	if (getc(devin) != COM_COMIN)
 		reply_error("comin");
-	mygets(buf, devin);
+	mygets(buf, max, devin);
 	getstate();
 }
 
@@ -244,15 +245,20 @@ comm_comin(			/* read string from comman
 static void
 mygets(				/* get string from file (with nul) */
 	register char	*s,
-	register FILE	*fp
+	size_t max,
+	FILE *fp
 )
 {
 	register int	c;
+	size_t pos = 0;
 
-	while ((c = getc(fp)) != EOF)
-		if ((*s++ = c) == '\0')
+	while ((c = getc(fp)) != EOF) {
+		if (pos >= max - 1)
+			break;
+		if ((s[pos++] = c) == '\0')
 			return;
+	}
-	*s = '\0';
+	s[pos] = '\0';
 }