Technorama

An omnibus of tech posts by a Futurologist on software development primarily.

Monday 6 May 2024

 

The Next Pandemic

Given we've had coronavirus circulating for thousands of years, and various outbreaks like SARS (2002), MERS (2012) and COVID (2019) it looks like given the global nature of travel we'll have another epidemic like SARS or a pandemic like COVID within a range of 6-10 years, the confidence of this date prediction is not high.


Thursday 12 October 2023

 

Secure sandboxes

 Seems easy, iPhone keeps getting malware owned by faulty image files.


Sandbox decoders


Run decompressors in a micro sandboxed VM. It it doesn't finish decoding and outputting an uncompressed bitmap file to a ramdrive within one second, just kill the sandbox. Saves being exploited. (Unless the sandbox VM can also be jailbreaked)


Compile the process in the sandbox with AddressSanitizer.


Have a system to automatically upload any coredumps from the sandbox crashes, either then, or after a reboot.

Probably those creating the security exploits will test on real devices a few times before they get a working crack. That gives you chance to get the coredump and backtrace.




Wednesday 6 September 2023

 

gcc attribute nonnull considered harmful

gcc function attributes allow optimizer hints, set attribute nonnull and the optimizer will know it is never going to be a nullptr - so it will remove all nullptr checks!

This is often not what is expected by the humble programmer.


Monday 10 April 2023

 

Chromium debug build with symbols

 Navigate here

Click "Last Modified" heading


Then get the build folder number from the file LAST_CHANGE


Tuesday 21 February 2023

 

Custom C/C++ assert example with file line and column information

 // -fanalyzer -DNDEBUG -Wno-analyzer-use-of-uninitialized-value


#include <string>
#include <iostream>
#include <string_view>
#include <source_location>

// Pass const std::source_location location = std::source_location::current()
#if NDEBUG
#define myassert(x, s, l)
#else
#define myassert(x, s, l) if(!x) {printf("%s:%d:%d %s %s\n", l.file_name(), l.line(), l.column(), l.function_name(), s); fflush(stdout); abort();}
#endif

#define TRIGGER_NULLPTR_WARNING 1

std::string make_std_string(const char * const str, const std::source_location location =
std::source_location::current())
{
myassert((nullptr != str), "nullptr dereference", location);

#if TRIGGER_NULLPTR_WARNING
// This line ensures: warning: dereference of NULL '0' [CWE-476] [-Wanalyzer-null-dereference]
char b = *str;
#endif

std::string s(str);
#if TRIGGER_NULLPTR_WARNING
s[0] = b;
#endif

return s;
}

int main()
{
const char * a = NULL;
std::string result = make_std_string(a);
std::cout << result;
}


Thursday 16 February 2023

 

Use macros to contatenate file and line info into a string so easier to see when debugging particular issues with unique info per function.

Unfortunately __FUNCTION__ doesn't work this way though.

#define xto_str(s) to_str(s)

#define to_str(s) #s

int main()
{
const char * s = __FILE__ ":" xto_str(__LINE__);
__builtin_printf(s);
}

.LC0:
.string "/app/example.cpp:__PRETTY_FUNCTION__"
main:
subq $8, %rsp
movl $.LC0, %edi
xorl %eax, %eax
call printf
xorl %eax, %eax
addq $8, %rsp
ret

Wednesday 1 February 2023

 

Safe C/C++

// Example showing usual way to check parameters are valid to avoid crashing in
// a Release build, and an assert() for a Debug build.

// Some might argue that assert() creates different behaviour in a DEBUG build.
// It means the error handling will never be exercised in a DEBUG build that
// does abort() core dump.
// testsuite must be run in a RELEASE build, to be sure the error handling
// is exercised and good coverage.
// Of course, also application integration tests would run in RELEASE build
// and verify application is fully working.
// It is also fine to leave out the assert() and can verify test suite results
// in a DEBUG build then

#include <assert.h>
#include <stddef.h>
#include <stdio.h>

int example_if(const char * str)
{
assert(str);

if(NULL == str)
{
return -1;
}
else
{
printf("%s\n", str);
}

return 0;
}

int main()
{
example_if(NULL);
}

Archives

February 2003   March 2003   April 2003   August 2004   September 2004   December 2004   May 2005   June 2005   December 2006   January 2007   February 2007   March 2007   April 2007   July 2007   August 2007   September 2007   October 2007   November 2007   December 2007   January 2008   February 2008   March 2008   April 2008   May 2008   June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   April 2009   September 2009   November 2009   December 2009   January 2010   April 2010   September 2010   October 2010   November 2010   December 2010   January 2011   February 2011   March 2011   April 2011   May 2011   June 2011   July 2011   August 2011   September 2011   October 2011   November 2011   December 2011   January 2012   February 2012   March 2012   April 2012   May 2012   June 2012   July 2012   October 2012   December 2012   March 2013   May 2013   August 2013   September 2013   October 2013   November 2013   March 2014   May 2014   June 2014   July 2014   September 2014   October 2014   December 2014   January 2015   February 2015   March 2015   April 2015   May 2015   June 2015   July 2015   August 2015   September 2015   October 2015   November 2015   December 2015   March 2016   April 2016   May 2016   July 2016   August 2016   September 2016   October 2016   November 2016   December 2016   January 2017   February 2017   March 2017   April 2017   May 2017   June 2017   July 2017   August 2017   September 2017   November 2017   March 2018   April 2018   May 2018   June 2018   August 2018   October 2018   December 2018   January 2019   March 2019   May 2019   August 2019   September 2019   March 2020   April 2020   May 2020   September 2020   October 2020   February 2022   June 2022   July 2022   October 2022   December 2022   February 2023   April 2023   September 2023   October 2023   May 2024  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]