Minor binary-search int overflow in timezone code

From: Christoph Berg <cb(at)df7cb(dot)de>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Minor binary-search int overflow in timezone code
Date: 2014-12-15 11:17:54
Message-ID: 20141215111754.GF6506@msg.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

a fellow Debian Developer found a minor glitch in
src/timezone/localtime.c, where binary search is used. Now I don't
think there is an actual problem (unless there's > 2^30 timezones),
but it would at least make sense to mark the code as okayish so that
people running code scanners won't stumble over the issue again.

The attached patch added comments to address this.

Date: Sun, 30 Nov 2014 22:06:42 +0100
From: Niels Thykier <niels(at)thykier(dot)net>
Reply-To: Niels Thykier <niels(at)thykier(dot)net>, 771580(at)bugs(dot)debian(dot)org
To: Debian Bug Tracking System <submit(at)bugs(dot)debian(dot)org>
Subject: [Pkg-postgresql-public] Bug#771580: postgresql-9.4: Minor binary-search
int overflow

Source: postgresql-9.4
Version: 9.4~rc1-1
Severity: minor

Hi,

I stumbled on the folowing snippet from src/timezone/localtime.c,
function pg_interpret_timezone_abbrev:

{
int lo = 0;
int hi = sp->timecnt;

while (lo < hi)
{
int mid = (lo + hi) >> 1;
^^^^^^^

This looks it is subject to a known int overflow, when (original) hi
is close to INT_MAX and the item being close to then end of the array.

~Niels

[The original report had a link here to the googleresearch blog , but
the PG list servers think it is spam :(]

Attachment Content-Type Size
timezone-binary-search.patch text/x-diff 1.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2014-12-15 11:42:10 Re: replicating DROP commands across servers
Previous Message José Luis Tallón 2014-12-15 11:09:45 Re: On partitioning