Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/kernel/kshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ bool alt_mode = false;
bool ctrl_mode = false;
bool super_mode = false;

char history_data[100][RDL_SIZE];
uint8_t tot_cmds=0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer you keep this in some sort of dynamic data structure, rather than a list - not just for cleanliness, but because this implementation is rife with data overflow opportunities. - for instance, you never bounds check on tot_cmds

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a dynamic list to resolve the overflow problem.


void run_cmd(char *run) {
if (!(strncmp(run, "page 0x", 7))) {
show_page_table_layout_for_address(hex2int(run+7));
Expand Down Expand Up @@ -135,6 +138,13 @@ void run_cmd(char *run) {
}
} else if (!strncmp(run, "tree ", 5)) {
tree(run + 5);
}
else if (!strncmp(run, "history", 7)){
for(int i=0;i<tot_cmds;i++){
write_num(i+1);
kprintf(" %05s",history_data[i]);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 1 kprintf for this line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compressed my code to 1 line kprintf.

kprintf("\n");
}
} else {
kprintf("INVALID COMMAND\n");
}
Expand Down Expand Up @@ -184,12 +194,17 @@ void kshell(unsigned char key) {
if (up) {
int i;
kprintf("\n");
for (i = 0; i < rdl_index; i++)
{
history_data[tot_cmds][i]=readline[i];
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a memcpy implementation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied data using memcpy and reduced the no. of lines.

run_cmd(readline);
rdl_index = 0;
for(i=0;i<RDL_SIZE;i++) {
readline[i] = 0;
}
kprintf("%04s", "SOS$ ");
tot_cmds++;
}
break;

Expand Down