People: Fix buffer overflow in string handling.
Also move some variable declarations closer to their usages. Fixes #18618.
This commit is contained in:
parent
de9f473cda
commit
5c040b731c
@ -167,12 +167,6 @@ PersonWindow::MenusBeginning()
|
|||||||
void
|
void
|
||||||
PersonWindow::MessageReceived(BMessage* msg)
|
PersonWindow::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
char str[256];
|
|
||||||
BDirectory directory;
|
|
||||||
BEntry entry;
|
|
||||||
BFile file;
|
|
||||||
BNodeInfo *node;
|
|
||||||
|
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case M_SAVE:
|
case M_SAVE:
|
||||||
if (!fRef) {
|
if (!fRef) {
|
||||||
@ -206,23 +200,27 @@ PersonWindow::MessageReceived(BMessage* msg)
|
|||||||
if (msg->FindRef("directory", &dir) == B_OK) {
|
if (msg->FindRef("directory", &dir) == B_OK) {
|
||||||
const char* name = NULL;
|
const char* name = NULL;
|
||||||
msg->FindString("name", &name);
|
msg->FindString("name", &name);
|
||||||
|
|
||||||
|
BDirectory directory;
|
||||||
directory.SetTo(&dir);
|
directory.SetTo(&dir);
|
||||||
if (directory.InitCheck() == B_NO_ERROR) {
|
if (directory.InitCheck() == B_NO_ERROR) {
|
||||||
|
BFile file;
|
||||||
directory.CreateFile(name, &file);
|
directory.CreateFile(name, &file);
|
||||||
if (file.InitCheck() == B_NO_ERROR) {
|
if (file.InitCheck() == B_NO_ERROR) {
|
||||||
node = new BNodeInfo(&file);
|
BNodeInfo* node = new BNodeInfo(&file);
|
||||||
node->SetType("application/x-person");
|
node->SetType("application/x-person");
|
||||||
delete node;
|
delete node;
|
||||||
|
|
||||||
|
BEntry entry;
|
||||||
directory.FindEntry(name, &entry);
|
directory.FindEntry(name, &entry);
|
||||||
entry.GetRef(&dir);
|
entry.GetRef(&dir);
|
||||||
_SetToRef(new entry_ref(dir));
|
_SetToRef(new entry_ref(dir));
|
||||||
SetTitle(fRef->name);
|
SetTitle(fRef->name);
|
||||||
fView->CreateFile(fRef);
|
fView->CreateFile(fRef);
|
||||||
}
|
} else {
|
||||||
else {
|
BString str;
|
||||||
sprintf(str, B_TRANSLATE("Could not create %s."), name);
|
str.SetToFormat(B_TRANSLATE("Could not create %s."), name);
|
||||||
BAlert* alert = new BAlert("", str, B_TRANSLATE("Sorry"));
|
BAlert* alert = new BAlert("", str.String(), B_TRANSLATE("Sorry"));
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user