From 4e9e4b7ae361c975661cca96483ca974826e39d6 Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Fri, 18 Mar 2011 15:15:00 +0000 Subject: - add basic validation for .pc files, at least Name, Description and Version have to be set. this is what fd.o pkg-config requires at least. --- usr.bin/pkg-config/pkg-config | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/usr.bin/pkg-config/pkg-config b/usr.bin/pkg-config/pkg-config index 929fec50d52..8fe37c9b3ee 100644 --- a/usr.bin/pkg-config/pkg-config +++ b/usr.bin/pkg-config/pkg-config @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: pkg-config,v 1.36 2011/03/18 15:13:33 jasper Exp $ +# $OpenBSD: pkg-config,v 1.37 2011/03/18 15:14:59 jasper Exp $ #$CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $ # Copyright (c) 2006 Chris Kuethe @@ -294,7 +294,7 @@ sub get_config $cfg = OpenBSD::PkgConfig->read_file($f); }; if (!$@) { - return $cfg; + return validate_config($f, $cfg); } else { print STDERR $@, "\n" if $D; } @@ -314,6 +314,24 @@ sub cache_find_config } } +# Required elements for a valid .pc file: Name, Description, Version +sub validate_config +{ + my ($f, $cfg) = @_; + my @required_elems = ('Name', 'Description', 'Version'); + my $e; + + foreach (@required_elems) { + $e = $cfg->get_property($_, $variables); + if (!defined $e) { + print STDERR "incomplete or corrupt file: $f\n" if $D; + return undef; + } + } + + return $cfg; +} + # pkg-config won't install a pkg-config.pc file itself, but it may be # listed as a dependency in other files. -- cgit v1.2.3