DataRequest: Use ArrayDeleter to manage the temporary buffer
This simplify the clean up code path and make sure that the temporary buffer will always be freed on exit. Change-Id: I70c1a25bfa66c4f4a96dd3d0af3765a67e305fb2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3074 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
e1de8e8c21
commit
2056d60ff1
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "DataRequest.h"
|
#include "DataRequest.h"
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
#include <HttpAuthentication.h>
|
#include <HttpAuthentication.h>
|
||||||
#include <mail_encoding.h>
|
#include <mail_encoding.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -88,6 +89,7 @@ BDataRequest::_ProtocolLoop()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayDeleter<char> buffer;
|
||||||
if (isBase64) {
|
if (isBase64) {
|
||||||
// Check that the base64 data is properly padded (we process characters
|
// Check that the base64 data is properly padded (we process characters
|
||||||
// by groups of 4 and there must not be stray chars at the end as
|
// by groups of 4 and there must not be stray chars at the end as
|
||||||
@ -95,18 +97,17 @@ BDataRequest::_ProtocolLoop()
|
|||||||
if (data.Length() & 3)
|
if (data.Length() & 3)
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
|
|
||||||
char* buffer = new char[data.Length() * 3 / 4];
|
buffer.SetTo(new char[data.Length() * 3 / 4]);
|
||||||
payload = buffer;
|
payload = buffer.Get();
|
||||||
// payload must be a const char* so we can assign data.String() to
|
// payload must be a const char* so we can assign data.String() to
|
||||||
// it below, but decode_64 modifies buffer.
|
// it below, but decode_64 modifies buffer.
|
||||||
length = decode_base64(buffer, data.String(), data.Length());
|
length = decode_base64(buffer.Get(), data.String(), data.Length());
|
||||||
|
|
||||||
// There may be some padding at the end of the base64 stream. This
|
// There may be some padding at the end of the base64 stream. This
|
||||||
// prevents us from computing the exact length we should get, so allow
|
// prevents us from computing the exact length we should get, so allow
|
||||||
// for some error margin.
|
// for some error margin.
|
||||||
if (length > data.Length() * 3 / 4
|
if (length > data.Length() * 3 / 4
|
||||||
|| length < data.Length() * 3 / 4 - 3) {
|
|| length < data.Length() * 3 / 4 - 3) {
|
||||||
delete[] buffer;
|
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -124,8 +125,5 @@ BDataRequest::_ProtocolLoop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBase64)
|
|
||||||
delete[] payload;
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user