annotate lib-src/insert-data-in-exec.c @ 5887:6eca500211f4

Prototype for X509_check_host() has changed, detect this in configure.ac ChangeLog addition: 2015-04-09 Aidan Kehoe <kehoea@parhasard.net> * configure.ac: If X509_check_host() is available, check the number of arguments it takes. Don't use it if it takes any number of arguments other than five. Also don't use it if <openssl/x509v3.h> does not declare it, since if that is so there is no portable way to tell how many arguments it should take, and so we would end up smashing the stack. * configure: Regenerate. src/ChangeLog addition: 2015-04-09 Aidan Kehoe <kehoea@parhasard.net> * tls.c: #include <openssl/x509v3.h> for its prototype for X509_check_host(). * tls.c (tls_open): Pass the new fifth argument to X509_check_host().
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 09 Apr 2015 14:27:02 +0100
parents 86d33ddc7fd6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4722
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
1 /* Copies the dump file inside the xemacs executable.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
2 Copyright (C) 2003-2004 Olivier Galibert.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
3 Copyright (C) 2003 Larry McVoy.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
4
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
5 Redistribution and use in source and binary forms, with or without
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
6 modification, are permitted provided that the following conditions are met:
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
7
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
8 1. Redistributions of source code must retain the above copyright notice,
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
9 this list of conditions and the following disclaimer.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
10 2. Redistributions in binary form must reproduce the above copyright notice,
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
11 this list of conditions and the following disclaimer in the documentation
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
12 and/or other materials provided with the distribution.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
13
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
14 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
15 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LARRY
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
17 MCVOY, THE XEMACS PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
18 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
19 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
21 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
22 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
23 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
24
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
25 The views and conclusions contained in the software and documentation are those
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
26 of the authors and should not be interpreted as representing official policies,
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
27 either expressed or implied, of the XEmacs Project.
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
28
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
29 The "key" array is the work of Larry McVoy. See
dfc9fe46c294 Add BSD header to lib-src/insert-data-in-exec.c, with permission of Olivier
Jerry James <james@xemacs.org>
parents: 2502
diff changeset
30 http://lkml.org/lkml/2003/7/11/141 for more information. */
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
31
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
32 #include <stdio.h>
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
33 #include <stdlib.h>
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
34 #include <string.h>
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
35 #include <config.h>
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
36
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
37 static const unsigned char key[] = {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
38 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
39 6,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
40 1,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
41 2,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
42 3,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
43 4,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
44 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
45 3,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
46 9,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
47 62,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
48 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
49 10,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
50 4,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
51 61,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
52 255
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
53 };
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
54
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
55 int main(int argc, char **argv)
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
56 {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
57 FILE *te, *xe, *dump;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
58 unsigned char *xed, *p;
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
59 size_t size, size_dump, size1, i;
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
60 size_t max_size, offset;
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
61 OFF_T off;
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
62
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
63 char msg[65536];
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
64
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
65 if(argc != 6 && (argc != 3 || strcmp(argv[1], "-s"))) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
66 fprintf(stderr, "Usage:\n%s temacs xemacs.dmp xemacs size offset\n%s -s xemacs.dmp\n", argv[0], argv[0]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
67 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
68 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
69
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
70 if(argc == 3) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
71 sprintf(msg, "Opening %s failed", argv[2]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
72 dump = fopen(argv[2], "rb+");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
73 if(!dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
74 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
75 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
76 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
77
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
78 if(FSEEK(dump, 0, SEEK_END)) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
79 perror("fseek end dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
80 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
81 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
82
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
83 off = FTELL(dump);
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
84 if(off == -1) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
85 perror("ftell dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
86 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
87 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
88 size = (size_t)off;
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
89
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
90 printf("%zu\n", size);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
91 exit(0);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
92 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
93
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
94
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
95 max_size = strtoul(argv[4], 0, 10);
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
96 offset = strtoul(argv[5], 0, 10);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
97
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
98 sprintf(msg, "Opening %s failed", argv[1]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
99 te = fopen(argv[1], "rb");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
100 if(!te) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
101 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
102 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
103 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
104
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
105 if(FSEEK(te, 0, SEEK_END)) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
106 perror("fseek end");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
107 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
108 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
109
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
110 off = FTELL(te);
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
111 if(off == -1) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
112 perror("ftell");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
113 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
114 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
115 size = (size_t)off;
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
116
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
117 if(FSEEK(te, 0, SEEK_SET)) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
118 perror("fseek beginning");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
119 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
120 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
121
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
122 xed = malloc(size);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
123 if(!xed) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
124 perror("malloc");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
125 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
126 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
127
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
128 size1 = fread(xed, 1, size, te);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
129 if(size1 != size) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
130 if(ferror(te)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
131 perror("fread temacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
132 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
133 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
134 fprintf(stderr, "Fread returned %zu, expected %zu ?\n", size1, size);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
135 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
136 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
137
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
138 if(fclose(te)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
139 perror("fclose temacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
140 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
141 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
142
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
143 p = xed;
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
144 for(i=0; i<size-sizeof(key); i++) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
145 if(!memcmp(p, key, sizeof(key)))
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
146 goto found;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
147 p++;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
148 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
149
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
150 fprintf(stderr, "dumped_data key not found in executable.\n");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
151 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
152
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
153 found:
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
154 fprintf(stderr, "dumped_data found at offset 0x%zx, patching.\n", i);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
155
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
156 sprintf(msg, "Opening %s failed", argv[2]);
2502
261c5cd19207 [xemacs-hg @ 2005-01-26 03:40:10 by ben]
ben
parents: 2022
diff changeset
157 dump = fopen(argv[2], "rb");
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
158 if(!dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
159 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
160 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
161 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
162
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
163 if(FSEEK(dump, 0, SEEK_END)) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
164 perror("fseek end dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
165 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
166 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
167
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
168 off = FTELL(dump);
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
169 if(off == -1) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
170 perror("ftell dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
171 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
172 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
173 size_dump = (size_t)off;
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
174
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
175 if(size_dump > max_size) {
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
176 fprintf(stderr, "Dump file too big for available space (max=%zu, dump=%zu)\n", max_size, size_dump);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
177 exit(2);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
178 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
179
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
180 if(FSEEK(dump, 0, SEEK_SET)) {
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
181 perror("fseek beginning dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
182 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
183 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
184
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
185 size1 = fread(xed+i+offset, 1, size_dump, dump);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
186 if(size1 != size_dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
187 if(ferror(dump)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
188 perror("fread dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
189 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
190 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
191 fprintf(stderr, "Fread dump returned %zu, expected %zu ?\n", size1, size_dump);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
192 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
193 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
194
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
195 if(fclose(dump)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
196 perror("fclose dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
197 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
198 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
199
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
200 memset(xed+i, 0, offset);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
201
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
202 xed[i ] = size_dump;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
203 xed[i+1] = size_dump >> 8;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
204 xed[i+2] = size_dump >> 16;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
205 xed[i+3] = size_dump >> 24;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
206
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
207 fprintf(stderr, "dumped_data found at offset 0x%zx, patching.\n", i);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
208
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
209 sprintf(msg, "Opening %s failed", argv[3]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
210 xe = fopen(argv[3], "wb");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
211 if(!xe) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
212 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
213 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
214 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
215
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
216 size1 = fwrite(xed, 1, size, xe);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
217 if(size1 != size) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
218 if(ferror(xe)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
219 perror("fwrite xemacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
220 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
221 }
5727
86d33ddc7fd6 Avoid EOVERFLOW from stat() calls due to overflowing inode numbers.
Jerry James <james@xemacs.org>
parents: 4722
diff changeset
222 fprintf(stderr, "Fwrite xemacs returned %zu, expected %zu ?\n", size1, size);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
223 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
224 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
225
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
226 if(fclose(xe)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
227 perror("fclose xemacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
228 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
229 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
230
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
231 exit(0);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
232 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
233