-
Notifications
You must be signed in to change notification settings - Fork 549
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
Fix CVE-2024-5742 for nano :3.0 #11176
Open
KavyaSree2610
wants to merge
2
commits into
fasttrack/3.0
Choose a base branch
from
kkaitepalli/nano-CVE-2024-5742
base: fasttrack/3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−2
Open
Changes from all commits
Commits
Show all changes
2 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 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,89 @@ | ||
From 1a0861639022a9237a22349e0f07f2b61e89d244 Mon Sep 17 00:00:00 2001 | ||
From: kavyasree <[email protected]> | ||
Date: Thu, 21 Nov 2024 14:30:20 +0530 | ||
Subject: [PATCH] Fix CVE-2024-5742 | ||
|
||
--- | ||
src/definitions.h | 2 +- | ||
src/files.c | 13 ++++++++++++- | ||
src/nano.c | 12 +----------- | ||
3 files changed, 14 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/src/definitions.h b/src/definitions.h | ||
index 5c517a3..f308043 100644 | ||
--- a/src/definitions.h | ||
+++ b/src/definitions.h | ||
@@ -275,7 +275,7 @@ typedef enum { | ||
} message_type; | ||
|
||
typedef enum { | ||
- OVERWRITE, APPEND, PREPEND | ||
+ OVERWRITE, APPEND, PREPEND, EMERGENCY | ||
} kind_of_writing_type; | ||
|
||
typedef enum { | ||
diff --git a/src/files.c b/src/files.c | ||
index e2bbfe1..561d36b 100644 | ||
--- a/src/files.c | ||
+++ b/src/files.c | ||
@@ -1729,6 +1729,8 @@ bool write_file(const char *name, FILE *thefile, bool normal, | ||
#endif | ||
char *realname = real_dir_from_tilde(name); | ||
/* The filename after tilde expansion. */ | ||
+ int fd = 0; | ||
+ /* The descriptor that is assigned when opening the file. */ | ||
char *tempname = NULL; | ||
/* The name of the temporary file we use when prepending. */ | ||
linestruct *line = openfile->filetop; | ||
@@ -1812,7 +1814,6 @@ bool write_file(const char *name, FILE *thefile, bool normal, | ||
* For an emergency file, access is restricted to just the owner. */ | ||
if (thefile == NULL) { | ||
mode_t permissions = (normal ? RW_FOR_ALL : S_IRUSR|S_IWUSR); | ||
- int fd; | ||
|
||
#ifndef NANO_TINY | ||
block_sigwinch(TRUE); | ||
@@ -1939,6 +1940,16 @@ bool write_file(const char *name, FILE *thefile, bool normal, | ||
} | ||
#endif | ||
|
||
+#if !defined(NANO_TINY) && defined(HAVE_CHMOD) && defined(HAVE_CHOWN) | ||
+ /* Change permissions and owner of an emergency save file to the values | ||
+ * of the original file, but ignore any failure as we are in a hurry. */ | ||
+ if (method == EMERGENCY && fd && openfile->statinfo) { | ||
+ IGNORE_CALL_RESULT(fchmod(fd, openfile->statinfo->st_mode)); | ||
+ IGNORE_CALL_RESULT(fchown(fd, openfile->statinfo->st_uid, | ||
+ openfile->statinfo->st_gid)); | ||
+ } | ||
+#endif | ||
+ | ||
if (fclose(thefile) != 0) { | ||
statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno)); | ||
|
||
diff --git a/src/nano.c b/src/nano.c | ||
index 35f466b..9c2f0b2 100644 | ||
--- a/src/nano.c | ||
+++ b/src/nano.c | ||
@@ -337,18 +337,8 @@ void emergency_save(const char *filename) | ||
|
||
if (*targetname == '\0') | ||
fprintf(stderr, _("\nToo many .save files\n")); | ||
- else if (write_file(targetname, NULL, SPECIAL, OVERWRITE, NONOTES)) { | ||
+ else if (write_file(targetname, NULL, SPECIAL, EMERGENCY, NONOTES)) | ||
fprintf(stderr, _("\nBuffer written to %s\n"), targetname); | ||
-#if !defined(NANO_TINY) && defined(HAVE_CHMOD) && defined(HAVE_CHOWN) | ||
- /* Try to chmod/chown the saved file to the values of the original file, | ||
- * but ignore any failure as we are in a hurry to get out. */ | ||
- if (openfile->statinfo) { | ||
- IGNORE_CALL_RESULT(chmod(targetname, openfile->statinfo->st_mode)); | ||
- IGNORE_CALL_RESULT(chown(targetname, openfile->statinfo->st_uid, | ||
- openfile->statinfo->st_gid)); | ||
- } | ||
-#endif | ||
- } | ||
|
||
free(targetname); | ||
free(plainname); | ||
-- | ||
2.34.1 | ||
|
This file contains 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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
Summary: Text editor | ||
Name: nano | ||
Version: 6.4 | ||
Release: 1%{?dist} | ||
Release: 2%{?dist} | ||
License: GPLv3+ | ||
Vendor: Microsoft Corporation | ||
Distribution: Azure Linux | ||
Group: Applications/Editors | ||
URL: https://www.nano-editor.org/ | ||
Source0: http://www.nano-editor.org/dist/v6/%{name}-%{version}.tar.xz | ||
Patch0: CVE-2024-5742.patch | ||
|
||
BuildRequires: ncurses-devel | ||
Requires: ncurses | ||
|
||
|
@@ -22,7 +24,7 @@ Requires: %{name} = %{version}-%{release} | |
Lang for nano | ||
|
||
%prep | ||
%setup -q | ||
%autosetup -p1 | ||
|
||
%build | ||
%configure --enable-utf8 \ | ||
|
@@ -52,6 +54,9 @@ make %{?_smp_mflags} check | |
%{_docdir}/%{name}-%{version}/* | ||
|
||
%changelog | ||
* Thu Nov 21 2024 Kavya Sree Kaitepalli <[email protected]> - 6.4-2 | ||
- Patch for CVE-2024-5742 | ||
|
||
* Fri Oct 27 2023 CBL-Mariner Servicing Account <[email protected]> - 6.4-1 | ||
- Auto-upgrade to 6.4 - Azure Linux 3.0 - package upgrades | ||
|
||
|
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.
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.
The %setup needs to be changed to %autosetup.
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.
Switched it to
%autosetup -p1