Skip to content
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

CI: Add github code quality analysis (codeql) #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thesamesam
Copy link
Contributor

No description provided.

@N-R-K
Copy link
Contributor

N-R-K commented Jan 28, 2023

The following patch should solve one of the issues reported in the codeql scan. It also removes usage of utime which seems to be deprecated by POSIX 1

diff --git a/src/swclock/swclock.c b/src/swclock/swclock.c
index e526bd38..83b15c95 100644
--- a/src/swclock/swclock.c
+++ b/src/swclock/swclock.c
@@ -78,14 +78,12 @@ int main(int argc, char **argv)
 		eerrorx("swclock: Reference file was not specified");
 
 	if (sflag) {
-		if (stat(file, &sb) == -1) {
-			opt = open(file, O_WRONLY | O_CREAT, 0644);
-			if (opt == -1)
-				eerrorx("swclock: open: %s", strerror(errno));
-			close(opt);
-		} else
-			if (utime(file, NULL) == -1)
-				eerrorx("swclock: utime: %s", strerror(errno));
+		int fd = open(file, O_WRONLY | O_CREAT, 0644);
+		if (fd == -1)
+			eerrorx("swclock: open: %s", strerror(errno));
+		if (futimens(fd, NULL) == -1)
+			eerrorx("swclock: futimens: %s", strerror(errno));
+		close(fd);
 		return 0;
 	}
 

Footnotes

  1. https://www.man7.org/linux/man-pages/man3/utime.3p.html#FUTURE_DIRECTIONS

@vapier
Copy link
Member

vapier commented Jan 28, 2023

can you send a PR ? we're not going to copy & paste patches from comments ...

@N-R-K
Copy link
Contributor

N-R-K commented Jan 28, 2023

can you send a PR ? we're not going to copy & paste patches from comments ...

Sure. I was thinking @thesamesam might have wanted to add that to this PR since it's somewhat related.

EDIT: done at #591

pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a schedule for it when it already fires on pushes & pull requests ?

@@ -0,0 +1,52 @@
name: "CodeQL"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have a comment block at the top explaining what this is about and links to relevant docs

# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move URL to next line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants