KPasswordDialog / KPasswordEdit
Michael Pyne
michael.pyne at kdemail.net
Sun Jan 15 07:11:09 GMT 2006
On Saturday 14 January 2006 10:47, Daniel Molkentin wrote:
> The
> silver bullet would be to check what it takes to make QSharedData and thus
> QString to use non-swapable memory, so we could just use QString or a
> derived class to handle passwords and other sensitive data in the future.
How about the placement new operator? It constructs an object in
pre-allocated memory instead of allocating new memory. So we could allocate
protected memory for any object we want, and then construct that object in
the unshared memory and basically avoid the problem altogether.
Sample:
#include <QtCore/QString>
#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;
using std::malloc;
using std::free;
int main()
{
// Allocate space for object. Use secure_malloc() or something here.
void *buffer = malloc(1024);
// Note the "placement new" syntax.
QString *str = new (buffer) QString("StringString");
// It should actually work. ;)
cout << str->toUtf8().data() << endl;
// Don't use delete to free str, as it was not allocated by new.
// Run dtor manually instead.
str->~QString();
// Deallocate the memory using appropriate function(s).
free(buffer);
return 0;
}
Still seems like a lot of trouble for something not called SSH or GnuPG, but
there you go.
Regards,
- Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060115/d27ad650/attachment.sig>
More information about the kde-core-devel
mailing list