From cdf1abf190f1097c4f6ae2ff0a9fa023df6982f1 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 12 Oct 2019 22:41:01 -0400 Subject: Applied debian patch to fix compiler warnings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0014-fix-implicit-declarations-incompatible-types-argv-ty.patch From: Jan Date: Sat, 2 Mar 2019 15:41:59 +0100 Subject: fix: implicit declarations, incompatible types, argv type MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Fixed a few compiler warnings: prot.c:13:7: warning: implicit declaration of function ‘setgroups’ [-Wimplicit-function-declaration] chpst.c:80:7: warning: implicit declaration of function ‘setgroups’; did you mean ‘getgroups’? [-Wimplicit-function-declaration] - added #include , see: https://linux.die.net/man/2/setgroups chkshsgr.c:11:19: warning: passing argument 2 of ‘getgroups’ from incompatible pointer type [-Wincompatible-pointer-types] - change 'short' to 'gid_t', see: https://linux.die.net/man/2/setgroups pathexec_run.c:18:5: warning: implicit declaration of function ‘execve’ [-Wimplicit-function-declaration] - add #include , see: http://man7.org/linux/man-pages/man2/execve.2.html prot.c:17:10: warning: implicit declaration of function ‘setgid’; did you mean ‘getgrgid’? [-Wimplicit-function-declaration] - add #include , see: https://linux.die.net/man/3/setgid seek_set.c:9:7: warning: implicit declaration of function ‘lseek’ [-Wimplicit-function-declaration] - add #include , see: https://linux.die.net/man/2/lseek -------------------------------------- Fixed type of argv, from 'const char **argv' to 'char **argv' This resolves a lot of compiler typecast warnings like: pathexec_run.c:19:17: warning: passing argument 2 of ‘execve’ from incompatible pointer type [-Wincompatible-pointer-types] NOTE: this change might be disputable and not obvious at first. For arguments for argv as 'char **argv', see: The C Programming Language, Kernighan & Ritchie, Second Edition, Section 5.10, page 110 Command-line Arguments: main(int argc, char *argv[]) From https://riptutorial.com/c/example/3675/original--hello--world---in-k-r-c int main(int argc, char **argv) From C/C++ Kompendium (DE), Markt+Technik Verlag 2000, page 576, Chapter 12, main() Parameter: int main(int argc, char *argv[]) From http://www.cplusplus.com/articles/DEN36Up4/ int main(int argc, char* argv[]) // or char** argv From https://ece.uwaterloo.ca/~dwharder/icsrts/C/05/ int main( int argc, char *argv[] ) At https://stackoverflow.com/questions/5808679/why-is-main-argument-argv-of-type-char-rather-than-const-char is argued, that: - argv isn't const, since it's being created at runtime - in certain cases you should be able to rewrite argv from you program The main argument for this type change: the argv is used in a call to execve, so the type should be declared as compatible with execve parameters. http://man7.org/linux/man-pages/man2/execve.2.html defines: int execve(const char *filename, char *const argv[], char *const envp[]); so every argv defined as 'const char *const argv[]' was changed to: 'char *const argv[]' --- chpst.c | 31 ++++++++++++++++--------------- pathexec.h | 6 +++--- pathexec_env.c | 8 ++++---- pathexec_run.c | 3 ++- prot.c | 7 +++++-- prot.h | 2 +- sgetopt.c | 2 +- sgetopt.h | 2 +- subgetopt.c | 2 +- subgetopt.h | 2 +- 10 files changed, 35 insertions(+), 30 deletions(-) diff --git a/chpst.c b/chpst.c index f1b8ed9..2b9eb01 100644 --- a/chpst.c +++ b/chpst.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "sgetopt.h" #include "error.h" #include "strerr.h" @@ -40,7 +41,7 @@ void usage() { strerr_die4x(100, "usage: ", progname, USAGE_MAIN, "\n"); } char *set_user =0; char *env_user =0; -const char *argv0 =0; +char *argv0 =0; const char *env_dir =0; unsigned int verbose =0; unsigned int pgrp =0; @@ -258,14 +259,14 @@ void slimit() { } /* argv[0] */ -void setuidgid(int, const char *const *); -void envuidgid(int, const char *const *); -void envdir(int, const char *const *); -void pgrphack(int, const char *const *); -void setlock(int, const char *const *); -void softlimit(int, const char *const *); - -int main(int argc, const char **argv) { +void setuidgid(int, char *const *); +void envuidgid(int, char *const *); +void envdir(int, char *const *); +void pgrphack(int, char *const *); +void setlock(int, char *const *); +void softlimit(int, char *const *); + +int main(int argc, char **argv) { int opt; int i; unsigned long ul; @@ -366,7 +367,7 @@ int main(int argc, const char **argv) { void setuidgid_usage() { strerr_die4x(100, "usage: ", progname, USAGE_SETUIDGID, "\n"); } -void setuidgid(int argc, const char *const *argv) { +void setuidgid(int argc, char *const *argv) { const char *account; if (! (account =*++argv)) setuidgid_usage(); @@ -379,7 +380,7 @@ void setuidgid(int argc, const char *const *argv) { void envuidgid_usage() { strerr_die4x(100, "usage: ", progname, USAGE_ENVUIDGID, "\n"); } -void envuidgid(int argc, const char *const *argv) { +void envuidgid(int argc, char *const *argv) { const char *account; if (! (account =*++argv)) envuidgid_usage(); @@ -392,7 +393,7 @@ void envuidgid(int argc, const char *const *argv) { void envdir_usage() { strerr_die4x(100, "usage: ", progname, USAGE_ENVDIR, "\n"); } -void envdir(int argc, const char *const *argv) { +void envdir(int argc, char *const *argv) { const char *dir; if (! (dir =*++argv)) envdir_usage(); @@ -405,7 +406,7 @@ void envdir(int argc, const char *const *argv) { void pgrphack_usage() { strerr_die4x(100, "usage: ", progname, USAGE_PGRPHACK, "\n"); } -void pgrphack(int argc, const char *const *argv) { +void pgrphack(int argc, char *const *argv) { if (! *++argv) pgrphack_usage(); setsid(); pathexec(argv); @@ -415,7 +416,7 @@ void pgrphack(int argc, const char *const *argv) { void setlock_usage() { strerr_die4x(100, "usage: ", progname, USAGE_SETLOCK, "\n"); } -void setlock(int argc, const char *const *argv) { +void setlock(int argc, char *const *argv) { int opt; unsigned int delay =0; unsigned int x =0; @@ -449,7 +450,7 @@ void getlarg(long *l) { if (optarg[scan_ulong(optarg, &ul)]) usage(); *l =ul; } -void softlimit(int argc, const char *const *argv) { +void softlimit(int argc, char *const *argv) { int opt; while ((opt =getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) diff --git a/pathexec.h b/pathexec.h index d46ab17..8d850e7 100644 --- a/pathexec.h +++ b/pathexec.h @@ -3,9 +3,9 @@ #ifndef PATHEXEC_H #define PATHEXEC_H -extern void pathexec_run(const char *,const char * const *,const char * const *); +extern void pathexec_run(const char *, char *const *, char *const *); extern int pathexec_env(const char *,const char *); -extern void pathexec_env_run(const char *, const char * const *); -extern void pathexec(const char * const *); +extern void pathexec_env_run(const char *, char *const *); +extern void pathexec(char * const *); #endif diff --git a/pathexec_env.c b/pathexec_env.c index 1305469..f873094 100644 --- a/pathexec_env.c +++ b/pathexec_env.c @@ -22,9 +22,9 @@ int pathexec_env(const char *s,const char *t) return stralloc_cat(&plus,&tmp); } -void pathexec_env_run(const char *file, const char *const *argv) +void pathexec_env_run(const char *file, char *const *argv) { - const char **e; + char **e; unsigned int elen; unsigned int i; unsigned int j; @@ -40,7 +40,7 @@ void pathexec_env_run(const char *file, const char *const *argv) if (!plus.s[i]) ++elen; - e = (const char **) alloc((elen + 1) * sizeof(char *)); + e = (char **) alloc((elen + 1) * sizeof(char *)); if (!e) return; elen = 0; @@ -68,7 +68,7 @@ void pathexec_env_run(const char *file, const char *const *argv) alloc_free(e); } -void pathexec(const char *const *argv) +void pathexec(char *const *argv) { return pathexec_env_run(*argv, argv); } diff --git a/pathexec_run.c b/pathexec_run.c index 1770ac7..51f13ea 100644 --- a/pathexec_run.c +++ b/pathexec_run.c @@ -1,5 +1,6 @@ /* Public domain. */ +#include #include "error.h" #include "stralloc.h" #include "str.h" @@ -8,7 +9,7 @@ static stralloc tmp; -void pathexec_run(const char *file,const char * const *argv,const char * const *envp) +void pathexec_run(const char *file, char *const *argv, char *const *envp) { const char *path; unsigned int split; diff --git a/prot.c b/prot.c index 79a88c5..1ffd20c 100644 --- a/prot.c +++ b/prot.c @@ -1,12 +1,15 @@ /* Public domain. */ +#include +#include +#include #include "hasshsgr.h" #include "prot.h" -int prot_gid(int gid) +int prot_gid(gid_t gid) { #ifdef HASSHORTSETGROUPS - short x[2]; + gid_t x[2]; x[0] = gid; x[1] = 73; /* catch errors */ if (setgroups(1,x) == -1) return -1; #else diff --git a/prot.h b/prot.h index 2e5cb81..47a4204 100644 --- a/prot.h +++ b/prot.h @@ -3,7 +3,7 @@ #ifndef PROT_H #define PROT_H -extern int prot_gid(int); +extern int prot_gid(gid_t); extern int prot_uid(int); #endif diff --git a/sgetopt.c b/sgetopt.c index 8bb608f..778bca2 100644 --- a/sgetopt.c +++ b/sgetopt.c @@ -27,7 +27,7 @@ Documentation in sgetopt.3. int opterr = 1; const char *optprogname = 0; -int getopt(int argc,const char *const *argv,const char *opts) +int getopt(int argc,char *const *argv,const char *opts) { int c; const char *s; diff --git a/sgetopt.h b/sgetopt.h index bf8bce6..eb4cbf8 100644 --- a/sgetopt.h +++ b/sgetopt.h @@ -16,7 +16,7 @@ #include "subgetopt.h" -extern int sgetoptmine(int,const char *const *,const char *); +extern int sgetoptmine(int,char *const *,const char *); extern int sgetopterr; extern const char *sgetoptprogname; diff --git a/subgetopt.c b/subgetopt.c index 85ace96..a23e0d7 100644 --- a/subgetopt.c +++ b/subgetopt.c @@ -16,7 +16,7 @@ const char *optarg = 0; int optproblem = 0; int optdone = SUBGETOPTDONE; -int sgopt(int argc,const char *const *argv,const char *opts) +int sgopt(int argc,char *const *argv,const char *opts) { int c; const char *s; diff --git a/subgetopt.h b/subgetopt.h index 41ad26a..5163148 100644 --- a/subgetopt.h +++ b/subgetopt.h @@ -15,7 +15,7 @@ #define SUBGETOPTDONE -1 -extern int subgetopt(int,const char *const *,const char *); +extern int subgetopt(int,char *const *,const char *); extern const char *subgetoptarg; extern int subgetoptind; extern int subgetoptpos; -- cgit v1.2.3