[Crash-utility] [PATCH 2/2] Fix build if userid does not exist in user database

Dave Anderson anderson at redhat.com
Mon Jun 26 18:43:14 UTC 2017



----- Original Message -----
> make_build_data uses the output of the id command in order to generate the
> string in build_data.c indicating who built the program. Unfortunately, the
> previous parsing code looked for the presence of a ")" in order to determine
> where the user field ended. If the user is not found in the user database,
> the output looks more like:
> uid=59784003 gid=60243 groups=60243

For the changelog, what does "help -B" show in that case?  Or does the
build fail?

> 
> Instead, now it just calls the glibc helpers and formats the line based
> upon those instead of shelling out and trying to parse the output of id.
> If it cannot retrieve the username, it just sets the UID.

Ok, that's fine.

I also seem to recall that coverity scans (or perhaps distro-specific
compiler flags?) complain about not assigning/looking-at the return
value fgets().  The old code assigned it to "p" (and ignored it), so
the fgets() should probably still be assigned to something -- maybe by
re-introducing "char *p" with an "__attribute__ ((__unused__))".

Dave


> 
> Signed-off-by: Sargun Dhillon <sargun at sargun.me>
> ---
>  configure.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/configure.c b/configure.c
> index 10bc6e1..8ddec66 100644
> --- a/configure.c
> +++ b/configure.c
> @@ -56,6 +56,7 @@
>  #include <sys/stat.h>
>  #include <unistd.h>
>  #include <ctype.h>
> +#include <pwd.h>
>  
>  struct supported_gdb_version;
>  void build_configure(struct supported_gdb_version *);
> @@ -1252,7 +1253,7 @@ count_chars(char *s, char c)
>  void
>  make_build_data(char *target)
>  {
> -	char *p;
> +	struct passwd *passwd;
>  	char hostname[MAXSTRLEN];
>  	char progname[MAXSTRLEN];
>  	char datebuf[MAXSTRLEN];
> @@ -1274,14 +1275,15 @@ make_build_data(char *target)
>  	if (gethostname(hostname, MAXSTRLEN) != 0)
>  		hostname[0] = '\0';
>  
> -	p = fgets(datebuf, 79, fp_date);
> +	fgets(datebuf, 79, fp_date);
>  
> -	p = fgets(idbuf, 79, fp_id);
> -	p = strstr(idbuf, ")");
> -	p++;
> -	*p = '\0';
> +	passwd = getpwuid(getuid());
> +	if (passwd)
> +		sprintf(idbuf, "uid=%d(%s)", passwd->pw_uid, passwd->pw_name);
> +	else
> +		sprintf(idbuf, "uid=%d", getuid());
>  
> -	p = fgets(gccversionbuf, 79, fp_gcc);
> +	fgets(gccversionbuf, 79, fp_gcc);
>  
>  	lower_case(target_data.program, progname);
>  
> --
> 2.9.3
> 
> --
> Crash-utility mailing list
> Crash-utility at redhat.com
> https://www.redhat.com/mailman/listinfo/crash-utility
> 




More information about the Crash-utility mailing list