-
Notifications
You must be signed in to change notification settings - Fork 602
libtar: Pull misc Fedora patches, fix CVE-2021-33643, CVE-2021-33644, CVE-2021-33645, CVE-2021-33646 #3686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmcilvaney
merged 3 commits into
microsoft:main
from
dmcilvaney:damcilva/2.0/libtar_cve_sept
Sep 6, 2022
Merged
libtar: Pull misc Fedora patches, fix CVE-2021-33643, CVE-2021-33644, CVE-2021-33645, CVE-2021-33646 #3686
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- libtar-1.2.11/lib/libtar.h.deref 2009-12-30 16:37:03.790121122 +0100 | ||
| +++ libtar-1.2.11/lib/libtar.h 2009-12-30 16:37:35.521246633 +0100 | ||
| @@ -172,6 +172,7 @@ int th_write(TAR *t); | ||
| #define TH_ISDIR(t) ((t)->th_buf.typeflag == DIRTYPE \ | ||
| || S_ISDIR((mode_t)oct_to_int((t)->th_buf.mode)) \ | ||
| || ((t)->th_buf.typeflag == AREGTYPE \ | ||
| + && strlen((t)->th_buf.name) \ | ||
| && ((t)->th_buf.name[strlen((t)->th_buf.name) - 1] == '/'))) | ||
| #define TH_ISFIFO(t) ((t)->th_buf.typeflag == FIFOTYPE \ | ||
| || S_ISFIFO((mode_t)oct_to_int((t)->th_buf.mode))) | ||
| --- libtar-1.2.11/lib/util.c.deref 2003-01-07 02:41:00.000000000 +0100 | ||
| +++ libtar-1.2.11/lib/util.c 2009-12-30 17:35:51.860121660 +0100 | ||
| @@ -148,9 +148,7 @@ oct_to_int(char *oct) | ||
| { | ||
| int i; | ||
|
|
||
| - sscanf(oct, "%o", &i); | ||
| - | ||
| - return i; | ||
| + return sscanf(oct, "%o", &i) == 1 ? i : 0; | ||
| } | ||
|
|
||
|
|
||
|
|
||
40 changes: 40 additions & 0 deletions
40
SPECS/libtar/libtar-1.2.20-CVE-2021-33643-CVE-2021-33644.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| From 3936c7aa74d89e7a91dfbb2c1b7bfcad58a0355d Mon Sep 17 00:00:00 2001 | ||
| From: shixuantong <[email protected]> | ||
| Date: Wed, 6 Apr 2022 17:40:57 +0800 | ||
| Subject: [PATCH 1/2] Ensure that sz is greater than 0. | ||
|
|
||
| --- | ||
| lib/block.c | 10 ++++++++++ | ||
| 1 file changed, 10 insertions(+) | ||
|
|
||
| diff --git a/lib/block.c b/lib/block.c | ||
| index 092bc28..f12c4bc 100644 | ||
| --- a/lib/block.c | ||
| +++ b/lib/block.c | ||
| @@ -118,6 +118,11 @@ th_read(TAR *t) | ||
| if (TH_ISLONGLINK(t)) | ||
| { | ||
| sz = th_get_size(t); | ||
| + if ((int)sz <= 0) | ||
| + { | ||
| + errno = EINVAL; | ||
| + return -1; | ||
| + } | ||
| blocks = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0); | ||
| if (blocks > ((size_t)-1 / T_BLOCKSIZE)) | ||
| { | ||
| @@ -168,6 +173,11 @@ th_read(TAR *t) | ||
| if (TH_ISLONGNAME(t)) | ||
| { | ||
| sz = th_get_size(t); | ||
| + if ((int)sz <= 0) | ||
| + { | ||
| + errno = EINVAL; | ||
| + return -1; | ||
| + } | ||
| blocks = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0); | ||
| if (blocks > ((size_t)-1 / T_BLOCKSIZE)) | ||
| { | ||
| -- | ||
| 2.37.1 | ||
|
|
119 changes: 119 additions & 0 deletions
119
SPECS/libtar/libtar-1.2.20-CVE-2021-33645-CVE-2021-33646.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| From 3c7b1fd9bb63d74ecd38b71ffc876dca3ac87a8b Mon Sep 17 00:00:00 2001 | ||
| From: shixuantong <[email protected]> | ||
| Date: Sat, 7 May 2022 17:04:46 +0800 | ||
| Subject: [PATCH 2/2] fix memory leak | ||
|
|
||
| --- | ||
| lib/libtar.h | 1 + | ||
| lib/util.c | 9 ++++++++- | ||
| lib/wrapper.c | 11 +++++++++++ | ||
| libtar/libtar.c | 3 +++ | ||
| 4 files changed, 23 insertions(+), 1 deletion(-) | ||
|
|
||
| diff --git a/lib/libtar.h b/lib/libtar.h | ||
| index 08a8e0f..8b00e93 100644 | ||
| --- a/lib/libtar.h | ||
| +++ b/lib/libtar.h | ||
| @@ -285,6 +285,7 @@ int oct_to_int(char *oct); | ||
| /* integer to string-octal conversion, no NULL */ | ||
| void int_to_oct_nonull(int num, char *oct, size_t octlen); | ||
|
|
||
| +void free_longlink_longname(struct tar_header th_buf); | ||
|
|
||
| /***** wrapper.c **********************************************************/ | ||
|
|
||
| diff --git a/lib/util.c b/lib/util.c | ||
| index 11438ef..8a42e62 100644 | ||
| --- a/lib/util.c | ||
| +++ b/lib/util.c | ||
| @@ -15,6 +15,7 @@ | ||
| #include <stdio.h> | ||
| #include <sys/param.h> | ||
| #include <errno.h> | ||
| +#include <stdlib.h> | ||
|
|
||
| #ifdef STDC_HEADERS | ||
| # include <string.h> | ||
| @@ -160,4 +161,10 @@ int_to_oct_nonull(int num, char *oct, size_t octlen) | ||
| oct[octlen - 1] = ' '; | ||
| } | ||
|
|
||
| - | ||
| +void free_longlink_longname(struct tar_header th_buf) | ||
| +{ | ||
| + if (th_buf.gnu_longname != NULL) | ||
| + free(th_buf.gnu_longname); | ||
| + if (th_buf.gnu_longlink !=NULL) | ||
| + free(th_buf.gnu_longlink); | ||
| +} | ||
| diff --git a/lib/wrapper.c b/lib/wrapper.c | ||
| index 2d3f5b9..9d2f3bf 100644 | ||
| --- a/lib/wrapper.c | ||
| +++ b/lib/wrapper.c | ||
| @@ -36,7 +36,10 @@ tar_extract_glob(TAR *t, char *globname, char *prefix) | ||
| if (fnmatch(globname, filename, FNM_PATHNAME | FNM_PERIOD)) | ||
| { | ||
| if (TH_ISREG(t) && tar_skip_regfile(t)) | ||
| + { | ||
| + free_longlink_longname(t->th_buf); | ||
| return -1; | ||
| + } | ||
| continue; | ||
| } | ||
| if (t->options & TAR_VERBOSE) | ||
| @@ -46,9 +49,13 @@ tar_extract_glob(TAR *t, char *globname, char *prefix) | ||
| else | ||
| strlcpy(buf, filename, sizeof(buf)); | ||
| if (tar_extract_file(t, buf) != 0) | ||
| + { | ||
| + free_longlink_longname(t->th_buf); | ||
| return -1; | ||
| + } | ||
| } | ||
|
|
||
| + free_longlink_longname(t->th_buf); | ||
| return (i == 1 ? 0 : -1); | ||
| } | ||
|
|
||
| @@ -82,9 +89,13 @@ tar_extract_all(TAR *t, char *prefix) | ||
| "\"%s\")\n", buf); | ||
| #endif | ||
| if (tar_extract_file(t, buf) != 0) | ||
| + { | ||
| + free_longlink_longname(t->th_buf); | ||
| return -1; | ||
| + } | ||
| } | ||
|
|
||
| + free_longlink_longname(t->th_buf); | ||
| return (i == 1 ? 0 : -1); | ||
| } | ||
|
|
||
| diff --git a/libtar/libtar.c b/libtar/libtar.c | ||
| index ac339e7..b992abb 100644 | ||
| --- a/libtar/libtar.c | ||
| +++ b/libtar/libtar.c | ||
| @@ -197,6 +197,7 @@ list(char *tarfile) | ||
| { | ||
| fprintf(stderr, "tar_skip_regfile(): %s\n", | ||
| strerror(errno)); | ||
| + free_longlink_longname(t->th_buf); | ||
| return -1; | ||
| } | ||
| } | ||
| @@ -218,10 +219,12 @@ list(char *tarfile) | ||
|
|
||
| if (tar_close(t) != 0) | ||
| { | ||
| + free_longlink_longname(t->th_buf); | ||
| fprintf(stderr, "tar_close(): %s\n", strerror(errno)); | ||
| return -1; | ||
| } | ||
|
|
||
| + free_longlink_longname(t->th_buf); | ||
| return 0; | ||
| } | ||
|
|
||
| -- | ||
| 2.37.1 | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: The actual upstream patch for this seems to be:
560911b694055b0c677431cf85d4d0d5ebd1a3fdCan we please add a little context to this patch so that it becomes easy for us latter when we bump the version :)
How about something like
git format-patch -1 560911b694055b0c677431cf85d4d0d5ebd1a3fdReference: https://repo.or.cz/libtar.git/patch/560911b694055b0c677431cf85d4d0d5ebd1a3fd
The idea being, if we have the
upstreamcommit-id for all the applied patches, we can trivially determine what version (tags) have the specific commit and choose accordingly to either include/exclude them patches when we bump the version.git tag --contains commit-idThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, interesting. Redhat is usually good about grabbing the actual formatted patches. I've updated to the upstream patch,
thanks.