File: strcpy.patch

package info (click to toggle)
coils 2002-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 240 kB
  • sloc: ansic: 933; perl: 778; makefile: 23; sh: 11
file content (60 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download | duplicates (5)
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
Author: Steffen Moeller <moeller@debian.org>
LastChanged: Sat, 12 Jun 2010 16:03:22 +0200
Description: strcpy -> strncpy fixes

--- a/ncoils.c
+++ b/ncoils.c
@@ -35,7 +35,8 @@ main(int argc, char *argv[]) {
 	int mode;
 	int min_seg;
 
-	char heptfile[1000];
+#define HEPTFILELENGTH 1000
+	char heptfile[HEPTFILELENGTH];
 	char *buff;
 	static char *env;
 	char *seq,*title,*ident;
@@ -56,10 +57,12 @@ main(int argc, char *argv[]) {
 
 	if((env=getenv("COILSDIR"))==NULL) {
 		fprintf(stderr,"error: environment variable COILSDIR must be set\n");
+		fprintf(stderr,"       Assuming /usr/share/ncoils\n");
+		env=strdup("/usr/share/ncoils"); // a little leak, tolerated as singleton
 		exit(-1);
 	}
 
-	strcpy(&heptfile[0],env);
+	strncpy(&heptfile[0],env,HEPTFILELENGTH-1-8); // -1 for terminal 0, 8 for "/new.mat"
 	strcpy(&heptfile[strlen(heptfile)],"/new.mat");
 
 
@@ -67,7 +70,7 @@ main(int argc, char *argv[]) {
            if(argv[i][0]!='-') exit_error();
 	   if(strcmp(&argv[i][1],"m")==0) {
              if((i+1)>=argc) exit_error();
-             strcpy(&heptfile[0],argv[i+1]);
+             strncpy(&heptfile[0],argv[i+1],HEPTFILELENGTH-1);
              i++;
 	   } else if(strcmp(&argv[i][1],"win")==0) {
              if((i+1)>=argc) exit_error();
@@ -159,6 +162,10 @@ main(int argc, char *argv[]) {
 		} else {
 /*			printf("Adding |%s| to |%s| = \n",buff,seq);  */
 			seq=(char*)realloc(seq,(seqlen+strlen(buff)+1)*sizeof(char));
+			if (NULL == seq) {
+				fprintf(stderr,"Could not allocate memory.\n");
+				exit(-1);
+			}
 		        strcpy(&seq[seqlen],buff); 
                         seqlen=strlen(seq);
 /*			printf("       |%s|\n",seq);  */
--- a/ncoils.h
+++ b/ncoils.h
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <string.h>
 
 #define AAs "A_CDEFGHI_KLMN_PQRST_VW_Y_"
 #define PI  3.1415