X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/1b2ef365edf850456a724b8ea3171734a492da37..1549e076bc8f485888261a3b97ce35e442b5fda9:/misc.c?ds=sidebyside diff --git a/misc.c b/misc.c index a2d741e5..34e613ef 100644 --- a/misc.c +++ b/misc.c @@ -51,6 +51,35 @@ char *dupcat(char *s1, ...) } /* ---------------------------------------------------------------------- + * Base64 encoding routine. This is required in public-key writing + * but also in HTTP proxy handling, so it's centralised here. + */ + +void base64_encode_atom(unsigned char *data, int n, char *out) +{ + static const char base64_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + unsigned word; + + word = data[0] << 16; + if (n > 1) + word |= data[1] << 8; + if (n > 2) + word |= data[2]; + out[0] = base64_chars[(word >> 18) & 0x3F]; + out[1] = base64_chars[(word >> 12) & 0x3F]; + if (n > 1) + out[2] = base64_chars[(word >> 6) & 0x3F]; + else + out[2] = '='; + if (n > 2) + out[3] = base64_chars[word & 0x3F]; + else + out[3] = '='; +} + +/* ---------------------------------------------------------------------- * Generic routines to deal with send buffers: a linked list of * smallish blocks, with the operations * @@ -294,7 +323,7 @@ static void *minefield_alloc(int size) /* * Update the admin region. */ - for (i = start + 2; i < start + npages - 1; i++) + for (i = start + 2; i < start + npages + 1; i++) minefield_admin[i] = 0xFFFE; /* used but no region starts here */ minefield_admin[start + 1] = region_start % PAGESIZE; @@ -415,7 +444,7 @@ void *safemalloc(size_t size) #endif MessageBox(NULL, str, "PuTTY Fatal Error", MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); - exit(1); + cleanup_exit(1); } #ifdef MALLOC_LOG if (fp) @@ -452,7 +481,7 @@ void *saferealloc(void *ptr, size_t size) #endif MessageBox(NULL, str, "PuTTY Fatal Error", MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); - exit(1); + cleanup_exit(1); } #ifdef MALLOC_LOG if (fp)