Add null pointer check when creating SocketAddress
ClosedPublic

Authored by chinmoyr on May 7 2018, 3:53 PM.

Details

Summary

If for some reason SocketAddress:make_address() fails to create a proper sockaddr_un structure
then SocketAddress::address() will return a null pointer. In such case, to prevent application
crash, check for null pointer prior to any socket operation.

Based on D10411

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
chinmoyr created this revision.May 7 2018, 3:53 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 7 2018, 3:53 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
chinmoyr requested review of this revision.May 7 2018, 3:53 PM
dfaure added inline comments.May 8 2018, 12:06 PM
src/ioslaves/file/fdreceiver.cpp
36

print out m_path.toLocal8Bit() here?

src/ioslaves/file/kauth/fdsender.cpp
31

print out path here?

chinmoyr updated this revision to Diff 33820.May 8 2018, 12:30 PM

Print the invalid socket path in case of an error.

dfaure added inline comments.May 8 2018, 1:52 PM
src/ioslaves/file/fdreceiver.cpp
36

Possibly nitpicking, but toStdString converts to utf8 while toLocal8Bit() is what's used for SocketAddress and what's recommended for terminal output as well. If toLocal8Bit() doesn't compile, then you need m_path.toLocal8Bit().constData(). Or the short version for a cout/cerr statement:

<< qPrintable(m_path) << std::endl;
chinmoyr updated this revision to Diff 33831.May 8 2018, 4:10 PM

Used qPrintable()

dfaure accepted this revision.May 9 2018, 7:38 AM
This revision is now accepted and ready to land.May 9 2018, 7:38 AM
Restricted Application edited subscribers, added: kde-frameworks-devel; removed: Frameworks. · View Herald TranscriptMay 9 2018, 7:38 AM
ossi requested changes to this revision.May 27 2018, 10:09 AM
ossi added inline comments.
src/ioslaves/file/fdreceiver.cpp
34

it would be more elegant to use m_path.toLocal8Bit().toStdString() here.

src/ioslaves/file/kauth/fdsender.cpp
29

you're changing the type you're using for the call here. that's a good change, but logically not part of this patch.

This revision now requires changes to proceed.May 27 2018, 10:09 AM
chinmoyr updated this revision to Diff 34961.May 27 2018, 10:57 AM
chinmoyr marked 2 inline comments as done.

fixed the issues mentioned

ossi accepted this revision.May 27 2018, 11:04 AM
This revision is now accepted and ready to land.May 27 2018, 11:04 AM
This revision was automatically updated to reflect the committed changes.