shadow-maint/shadow

Loopity loop

alejandro-colomar opened this issue · 1 comments

I was joking the other day that I would like to see someone write a continue; within a do {...} while (0);, just for fun. I'd be 50/50 between burning the computer of the offender and ROFL. Example:

#define loopity_loop()  do { for (;;) { break; } continue; } while (0-0)

Well, unless I'm missing something, as often, reality surpasses my dreams. Look at what I just found:

		for (token = strtok_r(p, " \n\t", &saveptr);
		     token;
		     token = strtok_r(NULL, " \n\t", &saveptr)) {
			char libname[65];
			void *h;
			if (strcmp(token, "files") == 0) {
				subid_nss = NULL;
				goto done;
			}
			if (strlen(token) > 50) {
				fprintf(shadow_logfd, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
				fprintf(shadow_logfd, "Using files\n");
				subid_nss = NULL;
				goto done;
			}
			snprintf(libname, 64,  "libsubid_%s.so", token);
			h = dlopen(libname, RTLD_LAZY);
			if (!h) {
				fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
				fprintf(shadow_logfd, "Using files\n");
				subid_nss = NULL;
				goto done;
			}
			subid_nss = MALLOC(1, struct subid_nss_ops);
			if (!subid_nss) {
				dlclose(h);
				goto done;
			}
			subid_nss->has_range = dlsym(h, "shadow_subid_has_range");
			if (!subid_nss->has_range) {
				fprintf(shadow_logfd, "%s did not provide @has_range@\n", libname);
				dlclose(h);
				free(subid_nss);
				subid_nss = NULL;
				goto done;
			}
			subid_nss->list_owner_ranges = dlsym(h, "shadow_subid_list_owner_ranges");
			if (!subid_nss->list_owner_ranges) {
				fprintf(shadow_logfd, "%s did not provide @list_owner_ranges@\n", libname);
				dlclose(h);
				free(subid_nss);
				subid_nss = NULL;
				goto done;
			}
			subid_nss->find_subid_owners = dlsym(h, "shadow_subid_find_subid_owners");
			if (!subid_nss->find_subid_owners) {
				fprintf(shadow_logfd, "%s did not provide @find_subid_owners@\n", libname);
				dlclose(h);
				free(subid_nss);
				subid_nss = NULL;
				goto done;
			}
			subid_nss->handle = h;
			goto done;
		}

If that's a loop, I'm Bugs Bunny. The done label is of course after the (shall I really call it loop?) loop.

I'll prepare a PR...

hallyn commented

Well, on the topic of loops, at https://github.com/shadow-maint/shadow/pull/733/files#diff-31aa13e6c93f9d326376aaccba38a7d07039da0cb207b758db141fb23ea14072R625
I had suggested

struct passwd *pw = NULL;

	while (pw == NULL)
		pw = do_check_perms();
	return pw;

But of course that really should have been

    struct passwd *pw;
    do {
        pw = do_check_perms();
    } while (pw == NULL);