~ubuntu-branches/ubuntu/hardy/pennmush/hardy

« back to all changes in this revision

Viewing changes to src/funufun.c

  • Committer: Bazaar Package Importer
  • Author(s): Ervin Hearn III
  • Date: 2007-10-14 22:26:42 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071014222642-3vt0pg0vxdiuxq5z
Tags: 1.8.2p7-1
* New upstream release
* Latest upstream release fixes possible DoS vulnerabilities in
  pennmush (Closes: #436249)
* Added missing build target to debian/rules (Closes: #395786)
* Corrected FTBFS on GNU/kFreeBSD due to timestamp skew
  (Closes: #403711)
* Applied patch to correct control file to make package binNMU safe
  (Closes: #435951)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "confmagic.h"
23
23
 
24
24
void do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs,
25
 
               char **args, dbref executor, dbref caller, dbref enactor,
26
 
               PE_Info * pe_info);
 
25
               char **args, dbref executor, dbref caller, dbref enactor,
 
26
               PE_Info * pe_info);
27
27
 
28
28
/* ARGSUSED */
29
29
FUNCTION(fun_s)
31
31
  char const *p;
32
32
  p = args[0];
33
33
  process_expression(buff, bp, &p, executor, caller, enactor, PE_DEFAULT,
34
 
                     PT_DEFAULT, pe_info);
 
34
                     PT_DEFAULT, pe_info);
35
35
}
36
36
 
37
37
/* ARGSUSED */
44
44
 
45
45
  p = args[0];
46
46
  process_expression(buff, bp, &p, executor, caller, enactor, PE_DEFAULT,
47
 
                     PT_DEFAULT, pe_info);
 
47
                     PT_DEFAULT, pe_info);
48
48
 
49
49
  restore_global_regs("localize", saver);
50
50
}
63
63
  s = name;
64
64
  p = args[0];
65
65
  process_expression(name, &s, &p, executor, caller, enactor, PE_DEFAULT,
66
 
                     PT_DEFAULT, pe_info);
 
66
                     PT_DEFAULT, pe_info);
67
67
  *s = '\0';
68
68
 
69
69
  if (FUNCTION_SIDE_EFFECTS) {
72
72
     * standpoint. We require control.
73
73
     */
74
74
    if (((obj = match_thing(executor, name)) == NOTHING)
75
 
        || !controls(executor, obj))
 
75
        || !controls(executor, obj))
76
76
      obj = executor;
77
77
  } else {
78
78
    /* In order to evaluate from something else's viewpoint, you
79
79
     * must control it, or be able to see_all.
80
80
     */
81
81
    if (((obj = match_thing(executor, name)) == NOTHING)
82
 
        || (!controls(executor, obj) && !See_All(executor)))
 
82
        || (!controls(executor, obj) && !See_All(executor)))
83
83
      obj = executor;
84
84
  }
85
85
 
86
86
  p = args[1];
87
87
  process_expression(buff, bp, &p, obj, executor, enactor, PE_DEFAULT,
88
 
                     PT_DEFAULT, pe_info);
 
88
                     PT_DEFAULT, pe_info);
89
89
}
90
90
 
91
91
/** Helper function for ufun and family.
102
102
 */
103
103
void
104
104
do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs,
105
 
          char **args, dbref executor, dbref caller
106
 
          __attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info)
 
105
          char **args, dbref executor, dbref caller
 
106
          __attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info)
107
107
{
108
108
  int j;
109
109
  char *tptr[10];
110
110
  char *tbuf;
111
111
  char const *tp;
112
112
  int pe_flags = PE_DEFAULT;
 
113
  int old_args = 0;
113
114
 
114
115
  /* save our stack */
115
116
  for (j = 0; j < 10; j++)
117
118
 
118
119
  /* copy the appropriate args into the stack */
119
120
  if (nargs > 10)
120
 
    nargs = 10;                 /* maximum ten args */
 
121
    nargs = 10;                 /* maximum ten args */
121
122
  for (j = 0; j < nargs; j++)
122
123
    global_eval_context.wenv[j] = args[j];
123
124
  for (; j < 10; j++)
124
125
    global_eval_context.wenv[j] = NULL;
 
126
  if (pe_info) {
 
127
    old_args = pe_info->arg_count;
 
128
    pe_info->arg_count = nargs;
 
129
  }
125
130
 
126
131
  tp = tbuf = safe_atr_value(attrib);
127
132
  if (attrib->flags & AF_DEBUG)
128
133
    pe_flags |= PE_DEBUG;
129
134
  process_expression(buff, bp, &tp, obj, executor, enactor, pe_flags,
130
 
                     PT_DEFAULT, pe_info);
 
135
                     PT_DEFAULT, pe_info);
131
136
  free(tbuf);
132
137
 
133
138
  /* restore the stack */
134
139
  for (j = 0; j < 10; j++)
135
140
    global_eval_context.wenv[j] = tptr[j];
 
141
  if (pe_info)
 
142
    pe_info->arg_count = old_args;
136
143
}
137
144
 
138
145
/* ARGSUSED */
139
146
FUNCTION(fun_ufun)
140
147
{
141
 
  ATTR *attrib;
142
 
  dbref obj;
143
 
 
144
 
  /* find the user function attribute */
145
 
  parse_attrib(executor, args[0], &obj, &attrib);
146
 
  if (!GoodObject(obj)) {
147
 
    safe_str(T("#-1 INVALID OBJECT"), buff, bp);
148
 
    return;
149
 
  }
150
 
  if (attrib && Can_Read_Attr(executor, obj, attrib)) {
151
 
    if (!CanEvalAttr(executor, obj, attrib)) {
152
 
      safe_str(T(e_perm), buff, bp);
153
 
      return;
154
 
    }
155
 
    do_userfn(buff, bp, obj, attrib, nargs - 1, args + 1, executor, caller,
156
 
              enactor, pe_info);
157
 
    return;
158
 
  } else if (attrib || !Can_Examine(executor, obj)) {
159
 
    safe_str(T(e_atrperm), buff, bp);
160
 
    return;
161
 
  }
 
148
  char rbuff[BUFFER_LEN];
 
149
  ufun_attrib ufun;
 
150
 
 
151
  if (!fetch_ufun_attrib(args[0], executor, &ufun, 0)) {
 
152
    safe_str(T(ufun.errmess), buff, bp);
 
153
    return;
 
154
  }
 
155
 
 
156
  call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
 
157
 
 
158
  safe_str(rbuff, buff, bp);
 
159
 
 
160
  return;
 
161
}
 
162
 
 
163
/* ARGSUSED */
 
164
FUNCTION(fun_ulambda)
 
165
{
 
166
  char rbuff[BUFFER_LEN];
 
167
  ufun_attrib ufun;
 
168
 
 
169
  if (!fetch_ufun_attrib(args[0], executor, &ufun, 1)) {
 
170
    safe_str(T(ufun.errmess), buff, bp);
 
171
    return;
 
172
  }
 
173
 
 
174
  call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
 
175
 
 
176
  safe_str(rbuff, buff, bp);
 
177
 
162
178
  return;
163
179
}
164
180
 
168
184
  /* Like fun_ufun, but saves the state of the q0-q9 registers
169
185
   * when called
170
186
   */
171
 
  ATTR *attrib;
172
 
  dbref obj;
173
187
  char *preserve[NUMQ];
174
 
 
175
 
  /* find the user function attribute */
176
 
  parse_attrib(executor, args[0], &obj, &attrib);
177
 
  if (!GoodObject(obj)) {
178
 
    safe_str(T("#-1 INVALID OBJECT"), buff, bp);
179
 
    return;
180
 
  }
181
 
  if (attrib && Can_Read_Attr(executor, obj, attrib)) {
182
 
    if (!CanEvalAttr(executor, obj, attrib)) {
183
 
      safe_str(T(e_perm), buff, bp);
184
 
      return;
185
 
    }
186
 
    save_global_regs("ulocal.save", preserve);
187
 
    do_userfn(buff, bp, obj, attrib, nargs - 1, args + 1, executor, caller,
188
 
              enactor, pe_info);
189
 
    restore_global_regs("ulocal.save", preserve);
190
 
    return;
191
 
  } else if (attrib || !Can_Examine(executor, obj)) {
192
 
    safe_str(T(e_atrperm), buff, bp);
193
 
    return;
194
 
  }
 
