This is an archive of the discontinued LLVM Phabricator instance.

UriParser - fixed potential buffer overrun
ClosedPublic

Authored by vharron on Jan 11 2015, 2:38 AM.

Details

Summary

fixed potential buffer overrun by adding "10" to port parameter in sscanf
return error if port is invalid (>65535)
added tests

Diff Detail

Event Timeline

vharron updated this revision to Diff 17987.Jan 11 2015, 2:38 AM
vharron retitled this revision from to UriParser - fixed potential buffer overrun.
vharron updated this object.
vharron edited the test plan for this revision. (Show Details)
vharron added reviewers: clayborg, ovyalov, sivachandra.
vharron set the repository for this revision to rL LLVM.
vharron added a subscriber: Unknown Object (MLST).
ovyalov added inline comments.Jan 12 2015, 11:00 AM
/Users/vharron/ll/svn/lldb/source/Utility/UriParser.cpp
42

You may define port_tmp as auto instead of integer - otherwise if result of strtoul is greater than MAX_INT but less than max of unsigned long int it might be just a negative number.

43

Check for portr_tmp <= 0?

strtoul == "string to unsigned long" only accepts positive numbers

clayborg requested changes to this revision.Jan 12 2015, 11:41 AM
clayborg edited edge metadata.

I would prefer this to use Args::StringToUInt32() instead of a manual call to strtoul() from #include "lldb/Interpreter/Args.h" (even though the correct usage of strtoul() is used here). This helps abstract us from the host we are running on in case there is no strtoul() and also leads me to the fact that the Args::StringTo* calls could actually be moved into the host layer.

You might also be better off using the RegularExpression class to parse these instead of sscanf, but this isn't a required change.

This revision now requires changes to proceed.Jan 12 2015, 11:41 AM
vharron updated this revision to Diff 18245.Jan 15 2015, 12:45 PM
vharron edited edge metadata.

Switched from ::strtoul to StringConvert::ToUInt32

clayborg accepted this revision.Jan 15 2015, 12:50 PM
clayborg edited edge metadata.

Looks good.

This revision is now accepted and ready to land.Jan 15 2015, 12:50 PM
vharron updated this revision to Diff 18251.Jan 15 2015, 12:56 PM
vharron edited edge metadata.

Changed port output parameter to be -1 if port is unspecified

This makes more sense because we might want to be able to
differentiate between port unspecified and port==0

vharron closed this revision.Jan 15 2015, 1:38 PM

Committed revision 226204.