added[0] = 0;
while ((c = *cp++) != '\0') {
if (c != '%') {
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = c;
continue;
}
/* fall into... */
case '3':
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = (which / 100) | '0';
which %= 100;
/* fall into... */
case '2':
two:
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = which / 10 | '0';
one:
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = which % 10 | '0';
swap:
oncol = 1 - oncol;
* to be the successor of tab.
*/
do {
+ if (strlen(added) + 1 >= sizeof(added))
+ goto toohard;
strcat(added, oncol ? (BC ? BC : "\b") : UP);
which++;
} while (which == '\n');
}
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = which;
goto swap;
continue;
case '%':
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
*dp++ = c;
continue;
goto toohard;
}
}
- strncpy(dp, added, sizeof (result) - (dp - result) - 1);
+ if (dp - result + strlen(added) >= MAXRETURNSIZE - 1)
+ goto toohard;
+ strcpy(dp, added);
return (result);
}
-/* $OpenBSD: tparm.c,v 1.3 1996/09/16 02:41:53 tholo Exp $ */
+/* $OpenBSD: tparm.c,v 1.4 1997/03/28 00:39:08 tholo Exp $ */
/*
* Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: tparm.c,v 1.3 1996/09/16 02:41:53 tholo Exp $";
+static char rcsid[] = "$OpenBSD: tparm.c,v 1.4 1997/03/28 00:39:08 tholo Exp $";
#endif
#include <stdio.h>
#define MAX(a, b) ((a) < (b) ? (b) : (a))
-#define STKSIZ 32
+#define STKSIZ 32
+#define MAXRETURNSIZE 256
static __inline void push __P((int));
static __inline int popnum __P((void));
{
int param[10], variable[26];
int pops, num, i, level;
+ char scratch[64];
char *bufp, len;
const char *p;
bufp = buf;
while (*str) {
- if (*str != '%')
+ if (*str != '%') {
+ if (bufp >= buf + MAXRETURNSIZE)
+ goto overflow;
*bufp++ = *str;
+ }
else {
switch (*++str) {
case '%':
+ if (bufp >= buf + MAXRETURNSIZE)
+ goto overflow;
*bufp++ = '%';
break;
case 'd':
- sprintf(bufp, "%d", popnum());
+ sprintf(scratch, "%d", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
break;
case '0':
if (len == '2' || len == '3') {
if (*++str == 'd') {
if (len == '2')
- sprintf(bufp, "%02d", popnum());
+ sprintf(scratch, "%02d", popnum());
else
- sprintf(bufp, "%03d", popnum());
+ sprintf(scratch, "%03d", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
else if (*str == 'x') {
if (len == '2')
- sprintf(bufp, "%02x", popnum());
+ sprintf(scratch, "%02x", popnum());
else
- sprintf(bufp, "%03x", popnum());
+ sprintf(scratch, "%03x", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
}
break;
case '2':
if (*++str == 'd') {
- sprintf(bufp, "%2d", popnum());
+ sprintf(scratch, "%2d", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
else if (*str == 'x') {
- sprintf(bufp, "%2x", popnum());
+ sprintf(scratch, "%2x", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
break;
case '3':
if (*++str == 'd') {
- sprintf(bufp, "%3d", popnum());
+ sprintf(scratch, "%3d", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
else if (*str == 'x') {
- sprintf(bufp, "%3x", popnum());
+ sprintf(scratch, "%3x", popnum());
+ if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, scratch);
bufp += strlen(bufp);
}
break;
case 'c':
+ if (bufp >= buf + MAXRETURNSIZE)
+ goto overflow;
*bufp++ = (char)popnum();
break;
case 's':
- strcpy(bufp, popstr());
+ if (bufp + strlen(p = popstr()) >= buf + MAXRETURNSIZE)
+ goto overflow;
+ strcpy(bufp, p);
bufp += strlen(bufp);
break;
case 'p':
str++;
}
+ if (bufp >= buf + MAXRETURNSIZE)
+ goto overflow;
*bufp = '\0';
return(buf);
+overflow:
+ strcpy(buf, "OVERFLOW!");
+ return(buf);
}
char *
va_dcl
#endif
{
- static char buf[256];
+ static char buf[MAXRETURNSIZE];
va_list ap;
char *p;
#if !__STDC__