Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow #244

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/keytables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ const char char_or_func[] = // c = character key, f = function key, _ = blank/e

inline bool is_char_key(unsigned int code)
{
assert(code < sizeof(char_or_func));
assert(code < sizeof(char_or_func)-1);
return (char_or_func[code] == 'c');
}

inline bool is_func_key(unsigned int code)
{
assert(code < sizeof(char_or_func));
assert(code < sizeof(char_or_func)-1);
return (char_or_func[code] == 'f');
}

inline bool is_used_key(unsigned int code)
{
assert(code < sizeof(char_or_func));
assert(code < sizeof(char_or_func)-1);
return (char_or_func[code] != '_');
}

Expand Down
15 changes: 6 additions & 9 deletions src/logkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void determine_system_keymap()
std::stringstream ss, dump(execute(COMMAND_STR_DUMPKEYS)); // see example output after i.e. `loadkeys slovene`
std::string line;

unsigned int i = 0; // keycode
unsigned int i = -1; // keycode
int index;
int utf8code; // utf-8 code of keysym answering keycode i

Expand All @@ -205,7 +205,7 @@ void determine_system_keymap()
index = line.find("U+", index);
}

if (++i >= sizeof(char_or_func)) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used)
if (++i >= sizeof(char_or_func)-1) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used)
if (!is_char_key(i)) continue; // only map character keys of keyboard

assert(line.size() > 0);
Expand Down Expand Up @@ -258,15 +258,12 @@ void parse_input_keymap()
if (stdin == NULL)
error(EXIT_FAILURE, errno, "Error opening input keymap '%s'", args.keymap.c_str());

unsigned int i = -1;
unsigned int line_number = 0;
wchar_t func_string[32];
wchar_t line[32];

while (!feof(stdin)) {

if (++i >= sizeof(char_or_func)) break; // only ever read up to 128 keycode bindings (currently N_KEYS_DEFINED are used)

// only ever read up to 128 keycode bindings (currently N_KEYS_DEFINED are used)
for (unsigned int i=0; i < sizeof(char_or_func)-1 && !feof(stdin); ++i) {
if (is_used_key(i)) {
++line_number;
if(fgetws(line, sizeof(line), stdin) == NULL) {
Expand Down Expand Up @@ -295,7 +292,7 @@ void parse_input_keymap()
error_at_line(EXIT_FAILURE, 0, args.keymap.c_str(), line_number, "Invalid function key string"); // does this ever happen?
wcscpy(func_keys[to_func_keys_index(i)], func_string);
}
} // while (!feof(stdin))
} // for
fclose(stdin);

if (line_number < N_KEYS_DEFINED)
Expand All @@ -311,7 +308,7 @@ void export_keymap_to_file()
char buffer[32];
int buflen = 0;
unsigned int index;
for (unsigned int i = 0; i < sizeof(char_or_func); ++i) {
for (unsigned int i = 0; i < sizeof(char_or_func)-1; ++i) {
buflen = 0;
if (is_char_key(i)) {
index = to_char_keys_index(i);
Expand Down