argv bug fix

This commit is contained in:
Julian Barathieu 2019-05-18 22:53:57 +02:00
parent 58b896ea2a
commit 890cc6e615
3 changed files with 25 additions and 18 deletions

View File

@ -83,7 +83,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
assert(argv && cmdLine);
// Another ARG_MAX-wide buffer
char *buffer = *argv + ARG_MAX;
char *buffer = bufptr + ARG_MAX;
argv[0] = buffer;

View File

@ -27,7 +27,7 @@
int shcol = VGA_COLOR_LIGHT_GREY;
int shargc = 0;
char *argv0 = 0;
char *argvbuf = 0;
char **shargv = 0;
void ExecuteCommand(char *cmdbuf)
@ -40,7 +40,7 @@ void ExecuteCommand(char *cmdbuf)
return;
memzero(*shargv, ARG_MAX);
rc = KalCmdLineToArgVec(cmdbuf, &shargc, argv0);
rc = KalCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
@ -51,8 +51,10 @@ void ExecuteCommand(char *cmdbuf)
}
}
assert(shargv[0] == argvbuf + ARG_MAX);
if (found == false) {
KernLog("err: command not found: '%s' (%ld)\n",
KernLog("err: command not found: '%.255s' (%ld)\n",
shargv[0], strlen(shargv[0]));
}
}
@ -65,9 +67,9 @@ void KeStartShell(void)
char *cmdbuf = malloc(CMDBUFSIZE);
char *bufptr = cmdbuf;
argv0 = malloc(ARG_MAX * 2);
memzero(argv0, ARG_MAX * 2);
shargv = (char **)argv0;
argvbuf = malloc(ARG_MAX * 2);
memzero(argvbuf, ARG_MAX * 2);
shargv = (char **)argvbuf;
KernLog("\n%Cshell> ", shcol);
BFlushBuf(BStdOut);

View File

@ -110,7 +110,7 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
{
error_t rc = 0;
int width, prec, len;
ssize_t width, prec, len;
char type;
uchar uch;
@ -199,7 +199,7 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
fmt++; \
name = va_arg(ap, int); \
} else { \
while (isdigit(*fmt) && name < CONVBUFSIZE) { \
while (isdigit(*fmt)) { \
name = 10 * name + (*fmt - '0'); \
fmt++; \
} \
@ -221,12 +221,6 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
bextractwp(prec);
}
// Make sure they're not too big
if (width > CONVBUFSIZE || prec > CONVBUFSIZE) {
rc = EINVAL;
break;
}
//
// Length field
//
@ -270,12 +264,14 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
if (!(base < 0 || base > VGA_COLOR_WHITE))
rc = bputc(buf, RtlColorToChar(base));
assert(!rc && 1);
continue;
}
#endif
// Strings
else if (type == 's') {
if (type == 's') {
s = va_arg(ap, char *);
if (s == NULL) s = "(null)";
@ -292,8 +288,16 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
continue;
}
// Make sure width and prec aren't too big
// (We didn't do that earlier because %s uses width)
if (width > CONVBUFSIZE || prec > CONVBUFSIZE) {
rc = EINVAL;
break;
}
// Decimal, unsigned decimal, hexadecimal, octal and binary numbers
else if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
else if (type == 'X') { base = 16; cap = 1; }
else if (type == 'x') { base = 16; }
else if (type == 'u') { base = 10; }
@ -406,7 +410,8 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
}
// For debugging purposes
assert(!rc);
if(rc)KeStartPanic("%s",strerror(rc));
assert(!rc && "vbprintf() error");
return rc;
}