前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >git查看某个文件的提交记录

git查看某个文件的提交记录

作者头像
用户1423082
发布2024-12-31 20:13:20
发布2024-12-31 20:13:20
7400
代码可运行
举报
文章被收录于专栏:giantbranch's bloggiantbranch's blog
运行总次数:0
代码可运行

有时候分析漏洞我们需要看看怎么修复的,什么时候谁修复的,提交的id是多少,下面的命令就很有用

假如我们知道漏洞出现在某个文件,我们只要执行下面命令,即可看到这个文件的修改记录

代码语言:javascript
代码运行次数:0
复制
git log -p 文件名

比如下面的例子

代码语言:javascript
代码运行次数:0
复制
$ git log -p slirp/tcp_subr.c
commit 345fab6ffe57b0bf6dccbc0844f45f77b91d9de0
Author: Prasad J Pandit <pjp@fedoraproject.org>
Date:   Sun Jan 13 23:29:48 2019 +0530

    slirp: check data length while emulating ident function

    While emulating identification protocol, tcp_emu() does not check
    available space in the 'sc_rcv->sb_data' buffer. It could lead to
    heap buffer overflow issue. Add check to avoid it.

    Reported-by: Kira <864786842@qq.com>
    Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
    (cherry picked from commit a7104eda7dab99d0cdbd3595c211864cba415905)
    *CVE-2019-6778
    Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>

diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 473c8b0..aa88de8 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -640,6 +640,11 @@ tcp_emu(struct socket *so, struct mbuf *m)
                        socklen_t addrlen = sizeof(struct sockaddr_in);
                        struct sbuf *so_rcv = &so->so_rcv;

+                       if (m->m_len > so_rcv->sb_datalen
+                                       - (so_rcv->sb_wptr - so_rcv->sb_data)) {
+                           return 1;
+                       }
+
                        memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);
                        so_rcv->sb_wptr += m->m_len;
                        so_rcv->sb_rptr += m->m_len;
......
......
......

看到了这个commit id,你可以用git show id去查看,不过跟上面的结果看到的是一样的

代码语言:javascript
代码运行次数:0
复制
$ git show 345fab6ffe57b0bf6dccbc0844f45f77b91d9de0
commit 345fab6ffe57b0bf6dccbc0844f45f77b91d9de0
Author: Prasad J Pandit <pjp@fedoraproject.org>
Date:   Sun Jan 13 23:29:48 2019 +0530

    slirp: check data length while emulating ident function

    While emulating identification protocol, tcp_emu() does not check
    available space in the 'sc_rcv->sb_data' buffer. It could lead to
    heap buffer overflow issue. Add check to avoid it.

    Reported-by: Kira <864786842@qq.com>
    Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
    (cherry picked from commit a7104eda7dab99d0cdbd3595c211864cba415905)
    *CVE-2019-6778
    Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>

diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 473c8b0..aa88de8 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -640,6 +640,11 @@ tcp_emu(struct socket *so, struct mbuf *m)
                        socklen_t addrlen = sizeof(struct sockaddr_in);
                        struct sbuf *so_rcv = &so->so_rcv;

+                       if (m->m_len > so_rcv->sb_datalen
+                                       - (so_rcv->sb_wptr - so_rcv->sb_data)) {
+                           return 1;
+                       }
+
                        memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);
                        so_rcv->sb_wptr += m->m_len;
                        so_rcv->sb_rptr += m->m_len;
(END)

github上直接搜索这个commit id就可以了

题外话

更进一步,假如你想看看这个文件每一行最新是谁修改的,使用git blame 文件名

例子如下:

代码语言:javascript
代码运行次数:0
复制
git blame  slirp/tcp_subr.c
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   1) /*
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   2)  * Copyright (c) 1982, 1986, 1988, 1990, 1993
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   3)  * The Regents of the University of California.  All rights reserved.
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   4)  *
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   5)  * Redistribution and use in source and binary forms, with or without
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   6)  * modification, are permitted provided that the following conditions
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   7)  * are met:
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   8)  * 1. Redistributions of source code must retain the above copyright
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000   9)  *    notice, this list of conditions and the following disclaimer.
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  10)  * 2. Redistributions in binary form must reproduce the above copyright
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  11)  *    notice, this list of conditions and the following disclaimer in the
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  12)  *    documentation and/or other materials provided with the distribution.
2f5f89963 (Anthony Liguori    2009-01-26 19:37:41 +0000  13)  * 3. Neither the name of the University nor the names of its contributors
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  14)  *    may be used to endorse or promote products derived from this software
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  15)  *    without specific prior written permission.
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  16)  *
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  17)  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  18)  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
f0cbd3ec9 (Fabrice Bellard    2004-04-22 00:10:48 +0000  19)  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
......
......
......
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题外话
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档