pg_createcluster crashes when a username or group is specified that contains digits

Bug #1329227 reported by Sven Berkvens-Matthijsse
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
postgresql-common (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

pg_createcluster accepts options --user and --group to specify under which credentials a new database cluster should be created. According to the manual page, one may specify either a name or a UID/GID (as digits).

The implementation, however, tests whether there is a digit in the given string, not whether the entire string consists of digits. This causes problems for me: I have a development system where each developer creates databases and such per ticket. Users and groups are created for this purpose, named "ticketNNN" where NNN is the number of the ticket that the developer has been given to implement or bug fix. But pg_createcluster does not like these user and group names, for example "ticket123": it thinks I specified a UID/GID instead of a name, and does the wrong thing. It crashes later on when tries to use the string as a number. This is what it says on my Precise system specifically:

Argument "ticket123" isn't numeric in getpwuid at /usr/share/postgresql-common/PgCommon.pm line 790.
Argument "ticket123" isn't numeric in scalar assignment at /usr/share/postgresql-common/PgCommon.pm line 796.
Argument "ticket123" isn't numeric in numeric ne (!=) at /usr/share/postgresql-common/PgCommon.pm line 799.

This is because the test on line 237 of pg_createcluster:
    $owneruid = (getpwnam $owneruid)[2] unless $owneruid =~ /\d+/;
is testing the wrong thing. I think it should read:
    $owneruid = (getpwnam $owneruid)[2] unless $owneruid =~ /^\d+$/;

The same happens a few lines down with the group name.

My Ubuntu version information:
Description: Ubuntu 12.04.4 LTS
Release: 12.04

I'm using postgresql-common version 129ubuntu1.

Tags: patch
Revision history for this message
Sven Berkvens-Matthijsse (sven-launchpad) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "Patch for user names and group names containing digits" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks! Applied in bzr.

Changed in postgresql-common (Ubuntu):
status: New → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package postgresql-common - 160

---------------
postgresql-common (160) unstable; urgency=medium

  [ Martin Pitt ]
  * supported-versions: Set 9.4 as default for Ubuntu 14.10.
  * debian/maintscripts-functions: Call update-alternatives under C locale to
    fix parsing for non-English locales. (LP: #1293596)
  * pg_createcluster: Fix test if specified owner/group ID is numeric. Thanks
    Sven Berkvens-Matthijsse! (LP: #1329227)

  [ Christoph Berg ]
  * Use dh-systemd to enable postgresql.service on install. (Closes: #757612)
  * Set Multi-Arch: foreign in postgresql-common, postgresql-client-common,
    postgresql-client, and postgresql-doc, and document this in
    doc/dependencies.{dia,png}. (Closes: #757520)
  * Update examples in README.Debian for 9.4. (Closes: #756007)
  * Install README.systemd.

 -- Christoph Berg <email address hidden> Mon, 11 Aug 2014 15:39:39 +0200

Changed in postgresql-common (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.