[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Not everyone is linking shared libraries to libc



Previously Wichert Akkerman wrote:
> Can people please run the attached script on their system and see if it
> finds more broken packages on their system?

The attached script had a slight typo, new version attached.

Wichert.


-- 
  _________________________________________________________________
 /       Nothing is fool-proof to a sufficiently talented fool     \
| wichert@cistron.nl                  http://www.liacs.nl/~wichert/ |
| 1024D/2FA3BC2D 576E 100B 518D 2F16 36B0  2805 3CB8 9250 2FA3 BC2D |
#! /usr/bin/python
#
# check-libc 1.1
# Copyright 2001 Wichert Akkerman <wakkerma@debian.org>
#
# This program 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import os,re,string,stat

libdirs = [ "/lib", "/usr/lib" ]

def filterChild(command, regexp):
	"Run a command and return the regexp matches."

	# Run the command and grab its output
	fd=os.popen(command)
	output=string.split(fd.read(), '\n')
	fd.close()

	# Extract the matches text
	lst=[]
	matcher=re.compile(regexp)
	for line in output:
		mo=matcher.search(line)
		if mo:
			lst.append(mo.groups())
	
	return lst

def scanlibsObjdump(exe):
	"Use objdump to determine the shared libraries a binary uses."

	return map(lambda x: x[0], filterChild(("objdump -p %s" % exe), "^\s+NEEDED\s+(.+)$"))

def seqAdd(file, seq):
	"Add the contents of a file to a seqeuence."

	fd=open(file, 'r')
	map(lambda x,y=seq: y.append(x), string.split(fd.read(), '\n'))

def isLib(file):
	'''Check if a file is a possible shared library. Not highly advanced,
	but good enough for this purpose.'''

	if not stat.S_ISREG(os.lstat(file)[stat.ST_MODE]):
		return 0
	if not re.search("/lib.+\.so.*", file):
		return 0
	return 1

def checkLib(file):
	"Check if a library is linked to libc."

	libs=scanlibsObjdump(file)
	for i in libs:
		if re.match("^libc\.so\.", i):
			return 1

	return 0

# Add more directories to the list of directories to scan
seqAdd("/etc/ld.so.conf", libdirs)

for dir in libdirs:
	try:
		files=os.listdir(dir)
	except OSError:
		continue

	files=map(lambda x,y=dir: "%s/%s" % (y,x), files)
	files=filter(isLib, files)

	for f in files:
		if not checkLib(f):
			print f + " is not linked to libc"


Reply to: