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

Battery life in picoarch #5

Open
Xpndable opened this issue Mar 27, 2023 · 3 comments
Open

Battery life in picoarch #5

Xpndable opened this issue Mar 27, 2023 · 3 comments
Labels
bug Something isn't working on hold Will be fixed when more information is available

Comments

@Xpndable
Copy link
Owner

Need to reconfigure the battery level for picoarch, not accurate and warning prematurely.

@Xpndable Xpndable added the bug Something isn't working label Mar 27, 2023
@Xpndable
Copy link
Owner Author

Xpndable commented Apr 2, 2023

Still unable to replicate, adding logging mechanism for affected devices

@Xpndable Xpndable added the on hold Will be fixed when more information is available label Apr 2, 2023
@Xpndable Xpndable moved this to In Progress in DotUI v1.0 Apr 5, 2023
@birby0
Copy link

birby0 commented Apr 16, 2023

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/

@anzz1
Copy link

anzz1 commented May 5, 2023

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);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on hold Will be fixed when more information is available
Projects
Status: In Progress
Development

No branches or pull requests

3 participants