188
  char rbuff[BUFFER_LEN];
 
189
  ufun_attrib ufun;
 
190
 
 
191
  if (!fetch_ufun_attrib(args[0], executor, &ufun, 0)) {
 
192
    safe_str(T(ufun.errmess), buff, bp);
 
193
    return;
 
194
  }
 
195
 
 
196
  /* Save global regs */
 
197
  save_global_regs("ulocal.save", preserve);
 
198
 
 
199
  call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
 
200
  safe_str(rbuff, buff, bp);
 
201
 
 
202
  restore_global_regs("ulocal.save", preserve);
 
203
 
195
204
  return;
196
205
}
197
206
 
215
224
  dp = mstr;
216
225
  sp = args[0];
217
226
  process_expression(mstr, &dp, &sp, executor, caller, enactor,
218
 
                     PE_DEFAULT, PT_DEFAULT, pe_info);
 
227
                     PE_DEFAULT, PT_DEFAULT, pe_info);
219
228
  *dp = '\0';
220
229
  parse_attrib(executor, mstr, &thing, &attrib);
221
230
  if (GoodObject(thing) && attrib && CanEvalAttr(executor, thing, attrib)
226
235
    xargs = NULL;
227
236
    if (nargs > 2) {
228
237
      xargs =
229
 
        (char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs");
 
238
        (char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs");
230
239
      for (i = 0; i < nargs - 2; i++) {
231
 
        xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault");
232
 
        dp = xargs[i];
233
 
        sp = args[i + 2];
234
 
        process_expression(xargs[i], &dp, &sp, executor, caller, enactor,
235
 
                           PE_DEFAULT, PT_DEFAULT, pe_info);
236
 
        *dp = '\0';
 
240
        xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault");
 
241
        dp = xargs[i];
 
242
        sp = args[i + 2];
 
243
        process_expression(xargs[i], &dp, &sp, executor, caller, enactor,
 
244
                           PE_DEFAULT, PT_DEFAULT, pe_info);
 
245
        *dp = '\0';
237
246
      }
238
247
    }
239
248
    if (called_as[1] == 'L')
240
249
      save_global_regs("uldefault.save", preserve);
241
250
    do_userfn(buff, bp, thing, attrib, nargs - 2, xargs,
242
 
              executor, caller, enactor, pe_info);
 
251
              executor, caller, enactor, pe_info);
243
252
    if (called_as[1] == 'L')
244
253
      restore_global_regs("uldefault.save", preserve);
245
254
 
246
255
    /* Free the xargs */
247
256
    if (nargs > 2) {
248
257
      for (i = 0; i < nargs - 2; i++)
249
 
        mush_free(xargs[i], "udefault");
 
258
        mush_free(xargs[i], "udefault");
250
259
      mush_free(xargs, "udefault.xargs");
251
260
    }
252
261
    return;
257
266
  if (called_as[1] == 'L')
258
267
    save_global_regs("uldefault.save", preserve);
259
268
  process_expression(buff, bp, &sp, executor, caller, enactor,
260
 
                     PE_DEFAULT, PT_DEFAULT, pe_info);
 
269
                     PE_DEFAULT, PT_DEFAULT, pe_info);
261
270
  if (called_as[1] == 'L')
262
271
    restore_global_regs("uldefault.save", preserve);
263
272
  return;
284
293
      return;
285
294
    }
286
295
    do_userfn(buff, bp, zone, attrib, nargs - 1, args + 1, executor, caller,
287
 
              enactor, pe_info);
 
296
              enactor, pe_info);
288
297
    return;
289
298
  } else if (attrib || !Can_Examine(executor, zone)) {
290
299
    safe_str(T(e_atrperm), buff, bp);