Fix: program safety (zero-init some input buffers) + program args
This commit is contained in:
@@ -25,6 +25,8 @@ char* motd[] =
|
||||
};
|
||||
int motd_size = sizeof(motd)/sizeof(motd[0]);
|
||||
|
||||
bool do_splash = true;
|
||||
|
||||
void splash()
|
||||
{
|
||||
int random = randint(time_seed());
|
||||
@@ -87,7 +89,11 @@ int parse_input(char* input, char* argv[], int max_args)
|
||||
|
||||
void shell_install()
|
||||
{
|
||||
splash();
|
||||
if (do_splash == true)
|
||||
{
|
||||
do_splash = false;
|
||||
splash();
|
||||
}
|
||||
|
||||
register_command("help", program_help);
|
||||
register_command("panic", program_panic);
|
||||
|
||||
@@ -56,12 +56,35 @@ void dtostrf(double val, char *buffer, int precision);
|
||||
enum Colors
|
||||
{
|
||||
// AARRGGBB?
|
||||
white = 0xFFFFFFFF,
|
||||
black = 0x00000000,
|
||||
red = 0x00FF0000,
|
||||
green = 0x0000FF00,
|
||||
blue = 0x000000FF,
|
||||
yellow = 0x00FFFF00,
|
||||
white = 0xFFFFFFFF,
|
||||
black = 0x00000000,
|
||||
red = 0x00FF0000,
|
||||
green = 0x0000FF00,
|
||||
blue = 0x000000FF,
|
||||
yellow = 0x00FFFF00,
|
||||
cyan = 0x0000FFFF,
|
||||
magenta = 0x00FF00FF,
|
||||
orange = 0x00FFA500,
|
||||
purple = 0x00800080,
|
||||
brown = 0x00A52A2A,
|
||||
gray = 0x00808080,
|
||||
pink = 0x00FFC0CB,
|
||||
lime = 0x00BFFF00,
|
||||
navy = 0x00000080,
|
||||
teal = 0x00008080,
|
||||
maroon = 0x00800000,
|
||||
olive = 0x00808000,
|
||||
silver = 0x00C0C0C0,
|
||||
gold = 0x00FFD700,
|
||||
indigo = 0x004B0082,
|
||||
violet = 0x00EE82EE,
|
||||
coral = 0x00FF7F50,
|
||||
turquoise = 0x0040E0D0,
|
||||
salmon = 0x00FA8072,
|
||||
chocolate = 0x00D2691E,
|
||||
khaki = 0x00F0E68C,
|
||||
lavender = 0x00E6E6FA,
|
||||
beige = 0x00F5F5DC
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,14 +29,27 @@ void rot13(char* input, char* output)
|
||||
output[i] = '\0';
|
||||
}
|
||||
|
||||
void program_rot13()
|
||||
void program_rot13(int argc, char* argv[])
|
||||
{
|
||||
char input_buffer[BUFFER_SIZE];
|
||||
char output[BUFFER_SIZE];
|
||||
puts("String? ");
|
||||
get_input(input_buffer, BUFFER_SIZE);
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Usage: %s <string>\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
char input_buffer[BUFFER_SIZE] = {0};
|
||||
char output[BUFFER_SIZE] = {0};
|
||||
|
||||
for (int i=1; i<argc; i++)
|
||||
{
|
||||
strcat(input_buffer, argv[i]);
|
||||
if (i<argc-1)
|
||||
{
|
||||
strcat(input_buffer, " ");
|
||||
}
|
||||
}
|
||||
rot13(input_buffer, output);
|
||||
printf("\n%s\n", output);
|
||||
printf("%s\n", output);
|
||||
}
|
||||
|
||||
const char* morse_alphabet[] = {
|
||||
@@ -121,12 +134,27 @@ void to_morse(const char* input, char* output) {
|
||||
}
|
||||
}
|
||||
|
||||
void program_morse() {
|
||||
void program_morse(int argc, char* argv[]) {
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Usage: %s <string>\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
char output[512];
|
||||
char input_buffer[BUFFER_SIZE];
|
||||
puts("String? ");
|
||||
get_input(input_buffer, BUFFER_SIZE);
|
||||
to_morse(input_buffer, output);
|
||||
printf("\n%s\n", output);
|
||||
char message[BUFFER_SIZE];
|
||||
|
||||
for (int i=1; i<argc; i++)
|
||||
{
|
||||
strcat(message, argv[i]);
|
||||
if (i < argc-1)
|
||||
{
|
||||
strcat(message, " ");
|
||||
}
|
||||
}
|
||||
|
||||
to_morse(message, output);
|
||||
printf("%s\n", output);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,37 @@
|
||||
#define BUF_SIZE 256
|
||||
#define COLORS 20
|
||||
|
||||
void program_rainbow()
|
||||
void program_rainbow(int argc, char* argv[])
|
||||
{
|
||||
char input_buffer[BUF_SIZE];
|
||||
puts("What to print? ");
|
||||
get_input(input_buffer, BUF_SIZE);
|
||||
puts("\n");
|
||||
|
||||
for (int i=0; i<COLORS; i++)
|
||||
if (argc < 2)
|
||||
{
|
||||
//colorputs(input_buffer, i);
|
||||
printf("Usage: %s <string>\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
char input_buffer[BUF_SIZE] = {0};
|
||||
for (int i=1; i<argc; i++)
|
||||
{
|
||||
strcat(input_buffer, argv[i]);
|
||||
if (i<argc-1)
|
||||
{
|
||||
strcat(input_buffer, " ");
|
||||
}
|
||||
}
|
||||
|
||||
enum Colors colors[] = {
|
||||
white, black, red, green, blue, yellow,
|
||||
cyan, magenta, orange, purple, brown,
|
||||
gray, pink, lime, navy, teal, maroon,
|
||||
olive, silver, gold, indigo, violet,
|
||||
coral, turquoise, salmon, chocolate,
|
||||
khaki, lavender, beige
|
||||
};
|
||||
int colors_count = sizeof(colors)/sizeof(colors[0]);
|
||||
|
||||
for (int i=0; i<colors_count-1; i++)
|
||||
{
|
||||
colorputs(input_buffer, colors[i], colors[i+1]);
|
||||
puts("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user