#32 Explicitly check the return value of getgrgid_r/getgrnam_r
Opened a year ago by jhrozek. Modified a year ago
jhrozek/libuser getgr_retval_check  into  master

file modified
+3 -2

@@ -672,6 +672,7 @@ 

  			char buf[LINE_MAX * 4];

  			intmax_t val;

  			char *p;

+ 			int rv;

  

  			errno = 0;

  			val = strtoimax(value, &p, 10);

@@ -679,8 +680,8 @@ 

  			    || (gid_t)val != val) {

  				struct group grp, *g;

  

- 				getgrnam_r(value, &grp, buf, sizeof(buf), &g);

- 				if (g != NULL)

+ 				rv = getgrnam_r(value, &grp, buf, sizeof(buf), &g);

+ 				if (rv == 0 && g != NULL)

  					value = g->gr_name;

  				/* else ignore the entry */

  			}

file modified
+3 -2

@@ -2060,13 +2060,14 @@ 

  		struct lu_error *error = NULL;

  		do {

  			struct group grp, *err;

+ 			int rv;

  

  			/* There may be read-only sources of user information

  			 * on the system, and we want to avoid allocating an ID

  			 * that's already in use by a service we can't write

  			 * to, so check with NSS first. */

- 			getgrgid_r(id, &grp, buf, sizeof(buf), &err);

- 			if (err == &grp) {

+ 			rv = getgrgid_r(id, &grp, buf, sizeof(buf), &err);

+ 			if (rv == 0 && err == &grp) {

  				id++;

  				continue;

  			}

Merges:
https://pagure.io/libuser/issue/21

An explicit return value check makes the job of static code analyzers
easier.

Metadata