1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-04 20:38:50 +01:00

Fixed possible endless loop

This commit is contained in:
Stefan Bellon 2001-08-21 18:05:23 +00:00
parent 98a8843e28
commit fa3e86043f
2 changed files with 67 additions and 47 deletions

View File

@ -1,11 +1,15 @@
2001-08-21 Stefan Bellon <sbellon@sbellon.de>
* riscos.c [__riscos__] (close_fds): Fixed possible endless loop.
2001-08-20 Werner Koch <wk@gnupg.org>
Applied patches from Stefan Bellon <sbellon@sbellon.de> to support
the RISCOS. Nearly all of these patches are identified by the
RISC OS. Nearly all of these patches are identified by the
__riscos__ macro.
* secmem.c [__riscos__]: Disabled secure memory stuff.
* dotlock.c, ttyio.c [__riscos__]: Adapted for RISCOS
* fileutil.c, iobuf.c: Adapted for RISCOS; mainly replaced
* dotlock.c, ttyio.c [__riscos__]: Adapted for RISC OS
* fileutil.c, iobuf.c: Adapted for RISC OS; mainly replaced
hardcoded path separators with EXTSEP_S like macros.
* http.c (send_request): Use macros for the env-var name.
* logger.c [__riscos__]: Do an fflush at the end of each log

View File

@ -37,7 +37,6 @@
#include <sys/unix.h>
#undef __UNIXLIB_INTERNALS
/* RISC OS file open descriptor control list */
struct fds_item {
@ -45,6 +44,7 @@ struct fds_item {
struct fds_item *next;
};
static struct fds_item *fds_list = NULL;
static int initialized = 0;
/* RISC OS functions */
@ -100,13 +100,13 @@ riscos_fopen(const char *filename, const char *mode)
r.r[0] = 17;
r.r[1] = (int) filename;
if( e =_kernel_swi(OS_File, &r, &r) )
log_fatal("can't retrieve object information for %s\n", filename);
if( r.r[0] == 2) {
if (e =_kernel_swi(OS_File, &r, &r))
log_fatal("Can't retrieve object information for %s\n", filename);
if (r.r[0] == 2) {
errno = EISDIR;
return NULL;
}
if( r.r[0] == 3) {
if (r.r[0] == 3) {
/* setting file to to non-image file, after fopening, restore */
filetype = (r.r[2] >> 8) & 0xfff;
set_filetype(filename, 0xfff);
@ -128,9 +128,9 @@ riscos_open(const char *filename, int oflag, ...)
r.r[0] = 17;
r.r[1] = (int) filename;
if( e =_kernel_swi(OS_File, &r, &r) )
log_fatal("can't retrieve object information for %s\n", filename);
if( r.r[0] == 2) {
if (e =_kernel_swi(OS_File, &r, &r))
log_fatal("Can't retrieve object information for %s\n", filename);
if (r.r[0] == 2) {
errno = EISDIR;
return NULL;
}
@ -139,8 +139,8 @@ riscos_open(const char *filename, int oflag, ...)
mode = va_arg(ap, int);
va_end(ap);
if( r.r[0] == 3) {
/* setting file to to non-image file, after fopening, restore */
if (r.r[0] == 3) {
/* setting file to to non-image file, after opening, restore */
filetype = (r.r[2] >> 8) & 0xfff;
set_filetype(filename, 0xfff);
if (!mode)
@ -171,7 +171,7 @@ riscos_fstat(int fildes, struct stat *buf)
r.r[2] = 0;
r.r[5] = 0;
if (e = _kernel_swi(OS_Args, &r, &r))
log_fatal("can't convert from file handle to name\n");
log_fatal("Can't convert from file handle to name\n");
filename = m_alloc(1 - r.r[5]);
@ -180,18 +180,18 @@ riscos_fstat(int fildes, struct stat *buf)
r.r[2] = (int) filename;
r.r[5] = 1-r.r[5];
if (e = _kernel_swi(OS_Args, &r, &r))
log_fatal("can't convert from file handle to name\n");
log_fatal("Can't convert from file handle to name\n");
r.r[0] = 17;
r.r[1] = (int) filename;
if( e =_kernel_swi(OS_File, &r, &r) )
log_fatal("can't retrieve object information for %s\n", filename);
if( r.r[0] == 2) {
if (e =_kernel_swi(OS_File, &r, &r))
log_fatal("Can't retrieve object information for %s\n", filename);
if (r.r[0] == 2) {
errno = EISDIR;
return NULL;
}
if( r.r[0] == 3) {
/* setting file to to non-image file, after fopening, restore */
if (r.r[0] == 3) {
/* setting file to to non-image file, after fstating, restore */
filetype = (r.r[2] >> 8) & 0xfff;
set_filetype(filename, 0xfff);
rc = fstat(fildes, buf);
@ -205,22 +205,38 @@ riscos_fstat(int fildes, struct stat *buf)
return rc;
}
#ifdef DEBUG
void
dump_fdlist(void)
{
struct fds_item *iter = fds_list;
printf("list of open file descriptors:\n");
while (iter) {
printf(" %i\n", iter->fd);
iter = iter->next;
}
}
#endif /* DEBUG */
int
fdopenfile(const char *filename, const int allow_write)
{
struct fds_item *h;
static int initialized;
int fd = open(filename, allow_write ? O_CREAT | O_RDWR : O_RDONLY);
if( fd == -1 )
log_fatal("can't open file %s\n", filename);
int fd;
if (allow_write)
fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
else
fd = open(filename, O_RDONLY);
if (fd == -1)
log_error("can't open file %s: %i, %s\n", filename, errno, strerror(errno));
if( !initialized ) {
atexit( close_fds );
if (!initialized) {
atexit (close_fds);
initialized = 1;
}
h = fds_list;
fds_list = (struct fds_item *) m_alloc( sizeof( struct fds_item ) );
fds_list = (struct fds_item *) m_alloc(sizeof(struct fds_item));
fds_list->fd = fd;
fds_list->next = h;
@ -231,15 +247,15 @@ void
close_fds(void)
{
FILE *fp;
struct fds_item *h2, *h1 = fds_list;
while( h1 ) {
h2 = h1->next;
fp = fdopen (h2->fd, "a");
struct fds_item *h = fds_list;
while( fds_list ) {
h = fds_list->next;
fp = fdopen (fds_list->fd, "a");
if (fp)
fflush (fp);
close( h2->fd );
m_free( h1 );
h1 = h2;
fflush(fp);
close(fds_list->fd);
m_free(fds_list);
fds_list = h;
}
}
@ -280,7 +296,7 @@ gstrans(const char *old)
size += 256;
tmp = (char *) m_realloc(buf, size);
if (!tmp)
log_fatal("can't claim memory for OS_GSTrans buffer!\n");
log_fatal("Can't claim memory for OS_GSTrans buffer!\n");
buf = tmp;
}
} while (c);
@ -288,7 +304,7 @@ gstrans(const char *old)
buf[r.r[2]] = '\0';
tmp = (char *) m_realloc(buf, r.r[2] + 1);
if (!tmp)
log_fatal("can't realloc memory after OS_GSTrans!\n");
log_fatal("Couldn't realloc memory after OS_GSTrans!\n");
return tmp;
}
@ -303,7 +319,7 @@ set_filetype(const char *filename, const int type)
r.r[2] = type;
if (_kernel_swi(OS_File, &r, &r))
log_fatal("can't set filetype for %s\n", filename);
log_fatal("Can't set filetype for %s\n", filename);
}
void