… | |
… | |
32 | #include <time.h> |
32 | #include <time.h> |
33 | #include <signal.h> |
33 | #include <signal.h> |
34 | |
34 | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <material.h> |
36 | #include <material.h> |
|
|
37 | #include <object.h> |
37 | |
38 | |
38 | #include <sys/time.h> |
39 | #include <sys/time.h> |
39 | #include <sys/resource.h> |
40 | #include <sys/resource.h> |
40 | |
41 | |
41 | #include <glib.h> |
42 | #include <glib.h> |
… | |
… | |
447 | strcpy (input, tmp); |
448 | strcpy (input, tmp); |
448 | |
449 | |
449 | return; |
450 | return; |
450 | } |
451 | } |
451 | |
452 | |
|
|
453 | /******************************************************************************/ |
|
|
454 | |
|
|
455 | /* Checks a player-provided string which will become the msg property of |
|
|
456 | * an object for dangerous input. |
|
|
457 | */ |
|
|
458 | bool |
|
|
459 | msg_is_safe (const char *msg) |
|
|
460 | { |
|
|
461 | bool safe = true; |
|
|
462 | |
|
|
463 | /* Trying to cheat by getting data into the object */ |
|
|
464 | if (!strncmp (msg, "endmsg", strlen ("endmsg")) || strstr (msg, "\nendmsg")) |
|
|
465 | safe = false; |
|
|
466 | |
|
|
467 | /* Trying to make the object talk, and potentially access arbitrary code */ |
|
|
468 | if (object::msg_has_dialogue (msg)) |
|
|
469 | safe = false; |
|
|
470 | |
|
|
471 | return safe; |
|
|
472 | } |
|
|
473 | |
452 | ///////////////////////////////////////////////////////////////////////////// |
474 | ///////////////////////////////////////////////////////////////////////////// |
453 | |
475 | |
454 | void |
476 | void |
455 | fork_abort (const char *msg) |
477 | fork_abort (const char *msg) |
456 | { |
478 | { |
… | |
… | |
559 | |
581 | |
560 | #endif |
582 | #endif |
561 | |
583 | |
562 | /******************************************************************************/ |
584 | /******************************************************************************/ |
563 | |
585 | |
|
|
586 | int |
564 | void assign (char *dst, const char *src, int maxlen) |
587 | assign (char *dst, const char *src, int maxsize) |
565 | { |
588 | { |
566 | if (!src) |
589 | if (!src) |
567 | src = ""; |
590 | src = ""; |
568 | |
591 | |
569 | int len = strlen (src); |
592 | int len = strlen (src); |
570 | |
593 | |
571 | if (len >= maxlen - 1) |
594 | if (len >= maxsize) |
572 | { |
595 | { |
573 | if (maxlen <= 4) |
596 | if (maxsize <= 4) |
574 | { |
597 | { |
575 | memset (dst, '.', maxlen - 1); |
598 | memset (dst, '.', maxsize - 2); |
576 | dst [maxlen - 1] = 0; |
599 | dst [maxsize - 1] = 0; |
577 | } |
600 | } |
578 | else |
601 | else |
579 | { |
602 | { |
580 | memcpy (dst, src, maxlen - 4); |
603 | memcpy (dst, src, maxsize - 4); |
581 | memcpy (dst + maxlen - 4, "...", 4); |
604 | memcpy (dst + maxsize - 4, "...", 4); |
582 | } |
605 | } |
|
|
606 | |
|
|
607 | len = maxsize; |
583 | } |
608 | } |
584 | else |
609 | else |
585 | memcpy (dst, src, len + 1); |
610 | memcpy (dst, src, ++len); |
|
|
611 | |
|
|
612 | return len; |
586 | } |
613 | } |
587 | |
614 | |
588 | const char * |
615 | const char * |
589 | format (const char *format, ...) |
616 | format (const char *format, ...) |
590 | { |
617 | { |