Bug#751254: sleepd: Integer overflow while calculating battery percentage
Package: sleepd Version: 2.05 Severity: normal Tags: patch Dear Maintainer, *** Reporter, please consider answering these questions, where appropriate *** * What led up to the situation? My laptop got suspended immediately when the AC power off. * What exactly did you do (or not do) that was effective (or ineffective)? I find the problem: Integer overflow while calculating battery percentage. * What was the outcome of this action? * What outcome did you expect instead? Here is a concrete description: http://kdr2.com/tech/linux/1406-sleepd- bug-batt-cap.html , and there's a patch in the attachement. *** End of the template - remove these template lines *** -- System Information: Debian Release: jessie/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 3.10.27 (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages sleepd depends on: ii libc62.19-1 ii libglib2.0-0 2.40.0-3 ii libupower-glib1 0.9.23-2+b2 ii lsb-base 4.1+Debian13 Versions of packages sleepd recommends: ii pm-utils 1.4.1-14 ii upower0.9.23-2+b2 sleepd suggests no packages. -- Configuration Files: /etc/default/sleepd changed [not included] >From 5eef101c0b5360a6da4219c94d2086008373520b Mon Sep 17 00:00:00 2001 From: KDr2 Date: Wed, 11 Jun 2014 18:35:29 +0800 Subject: [PATCH] use int64_t for battery capacity to avoid integer overflow --- acpi.c | 14 +++--- acpi.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/acpi.c b/acpi.c index 38bf820..417ce67 100644 --- a/acpi.c +++ b/acpi.c @@ -27,7 +27,7 @@ char acpi_batt_info[ACPI_MAXITEM][128]; /* Filenames of the battery status files for each system battery. */ char acpi_batt_status[ACPI_MAXITEM][128]; /* Stores battery capacity, or 0 if the battery is absent. */ -int acpi_batt_capacity[ACPI_MAXITEM]; +int64_t acpi_batt_capacity[ACPI_MAXITEM]; int acpi_ac_count = 0; char acpi_ac_adapter_info[ACPI_MAXITEM][128]; @@ -86,15 +86,15 @@ int strmcmp(const char *s1, const char *s2) /* Given a buffer holding an acpi file, searches for the given key in it, * and returns the numeric value. 0 is returned on failure. */ -inline int scan_acpi_num (const char *buf, const char *key) { +inline int64_t scan_acpi_num (const char *buf, const char *key) { char *ptr; - int ret = 0; + int64_t ret = 0; do { ptr = strchr(buf, '\n'); if (!strmcmp(buf, key)) { if ((ptr = strchr(buf, '='))) { -sscanf(ptr + 1, "%d", &ret); +sscanf(ptr + 1, "%ld", &ret); return ret; } else { return 0; @@ -145,14 +145,14 @@ char *get_acpi_value (const char *file, const char *key) { /* Returns the last full charge capacity of a battery. */ -int get_acpi_batt_capacity(int battery) { +int64_t get_acpi_batt_capacity(int battery) { char *s; s = get_acpi_value(acpi_batt_info[battery], acpi_labels[label_last_full_capacity]); if (s == NULL) { return 0; } else { - return atoi(s); + return atoll(s); } } @@ -327,7 +327,7 @@ int acpi_read (int battery, apm_info *info) { /* Work out if the battery is present, and what percentage of full * it is and how much time is left. */ if (strcmp(scan_acpi_value(buf, acpi_labels[label_present]), "1") == 0) { - int pcap = scan_acpi_num(buf, acpi_labels[label_remaining_capacity]); + int64_t pcap = scan_acpi_num(buf, acpi_labels[label_remaining_capacity]); state = scan_acpi_value(buf, acpi_labels[label_charging_state]); if (state) { if (state[0] == 'D') { /* discharging */ diff --git a/acpi.h b/acpi.h index f82cba7..f7c77cc 100644 --- a/acpi.h +++ b/acpi.h @@ -20,10 +20,10 @@ int acpi_supported (void); int acpi_read (int battery, apm_info *info); #endif char *get_acpi_file (const char *file); -int scan_acpi_num (const char *buf, const char *key); +int64_t scan_acpi_num (const char *buf, const char *key); char *scan_acpi_value (const char *buf, const char *key); char *get_acpi_value (const char *file, const char *key); -int get_acpi_batt_capacity(int battery); +int64_t get_acpi_batt_capacity(int battery); extern int acpi_batt_count; /* Filenames of the battery info files for each system battery. */ @@ -31,7 +31,7 @@ extern char acpi_batt_info[ACPI_MAXITEM][128]; /* Filenames of the battery status files for each system battery. */ extern char acpi_batt_status[ACPI_MAXITEM][128]; /* Stores battery capacity, or 0 if the battery is absent. */ -extern int acpi_batt_capacity[ACPI_MAXITEM]; +extern int64_t acpi_batt_capacity[ACPI_MAXITEM]; extern int acpi_ac_count; extern char acpi_ac_adapter_info[ACPI_MAXITEM][128]; -- 2.0.0
Bug#731763: This bug also happens on my Debian jessie
root@Debian-X230:~# aptitude upgrade Resolving dependencies... The following NEW packages will be installed: libclang-common-3.3-dev{a} The following partially installed packages will be configured: clang clang-3.3 0 packages upgraded, 1 newly installed, 0 to remove and 30 not upgraded. Need to get 0 B/294 kB of archives. After unpacking 3,663 kB will be used. Do you want to continue? [Y/n/?] (Reading database ... 259623 files and directories currently installed.) Preparing to unpack .../libclang-common-3.3-dev_1%3a3.3-15_amd64.deb ... Unpacking libclang-common-3.3-dev (1:3.3-15) ... dpkg: error processing archive /var/cache/apt/archives/libclang-common-3.3-dev_1%3a3.3-15_amd64.deb (--unpack): trying to overwrite '/usr/lib/llvm-3.3/lib/libprofile_rt.a', which is also in package libclang-common-dev 1:3.3~svn177638-1 dpkg-deb: error: subprocess paste was killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/libclang-common-3.3-dev_1%3a3.3-15_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1) A package failed to install. Trying to recover: dpkg: dependency problems prevent configuration of clang-3.3: clang-3.3 depends on libclang-common-3.3-dev (= 1:3.3-15); however: Package libclang-common-3.3-dev is not installed. dpkg: error processing package clang-3.3 (--configure): dependency problems - leaving unconfigured dpkg: dependency problems prevent configuration of clang: clang depends on clang-3.3 (>= 3.3-1~); however: Package clang-3.3 is not configured yet. dpkg: error processing package clang (--configure): dependency problems - leaving unconfigured Errors were encountered while processing: clang-3.3 clang root@Debian-X230:~# more /etc/issue Debian GNU/Linux jessie/sid \n \l root@Debian-X230:~# uname -a Linux Debian-X230 3.10.23 #5 SMP Tue Dec 10 17:46:58 CST 2013 x86_64 GNU/Linux root@Debian-X230:~# dpkg -l|grep clang iU clang 1:3.3-21 amd64C, C++ and Objective-C compiler (LLVM based) iU clang-3.3 1:3.3-15 amd64C, C++ and Objective-C compiler (LLVM based) ii libclang-common-dev1:3.3~svn177638-1 amd64clang library - Common development package ii libclang1:amd641:3.3-21 amd64C, C++ and Objective-C compiler (LLVM based) ii libclang1-3.3:amd641:3.3-15 amd64C interface to the clang library root@Debian-X230:~# -- -- KDr2, http://kdr2.net
Bug#709142: dpkg: error processing tex-common (--configure): updmap-sys failed
Package: tex-common Version: 4.03 Severity: normal Dear Maintainer, *** Please consider answering these questions, where appropriate *** * What led up to the situation? * What exactly did you do (or not do) that was effective (or ineffective)? * What was the outcome of this action? * What outcome did you expect instead? *** End of the template - remove these lines *** -- System Information: Debian Release: jessie/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 3.6.11+ (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages tex-common depends on: ii debconf [debconf-2.0] 1.5.50 ii dpkg 1.16.10 ii ucf3.0027 tex-common recommends no packages. Versions of packages tex-common suggests: ii debhelper 9.20130518 Versions of packages texlive-base depends on: ii debconf [debconf-2.0] 1.5.50 ii dpkg 1.16.10 ii install-info 5.1.dfsg.1-3 ii libpaper-utils 1.1.24+nmu2 iu luatex 0.76.0-2 ii texlive-binaries 2012.20120628-4 ii texlive-common 2012.20120611-5 ii texlive-doc-base 2012.20120611-1 ii ucf3.0027 ii xdg-utils 1.1.0~rc1+git20111210-7 Versions of packages texlive-base recommends: ii lmodern 2.004.4-3 Versions of packages texlive-base suggests: ii evince [postscript-viewer] 3.4.0-3.1 ii ghostscript [postscript-viewer] 9.05~dfsg-6.3 pn perl-tk pn xpdf-reader | pdf-viewer Versions of packages texlive-binaries depends on: ii dpkg1.16.10 ii ed 1.8-1 ii install-info5.1.dfsg.1-3 ii libc6 2.17-3 ii libfontconfig1 2.9.0-7.1 ii libfreetype62.4.9-1.1 ii libgcc1 1:4.8.0-7 ii libgraphite31:2.3.1-0.2 ii libgs9 9.05~dfsg-6.3 ii libkpathsea62013.20130516.30500-1 ii libpng12-0 1.2.49-4 ii libpoppler190.18.4-6 ii libptexenc1 2013.20130516.30500-1 ii libstdc++6 4.8.0-7 ii libx11-62:1.5.0-1 ii libxaw7 2:1.0.10-2 ii libxmu6 2:1.1.1-1 ii libxpm4 1:3.5.10-1 ii libxt6 1:1.1.3-1 ii perl5.14.2-21 ii texlive-common 2012.20120611-5 ii zlib1g 1:1.2.8.dfsg-1 Versions of packages texlive-binaries recommends: iu luatex0.76.0-2 ii python2.7.3-5 ii ruby 1:1.9.3 ii texlive-base 2012.20120611-5 ii tk8.5 [wish] 8.5.11-2 -- debconf information: texlive-base/texconfig_ignorant: tex-common/check_texmf_wrong: updmap: Cannot find TEXMFROOT, aborting! updmap: Cannot find TEXMFROOT, aborting!