summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2014-04-16 19:54:20 +0000
committermiod <>2014-04-16 19:54:20 +0000
commitbe77aa550ef0450b00eb62880d4d98112ba86e50 (patch)
tree799ff7dd46104d5141090fe09459d15d959fc827
parent5fb0ca0ddf59f49b49200128095fb2d4a1577020 (diff)
downloadopenbsd-be77aa550ef0450b00eb62880d4d98112ba86e50.tar.gz
openbsd-be77aa550ef0450b00eb62880d4d98112ba86e50.tar.bz2
openbsd-be77aa550ef0450b00eb62880d4d98112ba86e50.zip
- Why do we hide from the OpenSSL police, dad?
- Because they're not like us, son. They use macros to wrap stdio routines, for an undocumented (OPENSSL_USE_APPLINK) use case, which only serves to obfuscate the code. ok tedu@
-rw-r--r--src/lib/libcrypto/bio/b_dump.c4
-rw-r--r--src/lib/libcrypto/bio/bio.h5
-rw-r--r--src/lib/libcrypto/bio/bio_lcl.h27
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c28
-rw-r--r--src/lib/libcrypto/bio/bss_file.c68
-rw-r--r--src/lib/libcrypto/cryptlib.h5
-rw-r--r--src/lib/libssl/src/crypto/bio/b_dump.c4
-rw-r--r--src/lib/libssl/src/crypto/bio/bio.h5
-rw-r--r--src/lib/libssl/src/crypto/bio/bio_lcl.h27
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_fd.c28
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_file.c68
-rw-r--r--src/lib/libssl/src/crypto/cryptlib.h5
12 files changed, 46 insertions, 228 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index 090cfc2b5f..ff75069df8 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -62,7 +62,7 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio_lcl.h" 65#include <openssl/bio.h>
66 66
67#define TRUNCATE 67#define TRUNCATE
68#define DUMP_WIDTH 16 68#define DUMP_WIDTH 16
@@ -149,7 +149,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
149static int 149static int
150write_fp(const void *data, size_t len, void *fp) 150write_fp(const void *data, size_t len, void *fp)
151{ 151{
152 return UP_fwrite(data, len, 1, fp); 152 return fwrite(data, len, 1, fp);
153} 153}
154 154
155int 155int
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index 9bae034daa..b64fd44b12 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -197,11 +197,6 @@ extern "C" {
197#define BIO_FLAGS_IO_SPECIAL 0x04 197#define BIO_FLAGS_IO_SPECIAL 0x04
198#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) 198#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
199#define BIO_FLAGS_SHOULD_RETRY 0x08 199#define BIO_FLAGS_SHOULD_RETRY 0x08
200#ifndef BIO_FLAGS_UPLINK
201/* "UPLINK" flag denotes file descriptors provided by application.
202 It defaults to 0, as most platforms don't require UPLINK interface. */
203#define BIO_FLAGS_UPLINK 0
204#endif
205 200
206/* Used in BIO_gethostbyname() */ 201/* Used in BIO_gethostbyname() */
207#define BIO_GHBN_CTRL_HITS 1 202#define BIO_GHBN_CTRL_HITS 1
diff --git a/src/lib/libcrypto/bio/bio_lcl.h b/src/lib/libcrypto/bio/bio_lcl.h
deleted file mode 100644
index cc89c1bf2d..0000000000
--- a/src/lib/libcrypto/bio/bio_lcl.h
+++ /dev/null
@@ -1,27 +0,0 @@
1#include <openssl/bio.h>
2
3#if BIO_FLAGS_UPLINK==0
4/* Shortcut UPLINK calls on most platforms... */
5#define UP_stdin stdin
6#define UP_stdout stdout
7#define UP_stderr stderr
8#define UP_fprintf fprintf
9#define UP_fgets fgets
10#define UP_fread fread
11#define UP_fwrite fwrite
12#undef UP_fsetmod
13#define UP_feof feof
14#define UP_fclose fclose
15
16#define UP_fopen fopen
17#define UP_fseek fseek
18#define UP_ftell ftell
19#define UP_fflush fflush
20#define UP_ferror ferror
21#define UP_fileno fileno
22#define UP_open open
23#define UP_read read
24#define UP_write write
25#define UP_lseek lseek
26#define UP_close close
27#endif
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
index c0e7f08fbb..988104e77c 100644
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ b/src/lib/libcrypto/bio/bss_fd.c
@@ -67,19 +67,7 @@
67 * BIO_s_fd here... 67 * BIO_s_fd here...
68 */ 68 */
69#else 69#else
70/* 70#include <openssl/bio.h>
71 * As for unconditional usage of "UPLINK" interface in this module.
72 * Trouble is that unlike Unix file descriptors [which are indexes
73 * in kernel-side per-process table], corresponding descriptors on
74 * platforms which require "UPLINK" interface seem to be indexes
75 * in a user-land, non-global table. Well, in fact they are indexes
76 * in stdio _iob[], and recall that _iob[] was the very reason why
77 * "UPLINK" interface was introduced in first place. But one way on
78 * another. Neither libcrypto or libssl use this BIO meaning that
79 * file descriptors can only be provided by application. Therefore
80 * "UPLINK" calls are due...
81 */
82#include "bio_lcl.h"
83 71
84static int fd_write(BIO *h, const char *buf, int num); 72static int fd_write(BIO *h, const char *buf, int num);
85static int fd_read(BIO *h, char *buf, int size); 73static int fd_read(BIO *h, char *buf, int size);
@@ -125,7 +113,7 @@ fd_new(BIO *bi)
125 bi->init = 0; 113 bi->init = 0;
126 bi->num = -1; 114 bi->num = -1;
127 bi->ptr = NULL; 115 bi->ptr = NULL;
128 bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ 116 bi->flags=0;
129 return (1); 117 return (1);
130} 118}
131 119
@@ -136,10 +124,10 @@ fd_free(BIO *a)
136 return (0); 124 return (0);
137 if (a->shutdown) { 125 if (a->shutdown) {
138 if (a->init) { 126 if (a->init) {
139 UP_close(a->num); 127 close(a->num);
140 } 128 }
141 a->init = 0; 129 a->init = 0;
142 a->flags = BIO_FLAGS_UPLINK; 130 a->flags = 0;
143 } 131 }
144 return (1); 132 return (1);
145} 133}
@@ -151,7 +139,7 @@ fd_read(BIO *b, char *out, int outl)
151 139
152 if (out != NULL) { 140 if (out != NULL) {
153 errno = 0; 141 errno = 0;
154 ret = UP_read(b->num, out, outl); 142 ret = read(b->num, out, outl);
155 BIO_clear_retry_flags(b); 143 BIO_clear_retry_flags(b);
156 if (ret <= 0) { 144 if (ret <= 0) {
157 if (BIO_fd_should_retry(ret)) 145 if (BIO_fd_should_retry(ret))
@@ -166,7 +154,7 @@ fd_write(BIO *b, const char *in, int inl)
166{ 154{
167 int ret; 155 int ret;
168 errno = 0; 156 errno = 0;
169 ret = UP_write(b->num, in, inl); 157 ret = write(b->num, in, inl);
170 BIO_clear_retry_flags(b); 158 BIO_clear_retry_flags(b);
171 if (ret <= 0) { 159 if (ret <= 0) {
172 if (BIO_fd_should_retry(ret)) 160 if (BIO_fd_should_retry(ret))
@@ -185,11 +173,11 @@ fd_ctrl(BIO *b, int cmd, long num, void *ptr)
185 case BIO_CTRL_RESET: 173 case BIO_CTRL_RESET:
186 num = 0; 174 num = 0;
187 case BIO_C_FILE_SEEK: 175 case BIO_C_FILE_SEEK:
188 ret = (long)UP_lseek(b->num, num, 0); 176 ret = (long)lseek(b->num, num, 0);
189 break; 177 break;
190 case BIO_C_FILE_TELL: 178 case BIO_C_FILE_TELL:
191 case BIO_CTRL_INFO: 179 case BIO_CTRL_INFO:
192 ret = (long)UP_lseek(b->num, 0, 1); 180 ret = (long)lseek(b->num, 0, 1);
193 break; 181 break;
194 case BIO_C_SET_FD: 182 case BIO_C_SET_FD:
195 fd_free(b); 183 fd_free(b);
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index 59e48e6659..c92c4753aa 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -86,7 +86,7 @@
86#include <stdio.h> 86#include <stdio.h>
87#include <errno.h> 87#include <errno.h>
88#include "cryptlib.h" 88#include "cryptlib.h"
89#include "bio_lcl.h" 89#include <openssl/bio.h>
90#include <openssl/err.h> 90#include <openssl/err.h>
91 91
92#if !defined(OPENSSL_NO_STDIO) 92#if !defined(OPENSSL_NO_STDIO)
@@ -134,7 +134,6 @@ BIO
134 return (NULL); 134 return (NULL);
135 } 135 }
136 136
137 BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
138 BIO_set_fp(ret, file, BIO_CLOSE); 137 BIO_set_fp(ret, file, BIO_CLOSE);
139 return (ret); 138 return (ret);
140} 139}
@@ -147,7 +146,6 @@ BIO
147 if ((ret = BIO_new(BIO_s_file())) == NULL) 146 if ((ret = BIO_new(BIO_s_file())) == NULL)
148 return (NULL); 147 return (NULL);
149 148
150 BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
151 BIO_set_fp(ret, stream, close_flag); 149 BIO_set_fp(ret, stream, close_flag);
152 return (ret); 150 return (ret);
153} 151}
@@ -164,7 +162,7 @@ file_new(BIO *bi)
164 bi->init = 0; 162 bi->init = 0;
165 bi->num = 0; 163 bi->num = 0;
166 bi->ptr = NULL; 164 bi->ptr = NULL;
167 bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ 165 bi->flags=0;
168 return (1); 166 return (1);
169} 167}
170 168
@@ -175,12 +173,9 @@ file_free(BIO *a)
175 return (0); 173 return (0);
176 if (a->shutdown) { 174 if (a->shutdown) {
177 if ((a->init) && (a->ptr != NULL)) { 175 if ((a->init) && (a->ptr != NULL)) {
178 if (a->flags&BIO_FLAGS_UPLINK) 176 fclose (a->ptr);
179 UP_fclose (a->ptr);
180 else
181 fclose (a->ptr);
182 a->ptr = NULL; 177 a->ptr = NULL;
183 a->flags = BIO_FLAGS_UPLINK; 178 a->flags = 0;
184 } 179 }
185 a->init = 0; 180 a->init = 0;
186 } 181 }
@@ -193,12 +188,8 @@ file_read(BIO *b, char *out, int outl)
193 int ret = 0; 188 int ret = 0;
194 189
195 if (b->init && (out != NULL)) { 190 if (b->init && (out != NULL)) {
196 if (b->flags&BIO_FLAGS_UPLINK) 191 ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
197 ret = UP_fread(out, 1,(int)outl, b->ptr); 192 if (ret == 0 && ferror((FILE *)b->ptr)) {
198 else
199 ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
200 if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ?
201 UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) {
202 SYSerr(SYS_F_FREAD, errno); 193 SYSerr(SYS_F_FREAD, errno);
203 BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); 194 BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
204 ret = -1; 195 ret = -1;
@@ -213,10 +204,7 @@ file_write(BIO *b, const char *in, int inl)
213 int ret = 0; 204 int ret = 0;
214 205
215 if (b->init && (in != NULL)) { 206 if (b->init && (in != NULL)) {
216 if (b->flags&BIO_FLAGS_UPLINK) 207 ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
217 ret = UP_fwrite(in,(int)inl, 1, b->ptr);
218 else
219 ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
220 if (ret) 208 if (ret)
221 ret = inl; 209 ret = inl;
222 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ 210 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
@@ -238,41 +226,20 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
238 switch (cmd) { 226 switch (cmd) {
239 case BIO_C_FILE_SEEK: 227 case BIO_C_FILE_SEEK:
240 case BIO_CTRL_RESET: 228 case BIO_CTRL_RESET:
241 if (b->flags&BIO_FLAGS_UPLINK) 229 ret = (long)fseek(fp, num, 0);
242 ret = (long)UP_fseek(b->ptr, num, 0);
243 else
244 ret = (long)fseek(fp, num, 0);
245 break; 230 break;
246 case BIO_CTRL_EOF: 231 case BIO_CTRL_EOF:
247 if (b->flags&BIO_FLAGS_UPLINK) 232 ret = (long)feof(fp);
248 ret = (long)UP_feof(fp);
249 else
250 ret = (long)feof(fp);
251 break; 233 break;
252 case BIO_C_FILE_TELL: 234 case BIO_C_FILE_TELL:
253 case BIO_CTRL_INFO: 235 case BIO_CTRL_INFO:
254 if (b->flags&BIO_FLAGS_UPLINK) 236 ret = ftell(fp);
255 ret = UP_ftell(b->ptr);
256 else
257 ret = ftell(fp);
258 break; 237 break;
259 case BIO_C_SET_FILE_PTR: 238 case BIO_C_SET_FILE_PTR:
260 file_free(b); 239 file_free(b);
261 b->shutdown = (int)num&BIO_CLOSE; 240 b->shutdown = (int)num&BIO_CLOSE;
262 b->ptr = ptr; 241 b->ptr = ptr;
263 b->init = 1; 242 b->init = 1;
264#if BIO_FLAGS_UPLINK!=0
265#if defined(_IOB_ENTRIES)
266 /* Safety net to catch purely internal BIO_set_fp calls */
267 if ((size_t)ptr >= (size_t)stdin &&
268 (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
269 BIO_clear_flags(b, BIO_FLAGS_UPLINK);
270#endif
271#endif
272#ifdef UP_fsetmod
273 if (b->flags&BIO_FLAGS_UPLINK)
274 UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b'));
275#endif
276 break; 243 break;
277 case BIO_C_SET_FILENAME: 244 case BIO_C_SET_FILENAME:
278 file_free(b); 245 file_free(b);
@@ -302,7 +269,6 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
302 } 269 }
303 b->ptr = fp; 270 b->ptr = fp;
304 b->init = 1; 271 b->init = 1;
305 BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
306 break; 272 break;
307 case BIO_C_GET_FILE_PTR: 273 case BIO_C_GET_FILE_PTR:
308 /* the ptr parameter is actually a FILE ** in this case. */ 274 /* the ptr parameter is actually a FILE ** in this case. */
@@ -318,10 +284,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
318 b->shutdown = (int)num; 284 b->shutdown = (int)num;
319 break; 285 break;
320 case BIO_CTRL_FLUSH: 286 case BIO_CTRL_FLUSH:
321 if (b->flags&BIO_FLAGS_UPLINK) 287 fflush((FILE *)b->ptr);
322 UP_fflush(b->ptr);
323 else
324 fflush((FILE *)b->ptr);
325 break; 288 break;
326 case BIO_CTRL_DUP: 289 case BIO_CTRL_DUP:
327 ret = 1; 290 ret = 1;
@@ -344,13 +307,8 @@ file_gets(BIO *bp, char *buf, int size)
344 int ret = 0; 307 int ret = 0;
345 308
346 buf[0] = '\0'; 309 buf[0] = '\0';
347 if (bp->flags&BIO_FLAGS_UPLINK) { 310 if (!fgets(buf, size,(FILE *)bp->ptr))
348 if (!UP_fgets(buf, size, bp->ptr)) 311 goto err;
349 goto err;
350 } else {
351 if (!fgets(buf, size,(FILE *)bp->ptr))
352 goto err;
353 }
354 if (buf[0] != '\0') 312 if (buf[0] != '\0')
355 ret = strlen(buf); 313 ret = strlen(buf);
356err: 314err:
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h
index d1d7cfe80a..b3342232c7 100644
--- a/src/lib/libcrypto/cryptlib.h
+++ b/src/lib/libcrypto/cryptlib.h
@@ -65,11 +65,6 @@
65 65
66#include "e_os.h" 66#include "e_os.h"
67 67
68#ifdef OPENSSL_USE_APPLINK
69#define BIO_FLAGS_UPLINK 0x8000
70#include "ms/uplink.h"
71#endif
72
73#include <openssl/crypto.h> 68#include <openssl/crypto.h>
74#include <openssl/buffer.h> 69#include <openssl/buffer.h>
75#include <openssl/bio.h> 70#include <openssl/bio.h>
diff --git a/src/lib/libssl/src/crypto/bio/b_dump.c b/src/lib/libssl/src/crypto/bio/b_dump.c
index 090cfc2b5f..ff75069df8 100644
--- a/src/lib/libssl/src/crypto/bio/b_dump.c
+++ b/src/lib/libssl/src/crypto/bio/b_dump.c
@@ -62,7 +62,7 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio_lcl.h" 65#include <openssl/bio.h>
66 66
67#define TRUNCATE 67#define TRUNCATE
68#define DUMP_WIDTH 16 68#define DUMP_WIDTH 16
@@ -149,7 +149,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
149static int 149static int
150write_fp(const void *data, size_t len, void *fp) 150write_fp(const void *data, size_t len, void *fp)
151{ 151{
152 return UP_fwrite(data, len, 1, fp); 152 return fwrite(data, len, 1, fp);
153} 153}
154 154
155int 155int
diff --git a/src/lib/libssl/src/crypto/bio/bio.h b/src/lib/libssl/src/crypto/bio/bio.h
index 9bae034daa..b64fd44b12 100644
--- a/src/lib/libssl/src/crypto/bio/bio.h
+++ b/src/lib/libssl/src/crypto/bio/bio.h
@@ -197,11 +197,6 @@ extern "C" {
197#define BIO_FLAGS_IO_SPECIAL 0x04 197#define BIO_FLAGS_IO_SPECIAL 0x04
198#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) 198#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
199#define BIO_FLAGS_SHOULD_RETRY 0x08 199#define BIO_FLAGS_SHOULD_RETRY 0x08
200#ifndef BIO_FLAGS_UPLINK
201/* "UPLINK" flag denotes file descriptors provided by application.
202 It defaults to 0, as most platforms don't require UPLINK interface. */
203#define BIO_FLAGS_UPLINK 0
204#endif
205 200
206/* Used in BIO_gethostbyname() */ 201/* Used in BIO_gethostbyname() */
207#define BIO_GHBN_CTRL_HITS 1 202#define BIO_GHBN_CTRL_HITS 1
diff --git a/src/lib/libssl/src/crypto/bio/bio_lcl.h b/src/lib/libssl/src/crypto/bio/bio_lcl.h
deleted file mode 100644
index cc89c1bf2d..0000000000
--- a/src/lib/libssl/src/crypto/bio/bio_lcl.h
+++ /dev/null
@@ -1,27 +0,0 @@
1#include <openssl/bio.h>
2
3#if BIO_FLAGS_UPLINK==0
4/* Shortcut UPLINK calls on most platforms... */
5#define UP_stdin stdin
6#define UP_stdout stdout
7#define UP_stderr stderr
8#define UP_fprintf fprintf
9#define UP_fgets fgets
10#define UP_fread fread
11#define UP_fwrite fwrite
12#undef UP_fsetmod
13#define UP_feof feof
14#define UP_fclose fclose
15
16#define UP_fopen fopen
17#define UP_fseek fseek
18#define UP_ftell ftell
19#define UP_fflush fflush
20#define UP_ferror ferror
21#define UP_fileno fileno
22#define UP_open open
23#define UP_read read
24#define UP_write write
25#define UP_lseek lseek
26#define UP_close close
27#endif
diff --git a/src/lib/libssl/src/crypto/bio/bss_fd.c b/src/lib/libssl/src/crypto/bio/bss_fd.c
index c0e7f08fbb..988104e77c 100644
--- a/src/lib/libssl/src/crypto/bio/bss_fd.c
+++ b/src/lib/libssl/src/crypto/bio/bss_fd.c
@@ -67,19 +67,7 @@
67 * BIO_s_fd here... 67 * BIO_s_fd here...
68 */ 68 */
69#else 69#else
70/* 70#include <openssl/bio.h>
71 * As for unconditional usage of "UPLINK" interface in this module.
72 * Trouble is that unlike Unix file descriptors [which are indexes
73 * in kernel-side per-process table], corresponding descriptors on
74 * platforms which require "UPLINK" interface seem to be indexes
75 * in a user-land, non-global table. Well, in fact they are indexes
76 * in stdio _iob[], and recall that _iob[] was the very reason why
77 * "UPLINK" interface was introduced in first place. But one way on
78 * another. Neither libcrypto or libssl use this BIO meaning that
79 * file descriptors can only be provided by application. Therefore
80 * "UPLINK" calls are due...
81 */
82#include "bio_lcl.h"
83 71
84static int fd_write(BIO *h, const char *buf, int num); 72static int fd_write(BIO *h, const char *buf, int num);
85static int fd_read(BIO *h, char *buf, int size); 73static int fd_read(BIO *h, char *buf, int size);
@@ -125,7 +113,7 @@ fd_new(BIO *bi)
125 bi->init = 0; 113 bi->init = 0;
126 bi->num = -1; 114 bi->num = -1;
127 bi->ptr = NULL; 115 bi->ptr = NULL;
128 bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ 116 bi->flags=0;
129 return (1); 117 return (1);
130} 118}
131 119
@@ -136,10 +124,10 @@ fd_free(BIO *a)
136 return (0); 124 return (0);
137 if (a->shutdown) { 125 if (a->shutdown) {
138 if (a->init) { 126 if (a->init) {
139 UP_close(a->num); 127 close(a->num);
140 } 128 }
141 a->init = 0; 129 a->init = 0;
142 a->flags = BIO_FLAGS_UPLINK; 130 a->flags = 0;
143 } 131 }
144 return (1); 132 return (1);
145} 133}
@@ -151,7 +139,7 @@ fd_read(BIO *b, char *out, int outl)
151 139
152 if (out != NULL) { 140 if (out != NULL) {
153 errno = 0; 141 errno = 0;
154 ret = UP_read(b->num, out, outl); 142 ret = read(b->num, out, outl);
155 BIO_clear_retry_flags(b); 143 BIO_clear_retry_flags(b);
156 if (ret <= 0) { 144 if (ret <= 0) {
157 if (BIO_fd_should_retry(ret)) 145 if (BIO_fd_should_retry(ret))
@@ -166,7 +154,7 @@ fd_write(BIO *b, const char *in, int inl)
166{ 154{
167 int ret; 155 int ret;
168 errno = 0; 156 errno = 0;
169 ret = UP_write(b->num, in, inl); 157 ret = write(b->num, in, inl);
170 BIO_clear_retry_flags(b); 158 BIO_clear_retry_flags(b);
171 if (ret <= 0) { 159 if (ret <= 0) {
172 if (BIO_fd_should_retry(ret)) 160 if (BIO_fd_should_retry(ret))
@@ -185,11 +173,11 @@ fd_ctrl(BIO *b, int cmd, long num, void *ptr)
185 case BIO_CTRL_RESET: 173 case BIO_CTRL_RESET:
186 num = 0; 174 num = 0;
187 case BIO_C_FILE_SEEK: 175 case BIO_C_FILE_SEEK:
188 ret = (long)UP_lseek(b->num, num, 0); 176 ret = (long)lseek(b->num, num, 0);
189 break; 177 break;
190 case BIO_C_FILE_TELL: 178 case BIO_C_FILE_TELL:
191 case BIO_CTRL_INFO: 179 case BIO_CTRL_INFO:
192 ret = (long)UP_lseek(b->num, 0, 1); 180 ret = (long)lseek(b->num, 0, 1);
193 break; 181 break;
194 case BIO_C_SET_FD: 182 case BIO_C_SET_FD:
195 fd_free(b); 183 fd_free(b);
diff --git a/src/lib/libssl/src/crypto/bio/bss_file.c b/src/lib/libssl/src/crypto/bio/bss_file.c
index 59e48e6659..c92c4753aa 100644
--- a/src/lib/libssl/src/crypto/bio/bss_file.c
+++ b/src/lib/libssl/src/crypto/bio/bss_file.c
@@ -86,7 +86,7 @@
86#include <stdio.h> 86#include <stdio.h>
87#include <errno.h> 87#include <errno.h>
88#include "cryptlib.h" 88#include "cryptlib.h"
89#include "bio_lcl.h" 89#include <openssl/bio.h>
90#include <openssl/err.h> 90#include <openssl/err.h>
91 91
92#if !defined(OPENSSL_NO_STDIO) 92#if !defined(OPENSSL_NO_STDIO)
@@ -134,7 +134,6 @@ BIO
134 return (NULL); 134 return (NULL);
135 } 135 }
136 136
137 BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
138 BIO_set_fp(ret, file, BIO_CLOSE); 137 BIO_set_fp(ret, file, BIO_CLOSE);
139 return (ret); 138 return (ret);
140} 139}
@@ -147,7 +146,6 @@ BIO
147 if ((ret = BIO_new(BIO_s_file())) == NULL) 146 if ((ret = BIO_new(BIO_s_file())) == NULL)
148 return (NULL); 147 return (NULL);
149 148
150 BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
151 BIO_set_fp(ret, stream, close_flag); 149 BIO_set_fp(ret, stream, close_flag);
152 return (ret); 150 return (ret);
153} 151}
@@ -164,7 +162,7 @@ file_new(BIO *bi)
164 bi->init = 0; 162 bi->init = 0;
165 bi->num = 0; 163 bi->num = 0;
166 bi->ptr = NULL; 164 bi->ptr = NULL;
167 bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ 165 bi->flags=0;
168 return (1); 166 return (1);
169} 167}
170 168
@@ -175,12 +173,9 @@ file_free(BIO *a)
175 return (0); 173 return (0);
176 if (a->shutdown) { 174 if (a->shutdown) {
177 if ((a->init) && (a->ptr != NULL)) { 175 if ((a->init) && (a->ptr != NULL)) {
178 if (a->flags&BIO_FLAGS_UPLINK) 176 fclose (a->ptr);
179 UP_fclose (a->ptr);
180 else
181 fclose (a->ptr);
182 a->ptr = NULL; 177 a->ptr = NULL;
183 a->flags = BIO_FLAGS_UPLINK; 178 a->flags = 0;
184 } 179 }
185 a->init = 0; 180 a->init = 0;
186 } 181 }
@@ -193,12 +188,8 @@ file_read(BIO *b, char *out, int outl)
193 int ret = 0; 188 int ret = 0;
194 189
195 if (b->init && (out != NULL)) { 190 if (b->init && (out != NULL)) {
196 if (b->flags&BIO_FLAGS_UPLINK) 191 ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
197 ret = UP_fread(out, 1,(int)outl, b->ptr); 192 if (ret == 0 && ferror((FILE *)b->ptr)) {
198 else
199 ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
200 if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ?
201 UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) {
202 SYSerr(SYS_F_FREAD, errno); 193 SYSerr(SYS_F_FREAD, errno);
203 BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); 194 BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
204 ret = -1; 195 ret = -1;
@@ -213,10 +204,7 @@ file_write(BIO *b, const char *in, int inl)
213 int ret = 0; 204 int ret = 0;
214 205
215 if (b->init && (in != NULL)) { 206 if (b->init && (in != NULL)) {
216 if (b->flags&BIO_FLAGS_UPLINK) 207 ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
217 ret = UP_fwrite(in,(int)inl, 1, b->ptr);
218 else
219 ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
220 if (ret) 208 if (ret)
221 ret = inl; 209 ret = inl;
222 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ 210 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
@@ -238,41 +226,20 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
238 switch (cmd) { 226 switch (cmd) {
239 case BIO_C_FILE_SEEK: 227 case BIO_C_FILE_SEEK:
240 case BIO_CTRL_RESET: 228 case BIO_CTRL_RESET:
241 if (b->flags&BIO_FLAGS_UPLINK) 229 ret = (long)fseek(fp, num, 0);
242 ret = (long)UP_fseek(b->ptr, num, 0);
243 else
244 ret = (long)fseek(fp, num, 0);
245 break; 230 break;
246 case BIO_CTRL_EOF: 231 case BIO_CTRL_EOF:
247 if (b->flags&BIO_FLAGS_UPLINK) 232 ret = (long)feof(fp);
248 ret = (long)UP_feof(fp);
249 else
250 ret = (long)feof(fp);
251 break; 233 break;
252 case BIO_C_FILE_TELL: 234 case BIO_C_FILE_TELL:
253 case BIO_CTRL_INFO: 235 case BIO_CTRL_INFO:
254 if (b->flags&BIO_FLAGS_UPLINK) 236 ret = ftell(fp);
255 ret = UP_ftell(b->ptr);
256 else
257 ret = ftell(fp);
258 break; 237 break;
259 case BIO_C_SET_FILE_PTR: 238 case BIO_C_SET_FILE_PTR:
260 file_free(b); 239 file_free(b);
261 b->shutdown = (int)num&BIO_CLOSE; 240 b->shutdown = (int)num&BIO_CLOSE;
262 b->ptr = ptr; 241 b->ptr = ptr;
263 b->init = 1; 242 b->init = 1;
264#if BIO_FLAGS_UPLINK!=0
265#if defined(_IOB_ENTRIES)
266 /* Safety net to catch purely internal BIO_set_fp calls */
267 if ((size_t)ptr >= (size_t)stdin &&
268 (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
269 BIO_clear_flags(b, BIO_FLAGS_UPLINK);
270#endif
271#endif
272#ifdef UP_fsetmod
273 if (b->flags&BIO_FLAGS_UPLINK)
274 UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b'));
275#endif
276 break; 243 break;
277 case BIO_C_SET_FILENAME: 244 case BIO_C_SET_FILENAME:
278 file_free(b); 245 file_free(b);
@@ -302,7 +269,6 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
302 } 269 }
303 b->ptr = fp; 270 b->ptr = fp;
304 b->init = 1; 271 b->init = 1;
305 BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
306 break; 272 break;
307 case BIO_C_GET_FILE_PTR: 273 case BIO_C_GET_FILE_PTR:
308 /* the ptr parameter is actually a FILE ** in this case. */ 274 /* the ptr parameter is actually a FILE ** in this case. */
@@ -318,10 +284,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
318 b->shutdown = (int)num; 284 b->shutdown = (int)num;
319 break; 285 break;
320 case BIO_CTRL_FLUSH: 286 case BIO_CTRL_FLUSH:
321 if (b->flags&BIO_FLAGS_UPLINK) 287 fflush((FILE *)b->ptr);
322 UP_fflush(b->ptr);
323 else
324 fflush((FILE *)b->ptr);
325 break; 288 break;
326 case BIO_CTRL_DUP: 289 case BIO_CTRL_DUP:
327 ret = 1; 290 ret = 1;
@@ -344,13 +307,8 @@ file_gets(BIO *bp, char *buf, int size)
344 int ret = 0; 307 int ret = 0;
345 308
346 buf[0] = '\0'; 309 buf[0] = '\0';
347 if (bp->flags&BIO_FLAGS_UPLINK) { 310 if (!fgets(buf, size,(FILE *)bp->ptr))
348 if (!UP_fgets(buf, size, bp->ptr)) 311 goto err;
349 goto err;
350 } else {
351 if (!fgets(buf, size,(FILE *)bp->ptr))
352 goto err;
353 }
354 if (buf[0] != '\0') 312 if (buf[0] != '\0')
355 ret = strlen(buf); 313 ret = strlen(buf);
356err: 314err:
diff --git a/src/lib/libssl/src/crypto/cryptlib.h b/src/lib/libssl/src/crypto/cryptlib.h
index d1d7cfe80a..b3342232c7 100644
--- a/src/lib/libssl/src/crypto/cryptlib.h
+++ b/src/lib/libssl/src/crypto/cryptlib.h
@@ -65,11 +65,6 @@
65 65
66#include "e_os.h" 66#include "e_os.h"
67 67
68#ifdef OPENSSL_USE_APPLINK
69#define BIO_FLAGS_UPLINK 0x8000
70#include "ms/uplink.h"
71#endif
72
73#include <openssl/crypto.h> 68#include <openssl/crypto.h>
74#include <openssl/buffer.h> 69#include <openssl/buffer.h>
75#include <openssl/bio.h> 70#include <openssl/bio.h>