diff mbox series

[BlueZ,v2,1/5] obexd: add NULL checks to file_stat_line()

Message ID 20240705075709.26809-2-r.smirnov@omp.ru (mailing list archive)
State Accepted
Commit 0fda2dd545fc0c2d879db729ab3be22e88be7072
Headers show
Series fix error found by SVACE static analyzer #2 | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch warning CheckSparse WARNING src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):tools/rctest.c:627:33: warning: non-ANSI function declaration of function 'automated_send_recv'
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/IncrementalBuild success Incremental Build PASS
tedd_an/ScanBuild warning ScanBuild: tools/rctest.c:747:9: warning: Null pointer passed to 1st parameter expecting 'nonnull' if (!strncasecmp(optarg, "hci", 3)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/rctest.c:759:9: warning: Null pointer passed to 1st parameter expecting 'nonnull' if (!strncasecmp(optarg, "hci", 3)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tools/rctest.c:766:14: warning: Null pointer passed to 1st parameter expecting 'nonnull' channel = atoi(optarg); ^~~~~~~~~~~~ tools/rctest.c:770:9: warning: Null pointer passed to 1st parameter expecting 'nonnull' if (!strcasecmp(optarg, "spp")) ^~~~~~~~~~~~~~~~~~~~~~~~~ tools/rctest.c:795:13: warning: Null pointer passed to 1st parameter expecting 'nonnull' linger = atoi(optarg); ^~~~~~~~~~~~ tools/rctest.c:799:18: warning: Null pointer passed to 1st parameter expecting 'nonnull' defer_setup = atoi(optarg); ^~~~~~~~~~~~ tools/rctest.c:811:17: warning: Null pointer passed to 1st parameter expecting 'nonnull' num_frames = atoi(optarg); ^~~~~~~~~~~~ tools/rctest.c:815:12: warning: Null pointer passed to 1st parameter expecting 'nonnull' count = atoi(optarg); ^~~~~~~~~~~~ tools/rctest.c:819:12: warning: Null pointer passed to 1st parameter expecting 'nonnull' delay = atoi(optarg) * 1000; ^~~~~~~~~~~~ tools/rctest.c:823:15: warning: Null pointer passed to 1st parameter expecting 'nonnull' priority = atoi(optarg); ^~~~~~~~~~~~ 10 warnings generated.

Commit Message

Roman Smirnov July 5, 2024, 7:57 a.m. UTC
gmtime() may return NULL. It is necessary to prevent
dereferencing of a NULL pointer.

Found with the SVACE static analysis tool.
---
 obexd/plugins/filesystem.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

bluez.test.bot@gmail.com July 5, 2024, 11:36 a.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=868674

---Test result---

Test Summary:
CheckPatch                    PASS      1.30 seconds
GitLint                       PASS      0.96 seconds
BuildEll                      PASS      24.63 seconds
BluezMake                     PASS      1738.36 seconds
MakeCheck                     PASS      13.42 seconds
MakeDistcheck                 PASS      178.63 seconds
CheckValgrind                 PASS      254.80 seconds
CheckSmatch                   WARNING   355.35 seconds
bluezmakeextell               PASS      120.21 seconds
IncrementalBuild              PASS      8162.11 seconds
ScanBuild                     WARNING   1011.55 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):tools/rctest.c:627:33: warning: non-ANSI function declaration of function 'automated_send_recv'
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
tools/rctest.c:747:9: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        if (!strncasecmp(optarg, "hci", 3))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rctest.c:759:9: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        if (!strncasecmp(optarg, "hci", 3))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rctest.c:766:14: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        channel = atoi(optarg);
                                  ^~~~~~~~~~~~
tools/rctest.c:770:9: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        if (!strcasecmp(optarg, "spp"))
                             ^~~~~~~~~~~~~~~~~~~~~~~~~
tools/rctest.c:795:13: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        linger = atoi(optarg);
                                 ^~~~~~~~~~~~
tools/rctest.c:799:18: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        defer_setup = atoi(optarg);
                                      ^~~~~~~~~~~~
tools/rctest.c:811:17: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        num_frames = atoi(optarg);
                                     ^~~~~~~~~~~~
tools/rctest.c:815:12: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        count = atoi(optarg);
                                ^~~~~~~~~~~~
tools/rctest.c:819:12: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        delay = atoi(optarg) * 1000;
                                ^~~~~~~~~~~~
tools/rctest.c:823:15: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                        priority = atoi(optarg);
                                   ^~~~~~~~~~~~
10 warnings generated.



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index 4887a0b8a..a57b25a83 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c
@@ -113,6 +113,7 @@  static char *file_stat_line(char *filename, struct stat *fstat,
 {
 	char perm[51], atime[18], ctime[18], mtime[18];
 	char *escaped, *ret = NULL;
+	struct tm a_gmtime, c_gmtime, m_gmtime;
 
 	snprintf(perm, 50, "user-perm=\"%s%s%s\" group-perm=\"%s%s%s\" "
 			"other-perm=\"%s%s%s\"",
@@ -126,9 +127,16 @@  static char *file_stat_line(char *filename, struct stat *fstat,
 			(fstat->st_mode & 0002 ? "W" : ""),
 			(dstat->st_mode & 0002 ? "D" : ""));
 
-	strftime(atime, 17, "%Y%m%dT%H%M%SZ", gmtime(&fstat->st_atime));
-	strftime(ctime, 17, "%Y%m%dT%H%M%SZ", gmtime(&fstat->st_ctime));
-	strftime(mtime, 17, "%Y%m%dT%H%M%SZ", gmtime(&fstat->st_mtime));
+	if (!gmtime_r(&fstat->st_atime, &a_gmtime) ||
+			!gmtime_r(&fstat->st_ctime, &c_gmtime) ||
+			!gmtime_r(&fstat->st_mtime, &m_gmtime)) {
+		error("gmtime_r() returned NULL");
+		return ret;
+	}
+
+	strftime(atime, 17, "%Y%m%dT%H%M%SZ", &a_gmtime);
+	strftime(ctime, 17, "%Y%m%dT%H%M%SZ", &c_gmtime);
+	strftime(mtime, 17, "%Y%m%dT%H%M%SZ", &m_gmtime);
 
 	escaped = g_markup_escape_text(filename, -1);