Mercurial > vim
comparison src/misc2.c @ 10644:2025bec9175f v8.0.0212
patch 8.0.0212: buffer for key name may be too small
commit https://github.com/vim/vim/commit/423977d3cebac2be1158b1d11da60fe96db4b750
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 22 15:05:12 2017 +0100
patch 8.0.0212: buffer for key name may be too small
Problem: The buffer used to store a key name theoreticaly could be too
small. (Coverity)
Solution: Count all possible modifier characters. Add a check for the
length just in case.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 22 Jan 2017 15:15:04 +0100 |
parents | 27be410d6d29 |
children | 24a1fbd78b76 |
comparison
equal
deleted
inserted
replaced
10643:9eee1718dcc6 | 10644:2025bec9175f |
---|---|
2160 {MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'}, | 2160 {MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'}, |
2161 #endif | 2161 #endif |
2162 /* 'A' must be the last one */ | 2162 /* 'A' must be the last one */ |
2163 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'}, | 2163 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'}, |
2164 {0, 0, NUL} | 2164 {0, 0, NUL} |
2165 /* NOTE: when adding an entry, update MAX_KEY_NAME_LEN! */ | |
2165 }; | 2166 }; |
2166 | 2167 |
2167 /* | 2168 /* |
2168 * Shifted key terminal codes and their unshifted equivalent. | 2169 * Shifted key terminal codes and their unshifted equivalent. |
2169 * Don't add mouse codes here, they are handled separately! | 2170 * Don't add mouse codes here, they are handled separately! |
2429 {K_SNR, (char_u *)"SNR"}, | 2430 {K_SNR, (char_u *)"SNR"}, |
2430 #endif | 2431 #endif |
2431 {K_PLUG, (char_u *)"Plug"}, | 2432 {K_PLUG, (char_u *)"Plug"}, |
2432 {K_CURSORHOLD, (char_u *)"CursorHold"}, | 2433 {K_CURSORHOLD, (char_u *)"CursorHold"}, |
2433 {0, NULL} | 2434 {0, NULL} |
2435 /* NOTE: When adding a long name update MAX_KEY_NAME_LEN. */ | |
2434 }; | 2436 }; |
2435 | 2437 |
2436 #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry)) | 2438 #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry)) |
2437 | 2439 |
2438 #ifdef FEAT_MOUSE | 2440 #ifdef FEAT_MOUSE |
2657 } | 2659 } |
2658 } | 2660 } |
2659 } | 2661 } |
2660 else /* use name of special key */ | 2662 else /* use name of special key */ |
2661 { | 2663 { |
2662 STRCPY(string + idx, key_names_table[table_idx].name); | 2664 size_t len = STRLEN(key_names_table[table_idx].name); |
2663 idx = (int)STRLEN(string); | 2665 |
2666 if (len + idx + 2 <= MAX_KEY_NAME_LEN) | |
2667 { | |
2668 STRCPY(string + idx, key_names_table[table_idx].name); | |
2669 idx += (int)len; | |
2670 } | |
2664 } | 2671 } |
2665 string[idx++] = '>'; | 2672 string[idx++] = '>'; |
2666 string[idx] = NUL; | 2673 string[idx] = NUL; |
2667 return string; | 2674 return string; |
2668 } | 2675 } |