-
Notifications
You must be signed in to change notification settings - Fork 12
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
Battery life in picoarch #5
Comments
Still unable to replicate, adding logging mechanism for affected devices |
Saw this post on Reddit regarding the battery prematurely warning for reference. I saw you're adding a logging mechanism, let me know if there's any way I can help! https://reddit.com/r/MiyooMini/comments/12nrldl/we_need_to_talk_about_the_myioo_mini_battery/ |
I think this will fix it, as there is a fun combination of buffer overflow (when batt is full) and underflow (always) when r/w the batt level to /tmp/battery. As there is a chance of the strlen to be anything random when batt==100 it can write whatever, also as the null byte was missing the read side could also read any garbage to fscanf as the string isnt terminated. keymon.c void checkAXP() {
// Code adapted from OnionOS
char *cmd = "cd /customer/app/ ; ./axp_test";
int batJsonSize = 100;
char buf[batJsonSize];
int battery_number;
FILE *fp;
fp = popen(cmd, "r");
if (fgets(buf, batJsonSize, fp) != NULL) {
sscanf(buf, "{\"battery\":%d, \"voltage\":%*d, \"charging\":%*d}", &battery_number);
}
pclose(fp);
int bat_fd = open("/tmp/battery", O_CREAT | O_WRONLY | O_TRUNC);
if (bat_fd>0) {
- char value[3];
+ char value[4];
sprintf(value, "%d", battery_number);
- write(bat_fd, value, strlen(value));
+ write(bat_fd, value, strlen(value)+1);
close(bat_fd);
}
} |
Need to reconfigure the battery level for picoarch, not accurate and warning prematurely.
The text was updated successfully, but these errors were encountered: