1
0
Fork 0

Fix NULL issues in shell code

This commit is contained in:
krcroft 2020-01-18 15:29:10 -08:00 committed by Patryk Obara
parent a0eafc9d8e
commit 3391651323
3 changed files with 25 additions and 11 deletions

View file

@ -202,6 +202,11 @@ Bitu DOS_Shell::GetRedirection(char *s, char **ifn, char **ofn,bool * append) {
// else
// *lr=0;
t = (char*)malloc(lr-*ofn+1);
if (t == nullptr) {
E_Exit("SHELL: Could not allocate %u bytes in parser",
static_cast<unsigned int>(lr-*ofn+1));
}
safe_strncpy(t,*ofn,lr-*ofn+1);
*ofn=t;
continue;
@ -216,6 +221,10 @@ Bitu DOS_Shell::GetRedirection(char *s, char **ifn, char **ofn,bool * append) {
// else
// *lr=0;
t = (char*)malloc(lr-*ifn+1);
if (t == nullptr) {
E_Exit("SHELL: Could not allocate %u bytes in parser",
static_cast<unsigned int>(lr-*ifn+1));
}
safe_strncpy(t,*ifn,lr-*ifn+1);
*ifn=t;
continue;

View file

@ -1319,20 +1319,25 @@ void DOS_Shell::CMD_CHOICE(char * args){
HELP("CHOICE");
static char defchoice[3] = {'y','n',0};
char *rem = NULL, *ptr;
bool optN = ScanCMDBool(args,"N");
bool optS = ScanCMDBool(args,"S"); //Case-sensitive matching
ScanCMDBool(args,"T"); //Default Choice after timeout
bool optN = false;
bool optS = false;
if (args) {
optN = ScanCMDBool(args,"N");
optS = ScanCMDBool(args,"S"); //Case-sensitive matching
ScanCMDBool(args,"T"); //Default Choice after timeout
char *last = strchr(args,0);
StripSpaces(args);
rem = ScanCMDRemain(args);
if (rem && *rem && (tolower(rem[1]) != 'c')) {
WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem);
return;
}
if (args == rem) {
assert(args);
args = strchr(rem, '\0') + 1;
if (rem != nullptr) {
args = strchr(rem, '\0') + 1;
}
}
if (rem) rem += 2;
if(rem && rem[0]==':') rem++; /* optional : after /c */
@ -1379,10 +1384,10 @@ void DOS_Shell::CMD_ATTRIB(char *args){
void DOS_Shell::CMD_PATH(char *args){
HELP("PATH");
if(args && *args && strlen(args)){
if(args && strlen(args)){
char pathstring[DOS_PATHLENGTH+CROSS_LEN+20]={ 0 };
strcpy(pathstring,"set PATH=");
while(args && *args && (*args=='='|| *args==' '))
while(args && *args && (*args=='='|| *args==' '))
args++;
strcat(pathstring,args);
this->ParseLine(pathstring);
@ -1398,7 +1403,7 @@ void DOS_Shell::CMD_PATH(char *args){
void DOS_Shell::CMD_VER(char *args) {
HELP("VER");
if(args && *args) {
if(args && strlen(args)) {
char* word = StripWord(args);
if(strcasecmp(word,"set")) return;
word = StripWord(args);

View file

@ -254,11 +254,11 @@ void DOS_Shell::InputCommand(char * line) {
// build the completion list
char mask[DOS_PATHLENGTH] = {0};
if (strlen(p_completion_start) + 3 >= DOS_PATHLENGTH) {
//Beep;
break;
}
if (p_completion_start) {
if (strlen(p_completion_start) + 3 >= DOS_PATHLENGTH) {
//Beep;
break;
}
safe_strncpy(mask, p_completion_start,DOS_PATHLENGTH);
char* dot_pos=strrchr(mask,'.');
char* bs_pos=strrchr(mask,'\\');