Git development
 help / color / mirror / Atom feed
From: Robert Watson <robert.oo.watson@gmail.com>
To: git@vger.kernel.org
Subject: minor problems in git.c
Date: Thu, 1 Dec 2005 12:00:54 +0000	[thread overview]
Message-ID: <72499e3b0512010400i1de76ed2la22cd745f811007f@mail.gmail.com> (raw)

Hi,

There are some minor problems in git.c:

(1) potential buffer overrun.

        strncat(&git_command[len], "/git-", sizeof(git_command) - len);
        len += 5;
        strncat(&git_command[len], argv[i], sizeof(git_command) - len);

The first line will write one byte ('\0') beyond the end of
git_command, when sizeof(git_command) - len == 5.

The second line increase len by 5, without regarding how many bytes
are written in the first line.  It is possible to make len greater
than sizeof(git_command), therefore make the third argument of the
third line underflow, allowing almost any number of bytes from argv[1]
to be copied.

(2) environ

int main(int argc, char **argv, char **envp)
{
  ...
  execve(git_command, &argv[i], envp);
  ...
}

I am wondering whether the global variable "environ" could change when
you do setenv.  Would it be clear by using the "environ" as the third
argument of evecve()?

(3) printf("Failed to run command '%s': %s\n", git_command, strerror(errno));
should go to stderr?

Regards,
Robertoo

             reply	other threads:[~2005-12-01 12:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-01 12:00 Robert Watson [this message]
2005-12-01 12:48 ` minor problems in git.c Alex Riesen
2005-12-01 13:51   ` Sven Verdoolaege
2005-12-01 14:02     ` Alex Riesen
2005-12-02  1:07       ` Junio C Hamano
2005-12-02  8:12         ` Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72499e3b0512010400i1de76ed2la22cd745f811007f@mail.gmail.com \
    --to=robert.oo.watson@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox