Line 0
Link Here
|
|
|
1 |
--- src/file.c.orig Mon Dec 2 21:03:36 2002 |
2 |
+++ src/file.c Mon Dec 2 21:33:40 2002 |
3 |
@@ -244,9 +244,10 @@ |
4 |
unsigned short ciphertext[4]; |
5 |
int val=0; |
6 |
unsigned char key[128]; |
7 |
+ off_t filesize = LOAD_BUFFER_LENGTH; |
8 |
|
9 |
/* first we should check the file permissions */ |
10 |
- if (file_exists(filename)) { |
11 |
+ if ( (filesize = file_exists(filename)) > 0) { |
12 |
val = check_file(filename); |
13 |
if (val != 1) { |
14 |
return val; |
15 |
@@ -261,7 +262,15 @@ |
16 |
return 0; |
17 |
} |
18 |
|
19 |
- buffer = malloc(LOAD_BUFFER_LENGTH); |
20 |
+ filesize = filesize >= LOAD_BUFFER_LENGTH ? filesize : LOAD_BUFFER_LENGTH; |
21 |
+ buffer = malloc((size_t) filesize); |
22 |
+ if (buffer == NULL) { |
23 |
+#ifdef DEBUG |
24 |
+ fprintf(stderr, "load_init: failed to allocate buffer of size %ld\n", filesize); |
25 |
+#endif |
26 |
+ return 0; |
27 |
+ } |
28 |
+ |
29 |
#ifdef DEBUGload |
30 |
fprintf(stderr, "load_init, password=\"%s\"\n", password); |
31 |
#endif |
32 |
@@ -440,7 +449,7 @@ |
33 |
} |
34 |
|
35 |
|
36 |
-int |
37 |
+off_t |
38 |
file_exists (char *tfile) |
39 |
{ |
40 |
struct stat naamstat; |
41 |
@@ -455,8 +464,8 @@ |
42 |
else |
43 |
{ |
44 |
#ifdef DEBUG |
45 |
- fprintf (stderr, "file_exists, %s DOES exist\n", tfile); |
46 |
+ fprintf (stderr, "file_exists, %s DOES exist, size is %ld\n", tfile, naamstat.st_size); |
47 |
#endif |
48 |
- return (1); |
49 |
+ return (naamstat.st_size); |
50 |
} |
51 |
} |