| 621 | } |
| 622 | |
| 623 | bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, |
| 624 | const LEX_CSTRING &username, |
| 625 | const LEX_CSTRING &hostname, |
| 626 | const LEX_CSTRING &rolename, |
| 627 | bool with_admin_option) |
| 628 | { |
| 629 | /* |
| 630 | Create a buffer that holds all 3 NULL terminated strings in succession |
| 631 | To save memory space, the same buffer is used as the hashkey |
| 632 | Add the '\0' as well. |
| 633 | */ |
| 634 | size_t bufflen= username.length + hostname.length + rolename.length + 3; |
| 635 | char *buff= (char *)alloc_root(mem, bufflen); |
| 636 | if (!buff) |
| 637 | return true; |
| 638 | |
| 639 | /* |
| 640 | Offsets in the buffer for all 3 strings |
| 641 | */ |
| 642 | char *username_pos= buff; |
| 643 | char *hostname_pos= buff + username.length + 1; |
| 644 | char *rolename_pos= buff + username.length + hostname.length + 2; |
| 645 | |
| 646 | if (username.str) //prevent undefined behaviour |
| 647 | memcpy(username_pos, username.str, username.length); |
| 648 | username_pos[username.length]= '\0'; //#1 string terminator |
| 649 | u_uname= Lex_cstring(username_pos, username.length); |
| 650 | |
| 651 | if (hostname.str) //prevent undefined behaviour |
| 652 | memcpy(hostname_pos, hostname.str, hostname.length); |
| 653 | hostname_pos[hostname.length]= '\0'; //#2 string terminator |
| 654 | u_hname= Lex_cstring(hostname_pos, hostname.length); |
| 655 | |
| 656 | if (rolename.str) //prevent undefined behaviour |
| 657 | memcpy(rolename_pos, rolename.str, rolename.length); |
| 658 | rolename_pos[rolename.length]= '\0'; //#3 string terminator |
| 659 | r_uname= Lex_cstring(rolename_pos, rolename.length); |
| 660 | |
| 661 | hashkey.str = buff; |
| 662 | hashkey.length = bufflen; |
| 663 | |
| 664 | with_admin= with_admin_option; |
| 665 | |
| 666 | return false; |
| 667 | } |
| 668 | |
| 669 | #define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3) |
| 670 |
no test coverage detected