Coder Social home page Coder Social logo

smaugfuss's People

Contributors

arthmoor avatar hatetank avatar infiniteaxis avatar radamanthas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smaugfuss's Issues

Casting the int result of fgetc to char before comparison with EOF isn't safe

http://c-faq.com/stdio/getcharc.html

Apparently it's somewhat common for people to try to run SmaugFUSS on ARM devices like Raspberry Pis, which have unsigned chars, not signed chars, and then get confused when it sort of looks like it's working but then errors in weird ways.

If char is unsigned, then code like

SmaugFUSS/src/act_comm.c

Lines 2461 to 2466 in b76ca68

char BUFF[MAX_STRING_LENGTH * 2];
if( ( rpfile = fopen( RIPSCREEN_FILE, "r" ) ) != NULL )
{
while( ( BUFF[num] = fgetc( rpfile ) ) != EOF )
num++;

overruns its buffer, because fgetc returns an int, not a char, which then gets converted from signed -1 to unsigned 255, and EOF is -1, which means the comparison always fails.

See also https://www.raspberrypi.org/forums/viewtopic.php?t=217769

Weather buffer overflows

Based purely on visual inspection of the code, various places in weather.c appear to read and write past the end of the weatherMap storage.

I think

SmaugFUSS/src/weather.c

Lines 3086 to 3096 in d86556c

if( x < 0 || x > WEATHER_SIZE_X )
{
ch_printf( ch, "X value must be between 0 and %d.\r\n", WEATHER_SIZE_X );
return;
}
if( y < 0 || y > WEATHER_SIZE_Y )
{
ch_printf( ch, "Y value must be between 0 and %d.\r\n", WEATHER_SIZE_Y );
return;
}

should be

   if( x < 0 || x >= WEATHER_SIZE_X )
   {
      ch_printf( ch, "X value must be between 0 and %d.\r\n", WEATHER_SIZE_X-1 );
      return;
   }

   if( y < 0 || y >= WEATHER_SIZE_Y )
   {
      ch_printf( ch, "Y value must be between 0 and %d.\r\n", WEATHER_SIZE_Y-1 );
      return;
   }

and

SmaugFUSS/src/weather.c

Lines 752 to 753 in d86556c

x = number_range( 0, WEATHER_SIZE_X );
y = number_range( 0, WEATHER_SIZE_Y );

should be

   x = number_range( 0, WEATHER_SIZE_X-1 );
   y = number_range( 0, WEATHER_SIZE_Y-1 );

Non-dynamic buffer sizes are...weird and dangerous

In #2 I mentioned

SmaugFUSS/src/act_comm.c

Lines 2461 to 2466 in b76ca68

char BUFF[MAX_STRING_LENGTH * 2];
if( ( rpfile = fopen( RIPSCREEN_FILE, "r" ) ) != NULL )
{
while( ( BUFF[num] = fgetc( rpfile ) ) != EOF )
num++;
which uses char BUFF[MAX_STRING_LENGTH * 2];. SmaugFUSS often does this in the context of reading file contents, but if the file is larger than MAX_STRING_LENGTH*2, the linked code will smash through the end of that buffer. It would be safer to make the buffer the actual size of the contents it's supposed to hold.

(Also, what does it mean for a string to be twice the max length? Isn't the max length then not the max?)

Now you could say "that file should never be so large", and maybe, but some of the people who are trying to run SmaugFUSS don't know what that means, and some may even unwittingly modify MAX_STRING_LENGTH to be smaller.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.