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

fixes null-character termination in ucis_add() #22351

Closed
wants to merge 4 commits into from

Conversation

rubienr
Copy link

@rubienr rubienr commented Oct 28, 2023

Description

With UCIS_ENABLE = yes and UNICODE_COMMON = yes when entering a wrong mnemonic, a second attempt with correct mnemonic would not trigger the ucis input.

This change:

  • adds a trailing 0 after the last added character in ucis_add()
  • introduces boundary check on ucis_add() to not write out of bounds
  • clears buffered character by 0 on ucis_remove_last()
  • correctly handles abortion (ESC)
  • correctly handles invalid characters (i.e.: ,.-/* ...)

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Fixes following example:

keymap.c

const ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
    UCIS_SYM("poop", 0x1F4A9),                // 💩
    UCIS_SYM("rofl", 0x1F923),                // 🤣
    UCIS_SYM("ukr", 0x1F1FA, 0x1F1E6),        // 🇺🇦
    UCIS_SYM("look", 0x0CA0, 0x005F, 0x0CA0)  // ಠ_ಠ
);
  1. enter ⌨poopxyz (wrong mnemonic)
  2. enter ⌨poop (correct mnemonic) would not trigger since the buffer is still poopxyz'0''0'...

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Relates to #21659

@github-actions github-actions bot added the core label Oct 28, 2023
Copy link
Member

@fauxpark fauxpark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test for this?

@fauxpark fauxpark requested a review from a team October 28, 2023 22:25
@rubienr
Copy link
Author

rubienr commented Oct 28, 2023

IMHO the fix reveals that match_mnemonic() had an issue because test UnicodeUCIS.does_not_match_shorter_sequence fails. However the bug/feature seems very convenient. If the mnemonic is not fully typed match_mnemonic() will match the first substring which i found to be very handy.

Given:

const ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
    UCIS_SYM("poop", 0x1F4A9),                // 💩
    UCIS_SYM("rofl", 0x1F923),                // 🤣
    UCIS_SYM("ukr", 0x1F1FA, 0x1F1E6),        // 🇺🇦
    UCIS_SYM("look", 0x0CA0, 0x005F, 0x0CA0)  // ಠ_ಠ
);
  • ⌨p would match poop
  • ⌨ro would match rofl
  • ...

Should i fix the test (and leave the current behaviour) or should i fix the behaviour:question:

@fauxpark
Copy link
Member

I think that behaviour might be less than predictable to most users, even if you personally find it useful. It's probably more straightforward to trigger only on the first exact match (which should really be the only exact match).

Copy link

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with bug, awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@github-actions github-actions bot added the stale Issues or pull requests that have become inactive without resolution. label Dec 26, 2023
@KarlK90
Copy link
Member

KarlK90 commented Dec 26, 2023

@rubienr thanks for your PR. It looks good in principle but there are now falling unit-tests as you have changed the behavior. This has to be fixed in order to merge. Also please add the mentioned example in the description of the pr as a new test.

@KarlK90 KarlK90 removed the stale Issues or pull requests that have become inactive without resolution. label Dec 26, 2023
@rubienr
Copy link
Author

rubienr commented Jan 4, 2024

Apologies for the long delay. I will try to focus on this PR ASAP: comments, suggestions, failing tests.
:/

@rojizo
Copy link

rojizo commented Jan 10, 2024

I think that behaviour might be less than predictable to most users, even if you personally find it useful. It's probably more straightforward to trigger only on the first exact match (which should really be the only exact match).

In fact, empty matching match the first thing in array which is weird...

Moreover, this fix closes #21128 and #22438.

@rojizo rojizo mentioned this pull request Jan 10, 2024
14 tasks
@rojizo
Copy link

rojizo commented Jan 10, 2024

The match_mnemonic could be implemented as

static bool match_mnemonic(char *mnemonic) {
    uint8_t i = 0;
    for (; input[i]; i++) {
        if (i > count || input[i] != mnemonic[i]) {
            return false;
        }
    }
    return (mnemonic[i] == '\0'); // Here, input[i] is '\0'
}

A conditional compilation variable could be added to switch between behaviours

@tzarc
Copy link
Member

tzarc commented Mar 21, 2024

Unblocked stalebot from doing its thing -- if there's no appetite for fixing unit tests, then there's no need to keep this PR open.

Copy link

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with bug, awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@github-actions github-actions bot added the stale Issues or pull requests that have become inactive without resolution. label May 15, 2024
Copy link

Thank you for your contribution!
This pull request has been automatically closed because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.
// [stale-action-closed]

@github-actions github-actions bot closed this Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes core stale Issues or pull requests that have become inactive without resolution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants