From: Eric S. Raymond Date: Wed, 4 Jun 2014 17:25:16 +0000 (-0400) Subject: Fix insecure config file permissions. X-Git-Tag: 1.13~1 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=8816c7cfd6d5a99ceec9b058ade891019455ffca;p=coverity-submit.git Fix insecure config file permissions. --- diff --git a/NEWS b/NEWS index 0551892..4e96fb8 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ Repository head: Documentation improvements. Code audited with new, stricter pylint. + Insecure positions on your configuration file are automatically fixed. 1.11 @ 2013-09-27 Fix buggy Mercurial commit-id method. diff --git a/coverity-submit b/coverity-submit index 9092886..cbacfe6 100755 --- a/coverity-submit +++ b/coverity-submit @@ -6,7 +6,8 @@ # from __future__ import print_function -import os, pwd, sys, ConfigParser, getopt, tempfile, shutil, datetime, commands +import os, pwd, sys, stat +import ConfigParser, getopt, tempfile, shutil, datetime, commands version = "1.12" @@ -48,17 +49,27 @@ def deduce_userid(): if __name__ == '__main__': name = email = project = token = url = None - config = ConfigParser.RawConfigParser() - if os.path.exists(os.path.expanduser("~/.config/coverity-submit")): - config.read(os.path.expanduser("~/.config/coverity-submit")) - else: - config.read(os.path.expanduser("~/.coverity-submit")) + cfgpaths = [os.path.expanduser(x) + for x in ("~/.config/coverity-submit", "~/.coverity-submit") + if os.path.exists(os.path.expanduser(x))] + + # Security fix + for path in cfgpaths: + if stat.S_IMODE(os.stat(path).st_mode) != (stat.S_IRUSR | stat.S_IWUSR): + sys.stderr.write("coverity-submit: fixing insecure permissions.\n") + os.chmod(path, stat.S_IRUSR | stat.S_IWUSR) def die(complaint): - sys.stderr.write(complaint + "\n") + sys.stderr.write("coverity-submit: " + complaint + "\n") sys.exit(1) - # Gather information that is not project-specific + if len(cfgpaths) == 2: + die("Multiple configuration files.") + config = ConfigParser.RawConfigParser() + if len(cfgpaths) == 1: + config.read(cfgpaths[0]) + + # Gather information that is not project-specific if not "ALL" in config.sections(): config.add_section("ALL") if not config.has_option("ALL", "name"): diff --git a/coverity-submit.xml b/coverity-submit.xml index 32122ee..b83f227 100644 --- a/coverity-submit.xml +++ b/coverity-submit.xml @@ -113,6 +113,12 @@ matches a project, it is selected. Otherwise, a command-line argument can specify the project name; it is a fatal error for the argument, if given, not to match the name of one of the configured project profiles. +Note: because your configuration file contains privileged +information (the per-project Coverity authentication tokens) it should +not have read or write permissions for anyone but its owner set. When +coverity-submit detects such insecure +permissions, it will fix them (telling you it is doing so). + The option says to display all the commands that would be run without actually executing them. The option enables slightly more verbose progress messages, and copies the Coverity