summaryrefslogtreecommitdiff
path: root/src/diff_print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diff_print.c')
-rw-r--r--src/diff_print.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 09bf77aef..7c9af2449 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -208,6 +208,7 @@ static int diff_print_one_raw(
{
diff_print_info *pi = data;
git_buf *out = pi->buf;
+ int id_abbrev;
char code = git_diff_status_char(delta->status);
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -218,6 +219,16 @@ static int diff_print_one_raw(
git_buf_clear(out);
+ id_abbrev = delta->old_file.mode ? delta->old_file.id_abbrev :
+ delta->new_file.id_abbrev;
+
+ if (pi->oid_strlen - 1 > id_abbrev) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ id_abbrev, pi->oid_strlen);
+ return -1;
+ }
+
git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.id);
git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.id);
@@ -252,6 +263,22 @@ static int diff_print_oid_range(
{
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
+ if (delta->old_file.mode &&
+ oid_strlen - 1 > delta->old_file.id_abbrev) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ delta->old_file.id_abbrev, oid_strlen);
+ return -1;
+ }
+
+ if ((delta->new_file.mode &&
+ oid_strlen - 1 > delta->new_file.id_abbrev)) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ delta->new_file.id_abbrev, oid_strlen);
+ return -1;
+ }
+
git_oid_tostr(start_oid, oid_strlen, &delta->old_file.id);
git_oid_tostr(end_oid, oid_strlen, &delta->new_file.id);