NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/57682: Check if suplied argument(s) has "-" using only argument vectors instead calling strcmp() function.



>Number:         57682
>Category:       bin
>Synopsis:       Check if suplied argument(s) has "-" using only argument vectors instead calling strcmp() function.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 05 10:05:00 +0000 2023
>Originator:     rilysh
>Release:        NetBSD-current
>Organization:
N/A
>Environment:
N/A
>Description:
Hello.

In 'bin/cat.c' at line 151 (inside cook_args() function) and at line 243 (inside raw_args() function) strcmp() function was used to check whether the command line argument has a "-". However, as we're comparing only a single character, we can just directly compare using the passed array of arguments, (i.e. **argv == '-').


In that same file, at line 299, bsize is set to sbuf.st_blksize which returns a long. Explicitly casting it to size_t can mitigate the implicit conversation warning.
>How-To-Repeat:
N/A
>Fix:
Here's the patch.

--- cat.c.~1.58.~	2023-05-19 01:28:54.000000000 -0400
+++ cat.c	2023-11-05 04:06:31.569572615 -0500
@@ -148,7 +148,7 @@
 	filename = "stdin";
 	do {
 		if (*argv) {
-			if (!strcmp(*argv, "-"))
+			if (**argv == '-')
 				fp = stdin;
 			else if ((fp = fopen(*argv,
 			    fflag ? "rf" : "r")) == NULL) {
@@ -240,7 +240,7 @@
 	filename = "stdin";
 	do {
 		if (*argv) {
-			if (!strcmp(*argv, "-")) {
+			if (**argv == '-') {
 				fd = fileno(stdin);
 				if (fd < 0)
 					goto skip;
@@ -296,7 +296,7 @@
 		if (bsize == 0) {
 			if (fstat(wfd, &sbuf) == 0 && sbuf.st_blksize > 0 &&
 			    (size_t)sbuf.st_blksize > sizeof(fb_buf))
-				bsize = sbuf.st_blksize;
+				bsize = (size_t)sbuf.st_blksize;
 		}
 		if (bsize > sizeof(fb_buf)) {
 			buf = malloc(bsize);

----- end of the patch ----- (don't include this line).
CVS is quite different than git so I just used plain diff -uN. If the patch fails to apply (likely), please edit the file manually.

Thank you.



Home | Main Index | Thread Index | Old Index