Package: powertop
Version: 1.11-1
Severity: serious
File: /usr/sbin/powertop

Dear mainteners,

The powertop command crashes if there are more than 5000 lines in the
kernel configuration file located in /boot/config-*, or if there is a
line longer than 100 characters (for info, the kernel 2.6.32-5-amd64 in
backport has a config file containing 5415 lines, the longest of 162
characters).

This crash comes from the static and fixed-size array defined in
config.c. This has not been fixed in the latest version of powertop that
seems to be available (1.12).

I attach an (still atrocious) patched version of config.c that should
not crash for a few releases of the kernel.

Cheers,

/*
 * Copyright 2007, Intel Corporation
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authors:
 * 	Arjan van de Ven <ar...@linux.intel.com>
 */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <dirent.h>

#include "powertop.h"

#define NB_CONFIG_LINES_MAX 10000
#define STRING_BUFFER_SIZE 256

/* static arrays are not nice programming.. but they're easy */
static char configlines[NB_CONFIG_LINES_MAX][STRING_BUFFER_SIZE];
static int configcount;

static void read_kernel_config(void)
{
	FILE *file;
	char version[STRING_BUFFER_SIZE], *c;
	char filename[STRING_BUFFER_SIZE];
	if (configcount)
		return;
	if (access("/proc/config.gz", R_OK) == 0) {
		file = popen("zcat /proc/config.gz 2> /dev/null", "r");
		while (file && !feof(file)) {
			char line[STRING_BUFFER_SIZE];
			if (fgets(line, STRING_BUFFER_SIZE, file) == NULL)
				break;
			strcpy(configlines[configcount++], line);
		}
		pclose(file);
		return;
	}
	file = fopen("/proc/sys/kernel/osrelease", "r");
	if (!file)
		return;
	if (fgets(version, STRING_BUFFER_SIZE, file) == NULL) {
		fclose(file);
		return;
	}
	fclose(file);
	c = strchr(version, '\n');
	if (c)
		*c = 0;
	sprintf(filename, "/boot/config-%s", version);
	file = fopen(filename, "r");
	if (!file) {
		sprintf(filename, "/lib/modules/%s/build/.config", version);
		file = fopen(filename, "r");
	}
	if (!file)
		return;
	while (!feof(file)) {
		char line[STRING_BUFFER_SIZE];
		if (fgets(line, STRING_BUFFER_SIZE, file) == NULL)
			break;
		strcpy(configlines[configcount++], line);
	}
	fclose(file);
}

/*
 * Suggest the user to turn on/off a kernel config option.
 * "comment" gets displayed if it's not already set to the right value 
 */
void suggest_kernel_config(char *string, int onoff, char *comment, int weight)
{
	int i;
	char searchon[STRING_BUFFER_SIZE];
	char searchoff[STRING_BUFFER_SIZE];
	int found = 0;

	read_kernel_config();

	sprintf(searchon, "%s=", string);
	sprintf(searchoff, "# %s is not set", string);

	for (i = 0; i < configcount; i++) {
		if (onoff && strstr(configlines[i], searchon))
			return;
		if (onoff==0 && strstr(configlines[i], searchoff))
			return;
		if (onoff==0 && strstr(configlines[i], searchon))
			found = 1;
	}
	if (onoff || found)
		add_suggestion(comment, weight, 0, NULL, NULL);
	fflush(stdout);
}
-- System Information:
Debian Release: 6.0.3
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.39-bpo.2-amd64 (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 powertop depends on:
ii  libc6                     2.11.2-10      Embedded GNU C Library: Shared lib
ii  libncursesw5              5.7+20100313-5 shared libraries for terminal hand

powertop recommends no packages.

Versions of packages powertop suggests:
pn  cpufrequtils                  <none>     (no description available)
pn  laptop-mode-tools             <none>     (no description available)

-- no debconf information

-- 
Francois Fleuret                         http://www.idiap.ch/~fleuret/

Reply via email to