mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Memory leak fix: repair endemic failure to call sftp_pkt_free().
[originally from svn r1570]
This commit is contained in:
parent
ae7c314f33
commit
0b61ac21c2
42
sftp.c
42
sftp.c
@ -336,12 +336,14 @@ int fxp_init(void)
|
||||
}
|
||||
if (pktin->type != SSH_FXP_VERSION) {
|
||||
fxp_internal_error("did not receive FXP_VERSION");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
remotever = sftp_pkt_getuint32(pktin);
|
||||
if (remotever > SFTP_PROTO_VERSION) {
|
||||
fxp_internal_error
|
||||
("remote protocol is more advanced than we support");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
@ -376,6 +378,7 @@ char *fxp_realpath(char *path)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x123) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
if (pktin->type == SSH_FXP_NAME) {
|
||||
@ -386,11 +389,13 @@ char *fxp_realpath(char *path)
|
||||
count = sftp_pkt_getuint32(pktin);
|
||||
if (count != 1) {
|
||||
fxp_internal_error("REALPATH returned name count != 1\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
sftp_pkt_getstring(pktin, &path, &len);
|
||||
if (!path) {
|
||||
fxp_internal_error("REALPATH returned malformed FXP_NAME\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
path = mkstr(path, len);
|
||||
@ -398,6 +403,7 @@ char *fxp_realpath(char *path)
|
||||
return path;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -424,6 +430,7 @@ struct fxp_handle *fxp_open(char *path, int type)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x567) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
if (pktin->type == SSH_FXP_HANDLE) {
|
||||
@ -434,6 +441,7 @@ struct fxp_handle *fxp_open(char *path, int type)
|
||||
sftp_pkt_getstring(pktin, &hstring, &len);
|
||||
if (!hstring) {
|
||||
fxp_internal_error("OPEN returned malformed FXP_HANDLE\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
handle = smalloc(sizeof(struct fxp_handle));
|
||||
@ -443,6 +451,7 @@ struct fxp_handle *fxp_open(char *path, int type)
|
||||
return handle;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -467,6 +476,7 @@ struct fxp_handle *fxp_opendir(char *path)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x456) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
if (pktin->type == SSH_FXP_HANDLE) {
|
||||
@ -477,6 +487,7 @@ struct fxp_handle *fxp_opendir(char *path)
|
||||
sftp_pkt_getstring(pktin, &hstring, &len);
|
||||
if (!hstring) {
|
||||
fxp_internal_error("OPENDIR returned malformed FXP_HANDLE\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
handle = smalloc(sizeof(struct fxp_handle));
|
||||
@ -486,6 +497,7 @@ struct fxp_handle *fxp_opendir(char *path)
|
||||
return handle;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -511,9 +523,11 @@ void fxp_close(struct fxp_handle *handle)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x789) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return;
|
||||
}
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
sfree(handle->hstring);
|
||||
sfree(handle);
|
||||
}
|
||||
@ -536,9 +550,11 @@ int fxp_mkdir(char *path)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x234) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -562,9 +578,11 @@ int fxp_rmdir(char *path)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x345) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -588,9 +606,11 @@ int fxp_remove(char *fname)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -615,9 +635,11 @@ int fxp_rename(char *srcfname, char *dstfname)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -645,14 +667,17 @@ int fxp_stat(char *fname, struct fxp_attrs *attrs)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pktin->type == SSH_FXP_ATTRS) {
|
||||
*attrs = sftp_pkt_getattrs(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return 1;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -675,14 +700,17 @@ int fxp_fstat(struct fxp_handle *handle, struct fxp_attrs *attrs)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pktin->type == SSH_FXP_ATTRS) {
|
||||
*attrs = sftp_pkt_getattrs(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return 1;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -708,9 +736,11 @@ int fxp_setstat(char *fname, struct fxp_attrs attrs)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -735,9 +765,11 @@ int fxp_fsetstat(struct fxp_handle *handle, struct fxp_attrs attrs)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0x678) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
id = fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
if (id != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -771,6 +803,7 @@ int fxp_read(struct fxp_handle *handle, char *buffer, uint64 offset,
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0xBCD) {
|
||||
fxp_internal_error("request ID mismatch");
|
||||
sftp_pkt_free(pktin);
|
||||
return -1;
|
||||
}
|
||||
if (pktin->type == SSH_FXP_DATA) {
|
||||
@ -781,14 +814,16 @@ int fxp_read(struct fxp_handle *handle, char *buffer, uint64 offset,
|
||||
|
||||
if (rlen > len || rlen < 0) {
|
||||
fxp_internal_error("READ returned more bytes than requested");
|
||||
sftp_pkt_free(pktin);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(buffer, str, rlen);
|
||||
sfree(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return rlen;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -814,6 +849,7 @@ struct fxp_names *fxp_readdir(struct fxp_handle *handle)
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0xABC) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
if (pktin->type == SSH_FXP_NAME) {
|
||||
@ -831,9 +867,11 @@ struct fxp_names *fxp_readdir(struct fxp_handle *handle)
|
||||
ret->names[i].longname = mkstr(str, len);
|
||||
ret->names[i].attrs = sftp_pkt_getattrs(pktin);
|
||||
}
|
||||
sftp_pkt_free(pktin);
|
||||
return ret;
|
||||
} else {
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -863,9 +901,11 @@ int fxp_write(struct fxp_handle *handle, char *buffer, uint64 offset,
|
||||
id = sftp_pkt_getuint32(pktin);
|
||||
if (id != 0xDCB) {
|
||||
fxp_internal_error("request ID mismatch\n");
|
||||
sftp_pkt_free(pktin);
|
||||
return 0;
|
||||
}
|
||||
fxp_got_status(pktin);
|
||||
sftp_pkt_free(pktin);
|
||||
return fxp_errtype == SSH_FX_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user