OBJS3 = sshbn.$(OBJ) sshpubk.$(OBJ) ssh.$(OBJ) pageantc.$(OBJ) sshzlib.$(OBJ)
##-- objects pageant
PAGE1 = pageant.$(OBJ) sshrsa.$(OBJ) sshpubk.$(OBJ) sshdes.$(OBJ) sshbn.$(OBJ)
-PAGE2 = sshmd5.$(OBJ) version.$(OBJ) tree234.$(OBJ)
+PAGE2 = sshmd5.$(OBJ) version.$(OBJ) tree234.$(OBJ) misc.$(OBJ)
##-- objects puttygen
GEN1 = puttygen.$(OBJ) sshrsag.$(OBJ) sshprime.$(OBJ) sshdes.$(OBJ)
GEN2 = sshbn.$(OBJ) sshmd5.$(OBJ) version.$(OBJ) sshrand.$(OBJ) noise.$(OBJ)
echo $(SOCK2) >> plink.rsp
##-- dependencies
-window.$(OBJ): window.c putty.h network.h win_res.h storage.h winstuff.h
-windlg.$(OBJ): windlg.c putty.h network.h ssh.h win_res.h winstuff.h
+window.$(OBJ): window.c putty.h puttymem.h network.h win_res.h storage.h winstuff.h
+windlg.$(OBJ): windlg.c putty.h puttymem.h network.h ssh.h win_res.h winstuff.h
winctrls.$(OBJ): winctrls.c winstuff.h winstuff.h
-settings.$(OBJ): settings.c putty.h network.h storage.h
-winstore.$(OBJ): winstore.c putty.h network.h storage.h
-terminal.$(OBJ): terminal.c putty.h network.h
-sizetip.$(OBJ): sizetip.c putty.h network.h winstuff.h
-telnet.$(OBJ): telnet.c putty.h network.h
-raw.$(OBJ): raw.c putty.h network.h
-xlat.$(OBJ): xlat.c putty.h network.h
-ldisc.$(OBJ): ldisc.c putty.h network.h
-misc.$(OBJ): misc.c putty.h network.h
-noise.$(OBJ): noise.c putty.h network.h ssh.h storage.h
-ssh.$(OBJ): ssh.c ssh.h putty.h network.h tree234.h
-sshcrc.$(OBJ): sshcrc.c ssh.h
-sshdes.$(OBJ): sshdes.c ssh.h
-sshmd5.$(OBJ): sshmd5.c ssh.h
-sshrsa.$(OBJ): sshrsa.c ssh.h
-sshsha.$(OBJ): sshsha.c ssh.h
-sshrand.$(OBJ): sshrand.c ssh.h
-sshblowf.$(OBJ): sshblowf.c ssh.h
-sshdh.$(OBJ): sshdh.c ssh.h
-sshdss.$(OBJ): sshdss.c ssh.h
-sshbn.$(OBJ): sshbn.c ssh.h
-sshpubk.$(OBJ): sshpubk.c ssh.h
-sshzlib.$(OBJ): sshzlib.c ssh.h
-scp.$(OBJ): scp.c putty.h network.h winstuff.h
+settings.$(OBJ): settings.c putty.h puttymem.h network.h storage.h
+winstore.$(OBJ): winstore.c putty.h puttymem.h network.h storage.h
+terminal.$(OBJ): terminal.c putty.h puttymem.h network.h
+sizetip.$(OBJ): sizetip.c putty.h puttymem.h network.h winstuff.h
+telnet.$(OBJ): telnet.c putty.h puttymem.h network.h
+raw.$(OBJ): raw.c putty.h puttymem.h network.h
+xlat.$(OBJ): xlat.c putty.h puttymem.h network.h
+ldisc.$(OBJ): ldisc.c putty.h puttymem.h network.h
+misc.$(OBJ): misc.c putty.h puttymem.h network.h
+noise.$(OBJ): noise.c putty.h puttymem.h network.h ssh.h storage.h
+ssh.$(OBJ): ssh.c ssh.h putty.h puttymem.h network.h tree234.h
+sshcrc.$(OBJ): sshcrc.c ssh.h puttymem.h
+sshdes.$(OBJ): sshdes.c ssh.h puttymem.h
+sshmd5.$(OBJ): sshmd5.c ssh.h puttymem.h
+sshrsa.$(OBJ): sshrsa.c ssh.h puttymem.h
+sshsha.$(OBJ): sshsha.c ssh.h puttymem.h
+sshrand.$(OBJ): sshrand.c ssh.h puttymem.h
+sshblowf.$(OBJ): sshblowf.c ssh.h puttymem.h
+sshdh.$(OBJ): sshdh.c ssh.h puttymem.h
+sshdss.$(OBJ): sshdss.c ssh.h puttymem.h
+sshbn.$(OBJ): sshbn.c ssh.h puttymem.h
+sshpubk.$(OBJ): sshpubk.c ssh.h puttymem.h
+sshzlib.$(OBJ): sshzlib.c ssh.h puttymem.h
+scp.$(OBJ): scp.c putty.h puttymem.h network.h winstuff.h
version.$(OBJ): version.c
be_all.$(OBJ): be_all.c
be_nossh.$(OBJ): be_nossh.c
be_none.$(OBJ): be_none.c
-plink.$(OBJ): plink.c putty.h network.h winstuff.h
-pageant.$(OBJ): pageant.c ssh.h tree234.h
-tree234.$(OBJ): tree234.c tree234.h
+plink.$(OBJ): plink.c putty.h puttymem.h network.h winstuff.h
+pageant.$(OBJ): pageant.c ssh.h puttymem.h tree234.h
+pageantc.$(OBJ): pageantc.c puttymem.h
+tree234.$(OBJ): tree234.c tree234.h puttymem.h
##--
# Hack to force version.obj to be rebuilt always
needs_pass = rsakey_encrypted(filename, &comment);
attempts = 0;
- key = malloc(sizeof(*key));
+ key = smalloc(sizeof(*key));
pps.passphrase = passphrase;
pps.comment = comment;
do {
NULL, PassphraseProc,
(LPARAM)&pps);
if (!dlgret) {
- if (comment) free(comment);
- free(key);
+ if (comment) sfree(comment);
+ sfree(key);
return; /* operation cancelled */
}
} else
ret = loadrsakey(filename, key, NULL, passphrase);
attempts++;
} while (ret == -1);
- if (comment) free(comment);
+ if (comment) sfree(comment);
if (ret == 0) {
MessageBox(NULL, "Couldn't load private key.", APPNAME,
MB_OK | MB_ICONERROR);
- free(key);
+ sfree(key);
return;
}
if (add234(rsakeys, key) != key)
- free(key); /* already present, don't waste RAM */
+ sfree(key); /* already present, don't waste RAM */
}
/*
{
struct RSAKey *key;
char *comment;
- key = malloc(sizeof(struct RSAKey));
+ key = smalloc(sizeof(struct RSAKey));
memset(key, 0, sizeof(key));
p += makekey(p, key, NULL, 1);
p += makeprivate(p, key);
p += ssh1_read_bignum(p, NULL); /* p^-1 mod q */
p += ssh1_read_bignum(p, NULL); /* p */
p += ssh1_read_bignum(p, NULL); /* q */
- comment = malloc(GET_32BIT(p));
+ comment = smalloc(GET_32BIT(p));
if (comment) {
memcpy(comment, p+4, GET_32BIT(p));
key->comment = comment;
ret[4] = SSH_AGENT_SUCCESS;
} else {
freersakey(key);
- free(key);
+ sfree(key);
}
}
break;
#include <stdio.h>
#include <stdlib.h>
+#include "puttymem.h"
+
#define AGENT_COPYDATA_ID 0x804e50ba /* random goop */
#define AGENT_MAX_MSGLEN 8192
if (id > 0) {
retlen = 4 + GET_32BIT(p);
debug(("len is %d\n", retlen));
- ret = malloc(retlen);
+ ret = smalloc(retlen);
if (ret) {
memcpy(ret, p, retlen);
*out = ret;
* Exports from misc.c.
*/
-/* #define MALLOC_LOG do this if you suspect putty of leaking memory */
-#ifdef MALLOC_LOG
-#define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
-#define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
-#define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
-void mlog(char *, int);
-#else
-#define smalloc safemalloc
-#define srealloc saferealloc
-#define sfree safefree
-#endif
-
-void *safemalloc(size_t);
-void *saferealloc(void *, size_t);
-void safefree(void *);
+#include "puttymem.h"
/*
* Exports from version.c.
PostMessage(params->dialog, WM_DONEKEY, 0, 0);
- free(params);
+ sfree(params);
return 0;
}
dec1 = bignum_decimal(key->exponent);
dec2 = bignum_decimal(key->modulus);
- buffer = malloc(strlen(dec1)+strlen(dec2)+
- strlen(key->comment)+30);
+ buffer = smalloc(strlen(dec1)+strlen(dec2)+
+ strlen(key->comment)+30);
sprintf(buffer, "%d %s %s %s",
ssh1_bignum_bitcount(key->modulus),
dec1, dec2, key->comment);
SetDlgItemText(hwnd, id, buffer);
- free(dec1);
- free(dec2);
- free(buffer);
+ sfree(dec1);
+ sfree(dec2);
+ sfree(buffer);
}
/*
switch (msg) {
case WM_INITDIALOG:
- state = malloc(sizeof(*state));
+ state = smalloc(sizeof(*state));
state->generation_thread_exists = FALSE;
state->collecting_entropy = FALSE;
state->entropy = NULL;
*/
random_add_heavynoise(state->entropy, state->entropy_size);
memset(state->entropy, 0, state->entropy_size);
- free(state->entropy);
+ sfree(state->entropy);
state->collecting_entropy = FALSE;
SetDlgItemText(hwnd, IDC_GENERATING, generating_msg);
MAKELPARAM(0, PROGRESSRANGE));
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
- params = malloc(sizeof(*params));
+ params = smalloc(sizeof(*params));
params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
params->dialog = hwnd;
params->keysize = state->keysize;
MessageBox(hwnd, "Out of thread resources",
"Key generation error",
MB_OK | MB_ICONERROR);
- free(params);
+ sfree(params);
} else {
state->generation_thread_exists = TRUE;
}
HWND editctl = GetDlgItem(hwnd, IDC_COMMENTEDIT);
int len = GetWindowTextLength(editctl);
if (state->key.comment)
- free(state->key.comment);
- state->key.comment = malloc(len+1);
+ sfree(state->key.comment);
+ state->key.comment = smalloc(len+1);
GetWindowText(editctl, state->key.comment, len+1);
}
}
state->entropy_got = 0;
state->entropy_size = (state->entropy_required *
sizeof(*state->entropy));
- state->entropy = malloc(state->entropy_size);
+ state->entropy = smalloc(state->entropy_size);
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, state->entropy_required));
ret = loadrsakey(filename, &newkey, &newaux,
passphrase);
} while (ret == -1);
- if (comment) free(comment);
+ if (comment) sfree(comment);
if (ret == 0) {
MessageBox(NULL, "Couldn't load private key.",
"PuTTYgen Error", MB_OK | MB_ICONERROR);
* the user will immediately want to change it, which is
* what we want :-)
*/
- state->key.comment = malloc(30);
+ state->key.comment = smalloc(30);
{
time_t t;
struct tm *tm;
break;
case WM_CLOSE:
state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
- free(state);
+ sfree(state);
EndDialog(hwnd, 1);
return 0;
}
--- /dev/null
+/*
+ * PuTTY memory-handling header.
+ */
+
+#ifndef PUTTY_PUTTYMEM_H
+#define PUTTY_PUTTYMEM_H
+
+/* #define MALLOC_LOG do this if you suspect putty of leaking memory */
+#ifdef MALLOC_LOG
+#define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
+#define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
+#define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
+void mlog(char *, int);
+#else
+#define smalloc safemalloc
+#define srealloc saferealloc
+#define sfree safefree
+#endif
+
+void *safemalloc(size_t);
+void *saferealloc(void *, size_t);
+void safefree(void *);
+
+#endif
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
- pending = (pending ? realloc(pending, pendsize) :
- malloc(pendsize));
+ pending = (pending ? srealloc(pending, pendsize) :
+ smalloc(pendsize));
if (!pending)
fatalbox("Out of memory");
}
pendlen -= pendused;
if (pendlen == 0) {
pendsize = 0;
- free(pending);
+ sfree(pending);
pending = NULL;
}
if (outlen == 0)
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
wtlen = GetWindowTextLength(hWnd);
- wt = (LPTSTR)malloc((wtlen+1)*sizeof(TCHAR));
+ wt = (LPTSTR)smalloc((wtlen+1)*sizeof(TCHAR));
GetWindowText(hWnd, wt, wtlen+1);
SetTextColor(hdc, tip_text);
TextOut(hdc, cr.left+3, cr.top+3, wt, wtlen);
- free(wt);
+ sfree(wt);
SelectObject(hdc, holdbr);
DeleteObject(hbr);
if (pktin.maxlen < st->biglen) {
pktin.maxlen = st->biglen;
- pktin.data = (pktin.data == NULL ? malloc(st->biglen+APIEXTRA) :
- realloc(pktin.data, st->biglen+APIEXTRA));
+ pktin.data = (pktin.data == NULL ? smalloc(st->biglen+APIEXTRA) :
+ srealloc(pktin.data, st->biglen+APIEXTRA));
if (!pktin.data)
fatalbox("Out of memory");
}
if (pktin.maxlen < st->pad + decomplen) {
pktin.maxlen = st->pad + decomplen;
- pktin.data = realloc(pktin.data, pktin.maxlen+APIEXTRA);
+ pktin.data = srealloc(pktin.data, pktin.maxlen+APIEXTRA);
if (!pktin.data)
fatalbox("Out of memory");
}
memcpy(pktin.body-1, decompblk, decomplen);
- free(decompblk);
+ sfree(decompblk);
pktin.length = decomplen-1;
#if 0
debug(("Packet payload post-decompression:\n"));
if (pktin.maxlen < st->cipherblk) {
pktin.maxlen = st->cipherblk;
- pktin.data = (pktin.data == NULL ? malloc(st->cipherblk+APIEXTRA) :
- realloc(pktin.data, st->cipherblk+APIEXTRA));
+ pktin.data = (pktin.data == NULL ? smalloc(st->cipherblk+APIEXTRA) :
+ srealloc(pktin.data, st->cipherblk+APIEXTRA));
if (!pktin.data)
fatalbox("Out of memory");
}
*/
if (pktin.maxlen < st->packetlen+st->maclen) {
pktin.maxlen = st->packetlen+st->maclen;
- pktin.data = (pktin.data == NULL ? malloc(pktin.maxlen+APIEXTRA) :
- realloc(pktin.data, pktin.maxlen+APIEXTRA));
+ pktin.data = (pktin.data == NULL ? smalloc(pktin.maxlen+APIEXTRA) :
+ srealloc(pktin.data, pktin.maxlen+APIEXTRA));
if (!pktin.data)
fatalbox("Out of memory");
}
&newpayload, &newlen)) {
if (pktin.maxlen < newlen+5) {
pktin.maxlen = newlen+5;
- pktin.data = (pktin.data == NULL ? malloc(pktin.maxlen+APIEXTRA) :
- realloc(pktin.data, pktin.maxlen+APIEXTRA));
+ pktin.data = (pktin.data == NULL ? smalloc(pktin.maxlen+APIEXTRA) :
+ srealloc(pktin.data, pktin.maxlen+APIEXTRA));
if (!pktin.data)
fatalbox("Out of memory");
}
debug(("\r\n"));
#endif
- free(newpayload);
+ sfree(newpayload);
}
}
#ifdef MSCRYPTOAPI
/* Allocate enough buffer space for extra block
* for MS CryptEncrypt() */
- pktout.data = (pktout.data == NULL ? malloc(biglen+12) :
- realloc(pktout.data, biglen+12));
+ pktout.data = (pktout.data == NULL ? smalloc(biglen+12) :
+ srealloc(pktout.data, biglen+12));
#else
- pktout.data = (pktout.data == NULL ? malloc(biglen+4) :
- realloc(pktout.data, biglen+4));
+ pktout.data = (pktout.data == NULL ? smalloc(biglen+4) :
+ srealloc(pktout.data, biglen+4));
#endif
if (!pktout.data)
fatalbox("Out of memory");
&compblk, &complen);
ssh1_pktout_size(complen-1);
memcpy(pktout.body-1, compblk, complen);
- free(compblk);
+ sfree(compblk);
#if 0
debug(("Packet payload post-compression:\n"));
for (i = -1; i < pktout.length; i++)
pktout.length += len;
if (pktout.maxlen < pktout.length) {
pktout.maxlen = pktout.length + 256;
- pktout.data = (pktout.data == NULL ? malloc(pktout.maxlen+APIEXTRA) :
- realloc(pktout.data, pktout.maxlen+APIEXTRA));
+ pktout.data = (pktout.data == NULL ? smalloc(pktout.maxlen+APIEXTRA) :
+ srealloc(pktout.data, pktout.maxlen+APIEXTRA));
if (!pktout.data)
fatalbox("Out of memory");
}
static char *ssh2_mpint_fmt(Bignum b, int *len) {
unsigned char *p;
int i, n = b[0];
- p = malloc(n * 2 + 1);
+ p = smalloc(n * 2 + 1);
if (!p)
fatalbox("out of memory");
p[0] = 0;
p = ssh2_mpint_fmt(b, &len);
ssh2_pkt_addstring_start();
ssh2_pkt_addstring_data(p, len);
- free(p);
+ sfree(p);
}
static void ssh2_pkt_send(void) {
int cipherblk, maclen, padding, i;
&newpayload, &newlen)) {
pktout.length = 5;
ssh2_pkt_adddata(newpayload, newlen);
- free(newpayload);
+ sfree(newpayload);
}
}
for (i = 0; i < len; i++)
debug((" %02x", p[i]));
debug(("\r\n"));
- free(p);
+ sfree(p);
}
#endif
int len;
p = ssh2_mpint_fmt(b, &len);
sha_string(s, p, len);
- free(p);
+ sfree(p);
}
/*
int FWport;
#endif
- savedhost = malloc(1+strlen(host));
+ savedhost = smalloc(1+strlen(host));
if (!savedhost)
fatalbox("Out of memory");
strcpy(savedhost, host);
len = (hostkey.bytes > servkey.bytes ? hostkey.bytes : servkey.bytes);
- rsabuf = malloc(len);
+ rsabuf = smalloc(len);
if (!rsabuf)
fatalbox("Out of memory");
*/
int len = rsastr_len(&hostkey);
char fingerprint[100];
- char *keystr = malloc(len);
+ char *keystr = smalloc(len);
if (!keystr)
fatalbox("Out of memory");
rsastr_fmt(keystr, &hostkey);
rsa_fingerprint(fingerprint, sizeof(fingerprint), &hostkey);
verify_ssh_host_key(savedhost, savedport, "rsa", keystr, fingerprint);
- free(keystr);
+ sfree(keystr);
}
for (i=0; i<32; i++) {
logevent("Trying to enable encryption...");
- free(rsabuf);
+ sfree(rsabuf);
cipher = cipher_type == SSH_CIPHER_BLOWFISH ? &ssh_blowfish_ssh1 :
cipher_type == SSH_CIPHER_DES ? &ssh_des :
len += ssh1_bignum_length(challenge);
len += 16; /* session id */
len += 4; /* response format */
- agentreq = malloc(4 + len);
+ agentreq = smalloc(4 + len);
PUT_32BIT(agentreq, len);
q = agentreq + 4;
*q++ = SSH_AGENTC_RSA_CHALLENGE;
memcpy(q, session_id, 16); q += 16;
PUT_32BIT(q, 1); /* response format */
agent_query(agentreq, len+4, &ret, &retlen);
- free(agentreq);
+ sfree(agentreq);
if (ret) {
if (ret[4] == SSH_AGENT_RSA_RESPONSE) {
logevent("Sending Pageant's response");
send_packet(SSH1_CMSG_AUTH_RSA_RESPONSE,
PKT_DATA, ret+5, 16, PKT_END);
- free(ret);
+ sfree(ret);
crWaitUntil(ispkt);
if (pktin.type == SSH1_SMSG_SUCCESS) {
logevent("Pageant's response accepted");
logevent("Pageant's response not accepted");
} else {
logevent("Pageant failed to answer challenge");
- free(ret);
+ sfree(ret);
}
} else {
logevent("No reply received from Pageant");
goto tryauth;
}
sprintf(prompt, "Passphrase for key \"%.100s\": ", comment);
- free(comment);
+ sfree(comment);
}
if (ssh_get_password) {
break; /* found a free number */
i = c->localid + 1;
}
- c = malloc(sizeof(struct ssh_channel));
+ c = smalloc(sizeof(struct ssh_channel));
c->remoteid = GET_32BIT(pktin.body);
c->localid = i;
c->closes = 0;
c->closes |= closetype;
if (c->closes == 3) {
del234(ssh_channels, c);
- free(c);
+ sfree(c);
}
}
} else if (pktin.type == SSH1_MSG_CHANNEL_DATA) {
}
if (c->u.a.lensofar == 4) {
c->u.a.totallen = 4 + GET_32BIT(c->u.a.msglen);
- c->u.a.message = malloc(c->u.a.totallen);
+ c->u.a.message = smalloc(c->u.a.totallen);
memcpy(c->u.a.message, c->u.a.msglen, 4);
}
if (c->u.a.lensofar >= 4 && len > 0) {
PKT_DATA, sentreply, replylen,
PKT_END);
if (reply)
- free(reply);
- free(c->u.a.message);
+ sfree(reply);
+ sfree(c->u.a.message);
c->u.a.lensofar = 0;
}
}
keystr, fingerprint);
logevent("Host key fingerprint is:");
logevent(fingerprint);
- free(fingerprint);
- free(keystr);
+ sfree(fingerprint);
+ sfree(keystr);
hostkey->freekey(hkey);
/*
/*
* So now create a channel with a session in it.
*/
- mainchan = malloc(sizeof(struct ssh_channel));
+ mainchan = smalloc(sizeof(struct ssh_channel));
mainchan->localid = 100; /* as good as any */
ssh2_pkt_init(SSH2_MSG_CHANNEL_OPEN);
ssh2_pkt_addstring("session");
#include <string.h>
+#include "puttymem.h"
+
/*
* Useful thing.
*/
Bignum Zero = bnZero, One = bnOne;
Bignum newbn(int length) {
- Bignum b = malloc((length+1)*sizeof(unsigned short));
+ Bignum b = smalloc((length+1)*sizeof(unsigned short));
if (!b)
abort(); /* FIXME */
memset(b, 0, (length+1)*sizeof(*b));
}
Bignum copybn(Bignum orig) {
- Bignum b = malloc((orig[0]+1)*sizeof(unsigned short));
+ Bignum b = smalloc((orig[0]+1)*sizeof(unsigned short));
if (!b)
abort(); /* FIXME */
memcpy(b, orig, (orig[0]+1)*sizeof(*b));
* Burn the evidence, just in case.
*/
memset(b, 0, sizeof(b[0]) * (b[0] + 1));
- free(b);
+ sfree(b);
}
/*
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = malloc(mlen * sizeof(unsigned short));
+ m = smalloc(mlen * sizeof(unsigned short));
for (j = 0; j < mlen; j++) m[j] = mod[mod[0] - j];
/* Shift m left to make msb bit set */
}
/* Allocate n of size mlen, copy base to n */
- n = malloc(mlen * sizeof(unsigned short));
+ n = smalloc(mlen * sizeof(unsigned short));
i = mlen - base[0];
for (j = 0; j < i; j++) n[j] = 0;
for (j = 0; j < base[0]; j++) n[i+j] = base[base[0] - j];
/* Allocate a and b of size 2*mlen. Set a = 1 */
- a = malloc(2 * mlen * sizeof(unsigned short));
- b = malloc(2 * mlen * sizeof(unsigned short));
+ a = smalloc(2 * mlen * sizeof(unsigned short));
+ b = smalloc(2 * mlen * sizeof(unsigned short));
for (i = 0; i < 2*mlen; i++) a[i] = 0;
a[2*mlen-1] = 1;
while (result[0] > 1 && result[result[0]] == 0) result[0]--;
/* Free temporary arrays */
- for (i = 0; i < 2*mlen; i++) a[i] = 0; free(a);
- for (i = 0; i < 2*mlen; i++) b[i] = 0; free(b);
- for (i = 0; i < mlen; i++) m[i] = 0; free(m);
- for (i = 0; i < mlen; i++) n[i] = 0; free(n);
+ for (i = 0; i < 2*mlen; i++) a[i] = 0; sfree(a);
+ for (i = 0; i < 2*mlen; i++) b[i] = 0; sfree(b);
+ for (i = 0; i < mlen; i++) m[i] = 0; sfree(m);
+ for (i = 0; i < mlen; i++) n[i] = 0; sfree(n);
return result;
}
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = malloc(mlen * sizeof(unsigned short));
+ m = smalloc(mlen * sizeof(unsigned short));
for (j = 0; j < mlen; j++) m[j] = mod[mod[0] - j];
/* Shift m left to make msb bit set */
pqlen = (p[0] > q[0] ? p[0] : q[0]);
/* Allocate n of size pqlen, copy p to n */
- n = malloc(pqlen * sizeof(unsigned short));
+ n = smalloc(pqlen * sizeof(unsigned short));
i = pqlen - p[0];
for (j = 0; j < i; j++) n[j] = 0;
for (j = 0; j < p[0]; j++) n[i+j] = p[p[0] - j];
/* Allocate o of size pqlen, copy q to o */
- o = malloc(pqlen * sizeof(unsigned short));
+ o = smalloc(pqlen * sizeof(unsigned short));
i = pqlen - q[0];
for (j = 0; j < i; j++) o[j] = 0;
for (j = 0; j < q[0]; j++) o[i+j] = q[q[0] - j];
/* Allocate a of size 2*pqlen for result */
- a = malloc(2 * pqlen * sizeof(unsigned short));
+ a = smalloc(2 * pqlen * sizeof(unsigned short));
/* Main computation */
internal_mul(n, o, a, pqlen);
while (result[0] > 1 && result[result[0]] == 0) result[0]--;
/* Free temporary arrays */
- for (i = 0; i < 2*pqlen; i++) a[i] = 0; free(a);
- for (i = 0; i < mlen; i++) m[i] = 0; free(m);
- for (i = 0; i < pqlen; i++) n[i] = 0; free(n);
- for (i = 0; i < pqlen; i++) o[i] = 0; free(o);
+ for (i = 0; i < 2*pqlen; i++) a[i] = 0; sfree(a);
+ for (i = 0; i < mlen; i++) m[i] = 0; sfree(m);
+ for (i = 0; i < pqlen; i++) n[i] = 0; sfree(n);
+ for (i = 0; i < pqlen; i++) o[i] = 0; sfree(o);
return result;
}
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = malloc(mlen * sizeof(unsigned short));
+ m = smalloc(mlen * sizeof(unsigned short));
for (j = 0; j < mlen; j++) m[j] = mod[mod[0] - j];
/* Shift m left to make msb bit set */
if (plen <= mlen) plen = mlen+1;
/* Allocate n of size plen, copy p to n */
- n = malloc(plen * sizeof(unsigned short));
+ n = smalloc(plen * sizeof(unsigned short));
for (j = 0; j < plen; j++) n[j] = 0;
for (j = 1; j <= p[0]; j++) n[plen-j] = p[j];
}
/* Free temporary arrays */
- for (i = 0; i < mlen; i++) m[i] = 0; free(m);
- for (i = 0; i < plen; i++) n[i] = 0; free(n);
+ for (i = 0; i < mlen; i++) m[i] = 0; sfree(m);
+ for (i = 0; i < plen; i++) n[i] = 0; sfree(n);
}
/*
Bignum ret;
/* mlen space for a, mlen space for b, 2*mlen for result */
- workspace = malloc(mlen * 4 * sizeof(unsigned short));
+ workspace = smalloc(mlen * 4 * sizeof(unsigned short));
for (i = 0; i < mlen; i++) {
workspace[0*mlen + i] = (mlen-i <= a[0] ? a[mlen-i] : 0);
workspace[1*mlen + i] = (mlen-i <= b[0] ? b[mlen-i] : 0);
i = ssh1_bignum_bitcount(x);
ndigits = (28*i + 92)/93; /* multiply by 28/93 and round up */
ndigits++; /* allow for trailing \0 */
- ret = malloc(ndigits);
+ ret = smalloc(ndigits);
/*
* Now allocate some workspace to hold the binary form as we
* repeatedly divide it by ten. Initialise this to the
* big-endian form of the number.
*/
- workspace = malloc(sizeof(unsigned short) * x[0]);
+ workspace = smalloc(sizeof(unsigned short) * x[0]);
for (i = 0; i < x[0]; i++)
workspace[i] = x[x[0] - i];
int slen;
struct dss_key *dss;
- dss = malloc(sizeof(struct dss_key));
+ dss = smalloc(sizeof(struct dss_key));
if (!dss) return NULL;
getstring(&data, &len, &p, &slen);
#endif
if (!p || memcmp(p, "ssh-dss", 7)) {
- free(dss);
+ sfree(dss);
return NULL;
}
dss->p = getmp(&data, &len);
freebn(dss->q);
freebn(dss->g);
freebn(dss->y);
- free(dss);
+ sfree(dss);
}
static char *dss_fmtkey(void *key) {
return NULL;
len = 8 + 4 + 1; /* 4 x "0x", punctuation, \0 */
len += 4 * (dss->p[0] + dss->q[0] + dss->g[0] + dss->y[0]); /* digits */
- p = malloc(len);
+ p = smalloc(len);
if (!p) return NULL;
pos = 0;
sprintf(buffer, "%d ", ssh1_bignum_bitcount(dss->p));
for (i = 0; i < 16; i++)
sprintf(buffer+strlen(buffer), "%s%02x", i?":":"", digest[i]);
- ret = malloc(strlen(buffer)+1);
+ ret = smalloc(strlen(buffer)+1);
if (ret)
strcpy(ret, buffer);
return ret;
j = GET_32BIT(buf+i);
i += 4;
if (len-i < j) goto end;
- comment = malloc(j+1);
+ comment = smalloc(j+1);
if (comment) {
memcpy(comment, buf+i, j);
comment[j] = '\0';
if (key->modulus) freebn(key->modulus);
if (key->exponent) freebn(key->exponent);
if (key->private_exponent) freebn(key->private_exponent);
- if (key->comment) free(key->comment);
+ if (key->comment) sfree(key->comment);
}
struct LZ77InternalContext *st;
int i;
- st = (struct LZ77InternalContext *)malloc(sizeof(*st));
+ st = (struct LZ77InternalContext *)smalloc(sizeof(*st));
if (!st)
return 0;
while (out->noutbits >= 8) {
if (out->outlen >= out->outsize) {
out->outsize = out->outlen + 64;
- out->outbuf = realloc(out->outbuf, out->outsize);
+ out->outbuf = srealloc(out->outbuf, out->outsize);
}
out->outbuf[out->outlen++] = (unsigned char)(out->outbits & 0xFF);
out->outbits >>= 8;
ectx.literal = zlib_literal;
ectx.match = zlib_match;
- out = malloc(sizeof(struct Outbuf));
+ out = smalloc(sizeof(struct Outbuf));
out->outbits = out->noutbits = 0;
out->firstblock = 1;
ectx.userdata = out;
static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
int nsyms,
int pfx, int pfxbits, int bits) {
- struct zlib_table *tab = malloc(sizeof(struct zlib_table));
+ struct zlib_table *tab = smalloc(sizeof(struct zlib_table));
int pfxmask = (1 << pfxbits) - 1;
int nbits, i, j, code;
- tab->table = malloc((1 << bits) * sizeof(struct zlib_tableentry));
+ tab->table = smalloc((1 << bits) * sizeof(struct zlib_tableentry));
tab->mask = (1 << bits) - 1;
for (code = 0; code <= tab->mask; code++) {
memset(lengths, 5, 32);
dctx.staticdisttable = zlib_mktable(lengths, 32);
dctx.state = START; /* even before header */
- dctx.currlentable = dctx.currdisttable = NULL;
+ dctx.currlentable = dctx.currdisttable = dctx.lenlentable = NULL;
dctx.bits = 0;
dctx.nbits = 0;
logevent("Initialised zlib (RFC1950) decompression");
dctx.winpos = (dctx.winpos + 1) & (WINSIZE-1);
if (dctx.outlen >= dctx.outsize) {
dctx.outsize = dctx.outlen + 512;
- dctx.outblk = realloc(dctx.outblk, dctx.outsize);
+ dctx.outblk = srealloc(dctx.outblk, dctx.outsize);
}
dctx.outblk[dctx.outlen++] = c;
}
#include <stdio.h>
#include <stdlib.h>
+#include "puttymem.h"
+
#include "tree234.h"
-#define mknew(typ) ( (typ *) malloc (sizeof (typ)) )
-#define sfree free
+#define mknew(typ) ( (typ *) smalloc (sizeof (typ)) )
+/* #define sfree free */
#ifdef TEST
#define LOG(x) (printf x)
if (arraysize < arraylen+1) {
arraysize = arraylen+1+256;
- array = (array == NULL ? malloc(arraysize*sizeof(*array)) :
- realloc(array, arraysize*sizeof(*array)));
+ array = (array == NULL ? smalloc(arraysize*sizeof(*array)) :
+ srealloc(array, arraysize*sizeof(*array)));
}
i = 0;
int *selitems;
selcount = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELCOUNT, 0, 0);
- selitems = malloc(selcount * sizeof(int));
+ selitems = smalloc(selcount * sizeof(int));
if (selitems) {
int count = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELITEMS,
for (i = 0; i < count; i++)
size += strlen(events[selitems[i]]) + sizeof(sel_nl);
- clipdata = malloc(size);
+ clipdata = smalloc(size);
if (clipdata) {
char *p = clipdata;
for (i = 0; i < count; i++) {
p += sizeof(sel_nl);
}
write_clip(clipdata, size, TRUE);
- free(clipdata);
+ sfree(clipdata);
}
- free(selitems);
+ sfree(selitems);
for (i = 0; i < nevents; i++)
SendDlgItemMessage(hwnd, IDN_LIST, LB_SETSEL,
{
char *bits;
int size = (font_width+15)/16 * 2 * font_height;
- bits = calloc(size, 1);
+ bits = smalloc(size);
+ memset(bits, 0, size);
caretbm = CreateBitmap(font_width, font_height, 1, 1, bits);
- free(bits);
+ sfree(bits);
}
/*
cl = c;
} else if (wParam == IDM_SAVEDSESS) {
char *session = sessions[(lParam - IDM_SAVED_MIN) / 16];
- cl = malloc(16 + strlen(session)); /* 8, but play safe */
+ cl = smalloc(16 + strlen(session)); /* 8, but play safe */
if (!cl)
cl = NULL; /* not a very important failure mode */
else {
if (filemap)
CloseHandle(filemap);
if (freecl)
- free(cl);
+ sfree(cl);
}
break;
case IDM_RECONF:
del234(sktree, s);
do_select(s->s, 0);
closesocket(s->s);
- free(s);
+ sfree(s);
}
char *winsock_error_string(int error) {
if (s->head->bufpos >= s->head->buflen) {
struct buffer *tmp = s->head;
s->head = tmp->next;
- free(tmp);
+ sfree(tmp);
if (!s->head)
s->tail = NULL;
}
while (walk) {
struct buffer *tmp = walk;
walk = tmp->next;
- free(tmp);
+ sfree(tmp);
}
}
s->head->next = NULL;
int ret;
char *p;
- p = malloc(3*strlen(sessionname)+1);
+ p = smalloc(3*strlen(sessionname)+1);
mungestr(sessionname, p);
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
if (ret != ERROR_SUCCESS) {
- free(p);
+ sfree(p);
return NULL;
}
ret = RegCreateKey(subkey1, p, &sesskey);
- free(p);
+ sfree(p);
RegCloseKey(subkey1);
if (ret != ERROR_SUCCESS)
return NULL;
HKEY subkey1, sesskey;
char *p;
- p = malloc(3*strlen(sessionname)+1);
+ p = smalloc(3*strlen(sessionname)+1);
mungestr(sessionname, p);
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
RegCloseKey(subkey1);
}
- free(p);
+ sfree(p);
return (void *)sesskey;
}
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
return;
- p = malloc(3*strlen(sessionname)+1);
+ p = smalloc(3*strlen(sessionname)+1);
mungestr(sessionname, p);
RegDeleteKey(subkey1, p);
- free(p);
+ sfree(p);
RegCloseKey(subkey1);
}
if (RegCreateKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
return NULL;
- ret = malloc(sizeof(*ret));
+ ret = smalloc(sizeof(*ret));
if (ret) {
ret->key = key;
ret->i = 0;
char *enum_settings_next(void *handle, char *buffer, int buflen) {
struct enumsettings *e = (struct enumsettings *)handle;
char *otherbuf;
- otherbuf = malloc(3*buflen);
+ otherbuf = smalloc(3*buflen);
if (otherbuf && RegEnumKey(e->key, e->i++, otherbuf,
3*buflen) == ERROR_SUCCESS) {
unmungestr(otherbuf, buffer, buflen);
- free(otherbuf);
+ sfree(otherbuf);
return buffer;
} else
return NULL;
void enum_settings_finish(void *handle) {
struct enumsettings *e = (struct enumsettings *)handle;
RegCloseKey(e->key);
- free(e);
+ sfree(e);
}
static void hostkey_regname(char *buffer, char *hostname,