… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* |
25 | /* |
… | |
… | |
32 | #include <time.h> |
33 | #include <time.h> |
33 | #include <signal.h> |
34 | #include <signal.h> |
34 | |
35 | |
35 | #include <global.h> |
36 | #include <global.h> |
36 | #include <material.h> |
37 | #include <material.h> |
|
|
38 | #include <object.h> |
37 | |
39 | |
38 | #include <sys/time.h> |
40 | #include <sys/time.h> |
39 | #include <sys/resource.h> |
41 | #include <sys/resource.h> |
40 | |
42 | |
41 | #include <glib.h> |
43 | #include <glib.h> |
… | |
… | |
226 | int j; |
228 | int j; |
227 | |
229 | |
228 | if (!op->materialname) |
230 | if (!op->materialname) |
229 | return; |
231 | return; |
230 | |
232 | |
231 | if (change->materialname && strcmp (op->materialname, change->materialname)) |
233 | if (op->materialname != change->materialname) |
232 | return; |
234 | return; |
233 | |
235 | |
234 | if (!op->is_armor ()) |
236 | if (!op->is_armor ()) |
235 | return; |
237 | return; |
236 | |
238 | |
… | |
… | |
447 | strcpy (input, tmp); |
449 | strcpy (input, tmp); |
448 | |
450 | |
449 | return; |
451 | return; |
450 | } |
452 | } |
451 | |
453 | |
|
|
454 | /******************************************************************************/ |
|
|
455 | |
|
|
456 | /* Checks a player-provided string which will become the msg property of |
|
|
457 | * an object for dangerous input. |
|
|
458 | */ |
|
|
459 | bool |
|
|
460 | msg_is_safe (const char *msg) |
|
|
461 | { |
|
|
462 | bool safe = true; |
|
|
463 | |
|
|
464 | /* Trying to cheat by getting data into the object */ |
|
|
465 | if (!strncmp (msg, "endmsg", sizeof ("endmsg") - 1) |
|
|
466 | || strstr (msg, "\nendmsg")) |
|
|
467 | safe = false; |
|
|
468 | |
|
|
469 | /* Trying to make the object talk, and potentially access arbitrary code */ |
|
|
470 | if (object::msg_has_dialogue (msg)) |
|
|
471 | safe = false; |
|
|
472 | |
|
|
473 | return safe; |
|
|
474 | } |
|
|
475 | |
452 | ///////////////////////////////////////////////////////////////////////////// |
476 | ///////////////////////////////////////////////////////////////////////////// |
453 | |
477 | |
454 | void |
478 | void |
455 | fork_abort (const char *msg) |
479 | fork_abort (const char *msg) |
456 | { |
480 | { |
… | |
… | |
559 | |
583 | |
560 | #endif |
584 | #endif |
561 | |
585 | |
562 | /******************************************************************************/ |
586 | /******************************************************************************/ |
563 | |
587 | |
|
|
588 | int |
564 | void assign (char *dst, const char *src, int maxlen) |
589 | assign (char *dst, const char *src, int maxsize) |
565 | { |
590 | { |
566 | if (!src) |
591 | if (!src) |
567 | src = ""; |
592 | src = ""; |
568 | |
593 | |
569 | int len = strlen (src); |
594 | int len = strlen (src); |
570 | |
595 | |
571 | if (len >= maxlen - 1) |
596 | if (len >= maxsize) |
572 | { |
597 | { |
573 | if (maxlen <= 4) |
598 | if (maxsize <= 4) |
574 | { |
599 | { |
575 | memset (dst, '.', maxlen - 1); |
600 | memset (dst, '.', maxsize - 2); |
576 | dst [maxlen - 1] = 0; |
601 | dst [maxsize - 1] = 0; |
577 | } |
602 | } |
578 | else |
603 | else |
579 | { |
604 | { |
580 | memcpy (dst, src, maxlen - 4); |
605 | memcpy (dst, src, maxsize - 4); |
581 | memcpy (dst + maxlen - 4, "...", 4); |
606 | memcpy (dst + maxsize - 4, "...", 4); |
582 | } |
607 | } |
|
|
608 | |
|
|
609 | len = maxsize; |
583 | } |
610 | } |
584 | else |
611 | else |
585 | memcpy (dst, src, len + 1); |
612 | memcpy (dst, src, ++len); |
|
|
613 | |
|
|
614 | return len; |
586 | } |
615 | } |
587 | |
616 | |
588 | const char * |
617 | const char * |
589 | format (const char *format, ...) |
618 | format (const char *format, ...) |
590 | { |
619 | { |