SlideShare a Scribd company logo
Code as Risk
@KevlinHenney
Code as Risk
Code as Risk
Code as Risk
Code as Risk
Code as Risk
Code as Risk
Code as Risk
https://twitter.com/tackline/status/757562488363843584
https://twitter.com/NativeWired/status/828939258475999232
Code as Risk
Code as Risk
https://krebsonsecurity.com/2016/11/san-francisco-rail-system-hacker-hacked/
Code as Risk
Code as Risk
Code as Risk
if ((err = ReadyHash(&SSLHashSHA1, &hashCtx)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &clientRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
Mike Bland
"Goto Fail, Heartbleed, and Unit Testing Culture"
https://martinfowler.com/articles/testing-culture.html
network code()
{
switch (line) {
case THING1:
doit1();
break;
case THING2:
if (x == STUFF) {
do_first_stuff();
if (y == OTHER_STUFF)
break;
do_later_stuff();
} /* coder meant to break to here... */
initialize_modes_pointer();
break;
default:
processing();
} /* ...but actually broke to here! */
use_modes_pointer(); /* leaving the modes_pointer uninitialized */
}
Peter van der Linden
Expert C Programming
Most of our systems are much
more complicated than can be
considered healthy, and are too
messy and chaotic to be used
in comfort and confidence.
Edsger W Dijkstra
Code as Risk
There are standard precautions that can help
reduce risk in complex software systems.
This includes the definition of a good
software architecture based on a clean
separation of concerns, data hiding,
modularity, well-defined interfaces, and
strong fault-protection mechanisms.
Gerard J Holzmann
http://cacm.acm.org/magazines/2014/2/171689-mars-code/fulltext
/ WordFriday
code, noun
▪ a set of instructions for a computer
▪ a computer program, or a portion thereof
▪ a system of words, figures or symbols used to represent others,
especially for the purposes of secrecy
▪ a set of conventions or principles governing behaviour or activity in
a particular domain
Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
risk, noun
▪ a situation involving exposure to danger
▪ the chance or hazard of commercial loss
▪ product of the consequence and probability of a hazardous event or
phenomenon
▪ exposure to a proposition of which one is uncertain
Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Wikipedia ∙ "Defining Risk" by Glen A Holton
https://twitter.com/kcpeppe/status/15473004648
Avoiding complexity
reduces bugs.
Linus Torvalds
Avoiding complexity
reduces vulnerabilities.
Code as Risk
Functional
Operational
Developmental
Connection * CreateServerConnection()
{
// Declarations
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
// Get address and check that its OK (throw an exception if its not)
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert adress to bytes and check that its OK (throw an exception if its not)
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Get port and check that its OK (throw an exception if its not)
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert port too bytes
port = htons(atoi(cfgPort.data()));
// Creation connection and check that its OK (throw an exception if its not)
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Return the connection
return result;
}
Connection * CreateServerConnection()
{
// Declarations
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
// Get address and check that its OK (throw an exception if its not)
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert adress to bytes and check that its OK (throw an exception if its not)
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Get port and check that its OK (throw an exception if its not)
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert port too bytes
port = htons(atoi(cfgPort.data()));
// Creation connection and check that its OK (throw an exception if its not)
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Return the connection
return result;
}
Connection * CreateServerConnection()
{
// Declarations
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
...
}
Connection * CreateServerConnection()
{
...
// Get address and check that its OK (throw an exception if its not)
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Convert adress to bytes and check that its OK (throw an exception if its not)
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Get port and check that its OK (throw an exception if its not)
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Convert port too bytes
port = htons(atoi(cfgPort.data()));
...
}
Connection * CreateServerConnection()
{
...
// Creation connection and check that its OK (throw an exception if its not)
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Return the connection
return result;
}
Connection * CreateServerConnection()
{
// Declarations
...
// Get address and check that its OK (throw an exception if its not)
...
// Convert adress to bytes and check that its OK (throw an exception if its not)
...
// Get port and check that its OK (throw an exception if its not)
...
// Convert port too bytes
...
// Creation connection and check that its OK (throw an exception if its not)
...
// Return the connection
...
}
Connection * CreateServerConnection()
{
// Declarations
...
// Get address and check that it's OK (throw an exception if it's not)
...
// Convert address to bytes and check that it's OK (throw an exception if it's not)
...
// Get port and check that it's OK (throw an exception if it's not)
...
// Convert port to bytes
...
// Creation connection and check that it's OK (throw an exception if it's not)
...
// Return the connection
...
}
Connection * CreateServerConnection()
{
...
...
...
...
...
...
...
}
Connection * CreateServerConnection()
{
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
port = htons(atoi(cfgPort.data()));
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
char buffer[1024];
std::string cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
unsigned long address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
std::string cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
unsigned short port = htons(atoi(cfgPort.data()));
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
Connection * result = new Connection(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
std::auto_ptr<Connection> CreateServerConnection()
{
...
std::auto_ptr<Connection> result(new Connection(address, port));
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
std::unique_ptr<Connection> CreateServerConnection()
{
...
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.c_str()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
printf
eval
evil
https://xkcd.com/327/
Every escape
is an entrance
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
snprintf(buffer, sizeof buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
...
if (cfgAddress.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
if (address == -1)
{
snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
if (cfgAddress.empty())
{
std::stringstream buffer;
buffer << "Configuration value missing: " << "address";
Log::Instance().Write(buffer.str());
throw ConnectionException(buffer.str());
}
...
if (address == -1)
{
std::stringstream buffer;
buffer << "Invalid address: " << cfgAddress;
Log::Instance().Write(buffer.str());
throw ConnectionException(buffer.str());
}
...
}
Connection * CreateServerConnection()
{
...
if (cfgAddress.empty())
{
static const char * logMessage = "Configuration value missing: address";
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
...
if (address == -1)
{
auto logMessage = "Invalid address: " + cfgAddress;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
...
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
static const char * logMessage = "Configuration value missing: address";
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
auto logMessage = "Invalid address: " + cfgAddress;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
static const char * logMessage = "Configuration value missing: port");
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
auto logMessage = "Failed to connect: " + cfgAddress + ":" + cfgPort;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
FailedToConnect("Configuration value missing: address");
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
FailedToConnect("Invalid address: " + cfgAddress);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
FailedToConnect("Configuration value missing: port");
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
}
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
std::unique_ptr<Connection> CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().ValueOf("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().ValueOf("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = Configuration::Instance().ValueOf("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = Configuration::Instance().ValueOf("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
Code as Risk
Early Detection of
Configuration Errors to
Reduce Failure Damage
https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
Our study shows that many of today’s
mature, widely used software systems
are subject to latent configuration
errors in their critically important
configurations.
https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
One root cause is that many (14.0%–
93.2%) of these configurations do not
have any special code for checking
the correctness of their settings at the
system’s initialization time.
https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = Configuration::Instance().ValueOf("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = Configuration::Instance().ValueOf("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer(
const std::string & cfgAddress, const std::string & cfgPort)
{
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
Be conservative in what you
do, be liberal in what you
accept from others.
Postel's law
Be conservative in what you
do, be conservative in what
you accept from others.
std::unique_ptr<Connection> ConnectToServer(
const std::string & cfgAddress, const std::string & cfgPort)
{
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port)
{
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect(address, port);
return result;
}
std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port)
{
return std::make_unique<Connection>(address, port);
}
Code as Risk
Remember that there
is no code faster than
no code.
Taligent's Guide to Designing Programs
Remember that there
is no code more
secure than no code.
http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
var cache = [
'',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '
];
function leftPad (str, len, ch) {
// convert `str` to `string`
str = str + '';
// `len` is the `pad`'s length now
len = len - str.length;
// doesn't need to pad
if (len <= 0) return str;
// `ch` defaults to `' '`
if (!ch && ch !== 0) ch = ' ';
// convert `ch` to `string`
ch = ch + '';
// cache common use cases
if (ch === ' ' && len < 10) return cache[len] + str;
// `pad` starts with an empty string
var pad = '';
// loop
while (true) {
// add `ch` to `pad` if `len` is odd
if (len & 1) pad += ch;
// divide `len` by 2, ditch the remainder
len >>= 1;
// "double" the `ch` so this operation count grows logarithmically on `len`
// each time `ch` is "doubled", the `len` would need to be "doubled" too
// similar to finding a value in binary search tree, hence O(log(n))
if (len) ch += ch;
// `len` is 0, exit the loop
else break;
}
// pad `str`!
return pad + str;
}
I have yet to see any problem,
however complicated, which,
when you looked at it in the
right way, did not become still
more complicated.
Anderson's Law
Code as Risk
https://twitter.com/seldo/status/712414400808755200
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
function leftpad (str, len, ch) {
somethingWickedThisWayComes()
return _leftpad(str, len, ch);
}
Code as Risk
Architectural decisions tend to
concentrate upon identifying and
controlling the seams in a system,
which are described in terms of
interfaces and mechanisms.
Grady Booch
As mankind relies more and more on the
software that controls the computers that
in turn guide society, it becomes crucial
that people control absolutely the
programs and the processes by which they
are produced, throughout the useful life of
the program.
Meir M Lehman
"Programs, Life Cycles, and Laws of Software Evolution"
Goto Fail, Heartbleed,
and Unit Testing Culture
Mike Bland
https://martinfowler.com/articles/testing-culture.html
These bugs are as instructive as they
were devastating:They were rooted
in the same programmer optimism,
overconfidence, and haste that strike
projects of all sizes and domains.
Mike Bland
https://martinfowler.com/articles/testing-culture.html
These bugs arouse my passion because I've
seen and lived the benefits of unit testing,
and this strongly-imprinted experience
compels me to reflect on how unit testing
approaches could prevent defects as high-
impact and high-profile as these SSL bugs.
Mike Bland
https://martinfowler.com/articles/testing-culture.html
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
var cache = [
'',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '
];
function leftPad (str, len, ch) {
// convert `str` to `string`
str = str + '';
// `len` is the `pad`'s length now
len = len - str.length;
// doesn't need to pad
if (len <= 0) return str;
// `ch` defaults to `' '`
if (!ch && ch !== 0) ch = ' ';
// convert `ch` to `string`
ch = ch + '';
// cache common use cases
if (ch === ' ' && len < 10) return cache[len] + str;
// `pad` starts with an empty string
var pad = '';
// loop
while (true) {
// add `ch` to `pad` if `len` is odd
if (len & 1) pad += ch;
// divide `len` by 2, ditch the remainder
len >>= 1;
// "double" the `ch` so this operation count grows logarithmically on `len`
// each time `ch` is "doubled", the `len` would need to be "doubled" too
// similar to finding a value in binary search tree, hence O(log(n))
if (len) ch += ch;
// `len` is 0, exit the loop
else break;
}
// pad `str`!
return pad + str;
}
function leftpad(content, length, pad) {
content = String(content)
pad = String(pad || pad === 0 ? pad : ' ')[0]
var left = Math.max(length - content.length, 0)
return pad.repeat(left) + content
}
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
toMap = object => new Map(Object.entries(object))
format = (proposition, ok) =>
proposition.fontcolor(ok ? "green" : "red") + "<br>"
present = truths =>
toMap(truths).forEach(
(ok, proposition) => write(format(proposition, ok)))
present(truths)
Padding an empty string to a length of 0 results in an empty string
Padding a non-empty string to a shorter length results in the same string
Padding a non-empty string to a negative length results in the same string
Padding a non-empty string to its length results in the same string
Padding to a longer length with a single character fills to the left
Padding to a longer length with surplus characters fills using only first
Padding to a longer length with an empty string fills with space
Padding to a longer length with no specified fill fills with space
Padding to a longer length with integer 0 fills with 0
Padding to a longer length with single-digit integer fills with digit
Padding to a longer length with multiple-digit integer fills with first digit
Padding to a longer length with negative integer fills with -
Padding a non-string uses string representation
Padding an empty string to a length of 0 results in an empty string
Padding a non-empty string to a shorter length results in the same string
Padding a non-empty string to a negative length results in the same string
Padding a non-empty string to its length results in the same string
Padding to a longer length with a single character fills to the left
Padding to a longer length with surplus characters fills using only first
Padding to a longer length with an empty string fills with space
Padding to a longer length with no specified fill fills with space
Padding to a longer length with integer 0 fills with 0
Padding to a longer length with single-digit integer fills with digit
Padding to a longer length with multiple-digit integer fills with first digit
Padding to a longer length with negative integer fills with -
Padding a non-string uses string representation
Testing Is the
Engineering
Rigor of Software
Development
Neal Ford
passive
POUT Plain
Ol'
Unit
Testing
POUT
active
POUT
TDD Test-
Driven
Development
POUT
TDD
reactive
POUT
TDD
DDT
Defect-
Driven
Testing
Simple Testing Can Prevent
Most Critical Failures
An Analysis of Production Failures in
Distributed Data-Intensive Systems
https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
Almost all catastrophic failures
are the result of incorrect
handling of non-fatal errors
explicitly signalled in software.
https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
A majority of the production
failures (77%) can be
reproduced by a unit test.
https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
Code as Risk
Firmitas
Utilitas
Venustas

More Related Content

PPTX
Project in programming
PDF
Deterministic simulation testing
PDF
Architecture for Massively Parallel HDL Simulations
PDF
Zone IDA Proc
PDF
Checking Wine with PVS-Studio and Clang Static Analyzer
PDF
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
PDF
Coroutines in Kotlin. UA Mobile 2017.
PDF
Kamil witecki asynchronous, yet readable, code
Project in programming
Deterministic simulation testing
Architecture for Massively Parallel HDL Simulations
Zone IDA Proc
Checking Wine with PVS-Studio and Clang Static Analyzer
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
Coroutines in Kotlin. UA Mobile 2017.
Kamil witecki asynchronous, yet readable, code

What's hot (20)

PDF
A Slipshod Check of the Visual C++ 2013 Library (update 3)
PDF
Rop and it's friends
KEY
PPT
2016年のPerl (Long version)
PDF
Qt Rest Server
PDF
Overpsss API / Overpass-Turbo
PDF
Hello, Is That FreeSWITCH? Then We're Coming to Check You!
PDF
Clang tidy
PDF
One definition rule - что это такое, и как с этим жить
PPT
bluespec talk
PDF
Vladimir Vorontsov - Splitting, smuggling and cache poisoning come back
PDF
ssh.isdn.test
PDF
Handling inline assembly in Clang and LLVM
PDF
Design your client: go way
PDF
An introduction to PHP 5.4
PDF
Global Interpreter Lock: Episode I - Break the Seal
PPTX
Hack ASP.NET website
PDF
Sandboxie process isolation with kernel hooks
PDF
Continuous testing In PHP
PDF
systems programming lab programs in c
A Slipshod Check of the Visual C++ 2013 Library (update 3)
Rop and it's friends
2016年のPerl (Long version)
Qt Rest Server
Overpsss API / Overpass-Turbo
Hello, Is That FreeSWITCH? Then We're Coming to Check You!
Clang tidy
One definition rule - что это такое, и как с этим жить
bluespec talk
Vladimir Vorontsov - Splitting, smuggling and cache poisoning come back
ssh.isdn.test
Handling inline assembly in Clang and LLVM
Design your client: go way
An introduction to PHP 5.4
Global Interpreter Lock: Episode I - Break the Seal
Hack ASP.NET website
Sandboxie process isolation with kernel hooks
Continuous testing In PHP
systems programming lab programs in c
Ad

Similar to Code as Risk (20)

PDF
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
PPTX
Gnu linux for safety related systems
PDF
dist_systems.pdf
PDF
The hangover: A "modern" (?) high performance approach to build an offensive ...
PPTX
Highly dependable automotive software
PDF
Monitoring using Sensu
PDF
Protocol T50: Five months later... So what?
PDF
Secure Coding Practices for Middleware
PPTX
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
PPT
Lecture07_FaultTolerance in parallel and distributing
PPT
Lecture07_FaultTolerance in parallel and distributed
PDF
Joe armstrong erlanga_languageforprogrammingreliablesystems
PDF
Server Tips
PPT
Distributed Checkpointing on an Enterprise Desktop Grid
PDF
Tips on High Performance Server Programming
PDF
Parsing and Type checking all 2^10000 configurations of the Linux kernel
PDF
Singularity
PDF
On the Effectiveness of Type-based Control Flow Integrity
PDF
RIoT (Raiding Internet of Things) by Jacob Holcomb
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Gnu linux for safety related systems
dist_systems.pdf
The hangover: A "modern" (?) high performance approach to build an offensive ...
Highly dependable automotive software
Monitoring using Sensu
Protocol T50: Five months later... So what?
Secure Coding Practices for Middleware
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
Lecture07_FaultTolerance in parallel and distributing
Lecture07_FaultTolerance in parallel and distributed
Joe armstrong erlanga_languageforprogrammingreliablesystems
Server Tips
Distributed Checkpointing on an Enterprise Desktop Grid
Tips on High Performance Server Programming
Parsing and Type checking all 2^10000 configurations of the Linux kernel
Singularity
On the Effectiveness of Type-based Control Flow Integrity
RIoT (Raiding Internet of Things) by Jacob Holcomb
Ad

More from Kevlin Henney (20)

PDF
Program with GUTs
PDF
The Case for Technical Excellence
PDF
Empirical Development
PDF
Lambda? You Keep Using that Letter
PDF
Lambda? You Keep Using that Letter
PDF
Solid Deconstruction
PDF
Get Kata
PDF
Procedural Programming: It’s Back? It Never Went Away
PDF
Structure and Interpretation of Test Cases
PDF
Agility ≠ Speed
PDF
Refactoring to Immutability
PDF
Old Is the New New
PDF
Turning Development Outside-In
PDF
Giving Code a Good Name
PDF
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
PDF
Thinking Outside the Synchronisation Quadrant
PDF
Software Is Details
PDF
Game of Sprints
PDF
Good Code
PDF
The Error of Our Ways
Program with GUTs
The Case for Technical Excellence
Empirical Development
Lambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Solid Deconstruction
Get Kata
Procedural Programming: It’s Back? It Never Went Away
Structure and Interpretation of Test Cases
Agility ≠ Speed
Refactoring to Immutability
Old Is the New New
Turning Development Outside-In
Giving Code a Good Name
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Thinking Outside the Synchronisation Quadrant
Software Is Details
Game of Sprints
Good Code
The Error of Our Ways

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Nekopoi APK 2025 free lastest update
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
top salesforce developer skills in 2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
System and Network Administration Chapter 2
Navsoft: AI-Powered Business Solutions & Custom Software Development
Operating system designcfffgfgggggggvggggggggg
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Nekopoi APK 2025 free lastest update
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
top salesforce developer skills in 2025.pdf
CHAPTER 2 - PM Management and IT Context
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo POS Development Services by CandidRoot Solutions
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
System and Network Administration Chapter 2

Code as Risk

  • 17. if ((err = ReadyHash(&SSLHashSHA1, &hashCtx)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &clientRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail; Mike Bland "Goto Fail, Heartbleed, and Unit Testing Culture" https://martinfowler.com/articles/testing-culture.html
  • 18. network code() { switch (line) { case THING1: doit1(); break; case THING2: if (x == STUFF) { do_first_stuff(); if (y == OTHER_STUFF) break; do_later_stuff(); } /* coder meant to break to here... */ initialize_modes_pointer(); break; default: processing(); } /* ...but actually broke to here! */ use_modes_pointer(); /* leaving the modes_pointer uninitialized */ } Peter van der Linden Expert C Programming
  • 19. Most of our systems are much more complicated than can be considered healthy, and are too messy and chaotic to be used in comfort and confidence. Edsger W Dijkstra
  • 21. There are standard precautions that can help reduce risk in complex software systems. This includes the definition of a good software architecture based on a clean separation of concerns, data hiding, modularity, well-defined interfaces, and strong fault-protection mechanisms. Gerard J Holzmann http://cacm.acm.org/magazines/2014/2/171689-mars-code/fulltext
  • 23. code, noun ▪ a set of instructions for a computer ▪ a computer program, or a portion thereof ▪ a system of words, figures or symbols used to represent others, especially for the purposes of secrecy ▪ a set of conventions or principles governing behaviour or activity in a particular domain Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
  • 24. risk, noun ▪ a situation involving exposure to danger ▪ the chance or hazard of commercial loss ▪ product of the consequence and probability of a hazardous event or phenomenon ▪ exposure to a proposition of which one is uncertain Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Wikipedia ∙ "Defining Risk" by Glen A Holton
  • 30. Connection * CreateServerConnection() { // Declarations char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; // Get address and check that its OK (throw an exception if its not) cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert adress to bytes and check that its OK (throw an exception if its not) address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Get port and check that its OK (throw an exception if its not) cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert port too bytes port = htons(atoi(cfgPort.data())); // Creation connection and check that its OK (throw an exception if its not) result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Return the connection return result; }
  • 31. Connection * CreateServerConnection() { // Declarations char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; // Get address and check that its OK (throw an exception if its not) cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert adress to bytes and check that its OK (throw an exception if its not) address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Get port and check that its OK (throw an exception if its not) cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert port too bytes port = htons(atoi(cfgPort.data())); // Creation connection and check that its OK (throw an exception if its not) result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Return the connection return result; }
  • 32. Connection * CreateServerConnection() { // Declarations char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; ... }
  • 33. Connection * CreateServerConnection() { ... // Get address and check that its OK (throw an exception if its not) cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 34. Connection * CreateServerConnection() { ... // Convert adress to bytes and check that its OK (throw an exception if its not) address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 35. Connection * CreateServerConnection() { ... // Get port and check that its OK (throw an exception if its not) cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 36. Connection * CreateServerConnection() { ... // Convert port too bytes port = htons(atoi(cfgPort.data())); ... }
  • 37. Connection * CreateServerConnection() { ... // Creation connection and check that its OK (throw an exception if its not) result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 38. Connection * CreateServerConnection() { ... // Return the connection return result; }
  • 39. Connection * CreateServerConnection() { // Declarations ... // Get address and check that its OK (throw an exception if its not) ... // Convert adress to bytes and check that its OK (throw an exception if its not) ... // Get port and check that its OK (throw an exception if its not) ... // Convert port too bytes ... // Creation connection and check that its OK (throw an exception if its not) ... // Return the connection ... }
  • 40. Connection * CreateServerConnection() { // Declarations ... // Get address and check that it's OK (throw an exception if it's not) ... // Convert address to bytes and check that it's OK (throw an exception if it's not) ... // Get port and check that it's OK (throw an exception if it's not) ... // Convert port to bytes ... // Creation connection and check that it's OK (throw an exception if it's not) ... // Return the connection ... }
  • 42. Connection * CreateServerConnection() { char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } port = htons(atoi(cfgPort.data())); result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 43. Connection * CreateServerConnection() { char buffer[1024]; std::string cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } unsigned long address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } std::string cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } unsigned short port = htons(atoi(cfgPort.data())); Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 44. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 45. Connection * CreateServerConnection() { ... Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 46. Connection * CreateServerConnection() { ... Connection * result = new Connection(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 47. std::auto_ptr<Connection> CreateServerConnection() { ... std::auto_ptr<Connection> result(new Connection(address, port)); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 48. std::unique_ptr<Connection> CreateServerConnection() { ... auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 49. Connection * CreateServerConnection() { ... auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 50. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 51. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 52. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.c_str())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 53. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 54. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 56. eval
  • 57. evil
  • 59. Every escape is an entrance
  • 60. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 61. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { snprintf(buffer, sizeof buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 62. Connection * CreateServerConnection() { char buffer[1024]; ... if (cfgAddress.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... if (address == -1) { snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 63. Connection * CreateServerConnection() { ... if (cfgAddress.empty()) { std::stringstream buffer; buffer << "Configuration value missing: " << "address"; Log::Instance().Write(buffer.str()); throw ConnectionException(buffer.str()); } ... if (address == -1) { std::stringstream buffer; buffer << "Invalid address: " << cfgAddress; Log::Instance().Write(buffer.str()); throw ConnectionException(buffer.str()); } ... }
  • 64. Connection * CreateServerConnection() { ... if (cfgAddress.empty()) { static const char * logMessage = "Configuration value missing: address"; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } ... if (address == -1) { auto logMessage = "Invalid address: " + cfgAddress; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } ... }
  • 65. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { static const char * logMessage = "Configuration value missing: address"; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { auto logMessage = "Invalid address: " + cfgAddress; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { static const char * logMessage = "Configuration value missing: port"); Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { auto logMessage = "Failed to connect: " + cfgAddress + ":" + cfgPort; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } return result.release(); }
  • 66. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { FailedToConnect("Configuration value missing: address"); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { FailedToConnect("Invalid address: " + cfgAddress); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { FailedToConnect("Configuration value missing: port"); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); } return result.release(); }
  • 67. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 68. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 69. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 70. std::unique_ptr<Connection> CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 71. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 72. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 73. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().ValueOf("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().ValueOf("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 74. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = Configuration::Instance().ValueOf("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = Configuration::Instance().ValueOf("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 76. Early Detection of Configuration Errors to Reduce Failure Damage https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
  • 77. Our study shows that many of today’s mature, widely used software systems are subject to latent configuration errors in their critically important configurations. https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
  • 78. One root cause is that many (14.0%– 93.2%) of these configurations do not have any special code for checking the correctness of their settings at the system’s initialization time. https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf
  • 79. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = Configuration::Instance().ValueOf("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = Configuration::Instance().ValueOf("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 80. std::unique_ptr<Connection> ConnectToServer( const std::string & cfgAddress, const std::string & cfgPort) { if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 81. Be conservative in what you do, be liberal in what you accept from others. Postel's law
  • 82. Be conservative in what you do, be conservative in what you accept from others.
  • 83. std::unique_ptr<Connection> ConnectToServer( const std::string & cfgAddress, const std::string & cfgPort) { if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 84. std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port) { auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect(address, port); return result; }
  • 85. std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port) { return std::make_unique<Connection>(address, port); }
  • 87. Remember that there is no code faster than no code. Taligent's Guide to Designing Programs
  • 88. Remember that there is no code more secure than no code.
  • 90. function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str; }
  • 91. var cache = [ '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' ]; function leftPad (str, len, ch) { // convert `str` to `string` str = str + ''; // `len` is the `pad`'s length now len = len - str.length; // doesn't need to pad if (len <= 0) return str; // `ch` defaults to `' '` if (!ch && ch !== 0) ch = ' '; // convert `ch` to `string` ch = ch + ''; // cache common use cases if (ch === ' ' && len < 10) return cache[len] + str; // `pad` starts with an empty string var pad = ''; // loop while (true) { // add `ch` to `pad` if `len` is odd if (len & 1) pad += ch; // divide `len` by 2, ditch the remainder len >>= 1; // "double" the `ch` so this operation count grows logarithmically on `len` // each time `ch` is "doubled", the `len` would need to be "doubled" too // similar to finding a value in binary search tree, hence O(log(n)) if (len) ch += ch; // `len` is 0, exit the loop else break; } // pad `str`! return pad + str; }
  • 92. I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated. Anderson's Law
  • 95. function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str; }
  • 96. function leftpad (str, len, ch) { somethingWickedThisWayComes() return _leftpad(str, len, ch); }
  • 98. Architectural decisions tend to concentrate upon identifying and controlling the seams in a system, which are described in terms of interfaces and mechanisms. Grady Booch
  • 99. As mankind relies more and more on the software that controls the computers that in turn guide society, it becomes crucial that people control absolutely the programs and the processes by which they are produced, throughout the useful life of the program. Meir M Lehman "Programs, Life Cycles, and Laws of Software Evolution"
  • 100. Goto Fail, Heartbleed, and Unit Testing Culture Mike Bland https://martinfowler.com/articles/testing-culture.html
  • 101. These bugs are as instructive as they were devastating:They were rooted in the same programmer optimism, overconfidence, and haste that strike projects of all sizes and domains. Mike Bland https://martinfowler.com/articles/testing-culture.html
  • 102. These bugs arouse my passion because I've seen and lived the benefits of unit testing, and this strongly-imprinted experience compels me to reflect on how unit testing approaches could prevent defects as high- impact and high-profile as these SSL bugs. Mike Bland https://martinfowler.com/articles/testing-culture.html
  • 103. function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str; }
  • 104. var cache = [ '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' ]; function leftPad (str, len, ch) { // convert `str` to `string` str = str + ''; // `len` is the `pad`'s length now len = len - str.length; // doesn't need to pad if (len <= 0) return str; // `ch` defaults to `' '` if (!ch && ch !== 0) ch = ' '; // convert `ch` to `string` ch = ch + ''; // cache common use cases if (ch === ' ' && len < 10) return cache[len] + str; // `pad` starts with an empty string var pad = ''; // loop while (true) { // add `ch` to `pad` if `len` is odd if (len & 1) pad += ch; // divide `len` by 2, ditch the remainder len >>= 1; // "double" the `ch` so this operation count grows logarithmically on `len` // each time `ch` is "doubled", the `len` would need to be "doubled" too // similar to finding a value in binary search tree, hence O(log(n)) if (len) ch += ch; // `len` is 0, exit the loop else break; } // pad `str`! return pad + str; }
  • 105. function leftpad(content, length, pad) { content = String(content) pad = String(pad || pad === 0 ? pad : ' ')[0] var left = Math.max(length - content.length, 0) return pad.repeat(left) + content }
  • 106. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 107. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 108. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 109. toMap = object => new Map(Object.entries(object)) format = (proposition, ok) => proposition.fontcolor(ok ? "green" : "red") + "<br>" present = truths => toMap(truths).forEach( (ok, proposition) => write(format(proposition, ok))) present(truths)
  • 110. Padding an empty string to a length of 0 results in an empty string Padding a non-empty string to a shorter length results in the same string Padding a non-empty string to a negative length results in the same string Padding a non-empty string to its length results in the same string Padding to a longer length with a single character fills to the left Padding to a longer length with surplus characters fills using only first Padding to a longer length with an empty string fills with space Padding to a longer length with no specified fill fills with space Padding to a longer length with integer 0 fills with 0 Padding to a longer length with single-digit integer fills with digit Padding to a longer length with multiple-digit integer fills with first digit Padding to a longer length with negative integer fills with - Padding a non-string uses string representation
  • 111. Padding an empty string to a length of 0 results in an empty string Padding a non-empty string to a shorter length results in the same string Padding a non-empty string to a negative length results in the same string Padding a non-empty string to its length results in the same string Padding to a longer length with a single character fills to the left Padding to a longer length with surplus characters fills using only first Padding to a longer length with an empty string fills with space Padding to a longer length with no specified fill fills with space Padding to a longer length with integer 0 fills with 0 Padding to a longer length with single-digit integer fills with digit Padding to a longer length with multiple-digit integer fills with first digit Padding to a longer length with negative integer fills with - Padding a non-string uses string representation
  • 112. Testing Is the Engineering Rigor of Software Development Neal Ford
  • 119. Simple Testing Can Prevent Most Critical Failures An Analysis of Production Failures in Distributed Data-Intensive Systems https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
  • 120. Almost all catastrophic failures are the result of incorrect handling of non-fatal errors explicitly signalled in software. https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf
  • 121. A majority of the production failures (77%) can be reproduced by a unit test. https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf