int i, ret;
TCHAR *out_p = NULL, *parms_in = NULL;
- if (out)
+ if (outsize >= 32768)
+ return 0;
+ if (out && outsize > 0) {
+ if (!trap_valid_address(ctx, out, 1))
+ return 0;
trap_put_byte(ctx, out, 0);
+ }
if (size == 0) {
- while (trap_get_byte(ctx, parms + size) != 0)
+ for (;;) {
+ if (!trap_valid_address(ctx, parms + size, 1))
+ return 0;
+ if (trap_get_byte(ctx, parms + size) == 0)
+ break;
size++;
+ if (size >= 32768)
+ return 0;
+ }
}
parms_p = xmalloc (uae_char, size + 1);
if (!parms_p) {
parms_in = au (parms_p);
ret = cfgfile_modify (index, parms_in, size, out_p, outsize);
xfree (parms_in);
- if (out) {
+ if (out && outsize > 0) {
parms_out = ua (out_p);
+ if (!trap_valid_address(ctx, out, strlen(parms_out) + 1 > outsize ? outsize : strlen(parms_out) + 1))
+ return 0;
trap_put_string(ctx, parms_out, out, outsize - 1);
}
xfree (parms_out);
TCHAR *str;
uae_char tmpa[CONFIG_BLEN];
- if (mode)
+ if (mode || maxlen > CONFIG_BLEN)
+ return 0;
+
+ if (!trap_valid_string(ctx, name, CONFIG_BLEN))
+ return 0;
+ if (!trap_valid_address(ctx, dst, maxlen))
return 0;
trap_get_string(ctx, tmpa, name, sizeof tmpa);
void trap_set_background(TrapContext *ctx);
void trap_background_set_complete(TrapContext *ctx);
bool trap_valid_address(TrapContext *ctx, uaecptr addr, uae_u32 size);
+bool trap_valid_string(TrapContext *ctx, uaecptr addr, uae_u32 maxsize);
bool trap_is_indirect(void);
void trap_dos_active(void);
void trap_reset(void);
atomic_inc(&ctx->trap_background);
}
+bool trap_valid_string(TrapContext *ctx, uaecptr addr, uae_u32 maxsize)
+{
+ if (!ctx || currprefs.uaeboard < 3) {
+ for (int i = 0; i < maxsize; i++) {
+ if (!valid_address(addr + i, 1))
+ return false;
+ if (get_byte(addr + i) == 0)
+ return true;
+ }
+ return false;
+ }
+ // can't really do any checks..
+ return true;
+}
+
bool trap_valid_address(TrapContext *ctx, uaecptr addr, uae_u32 size)
{
if (!ctx || currprefs.uaeboard < 3)