Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 381783 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/rc/mountinfo.c (-2 / +52 lines)
Lines 326-339 Link Here
326
#  error "Operating system not supported!"
326
#  error "Operating system not supported!"
327
#endif
327
#endif
328
328
329
/*
330
 * Done to fix bug #381783 in Gentoo Bugzilla, by i.Dark_Templar
331
 * This function resolves symlinks in paths inside regexp
332
 * Returns new string (should be freed later by free()) or NULL on errors
333
 * Paramaters:
334
 * 1. char *string - starting regexp
335
 * 2. const char *delimiter - used delimiter (i've seen '|' used in OpenRC scripts)
336
 */
337
338
char* regexp_resolve_symlinks(char* string, const char* delimiter) {
339
	char *oldstr, *newstr = NULL, *tmp, *token, *saveptr;
340
	char real_path[PATH_MAX + 1];
341
	
342
	oldstr = strdup(string);
343
	if (!oldstr) return NULL; /* not enough memory? abort */
344
345
	for (token = strtok_r(oldstr, delimiter, &saveptr); token != NULL; token = strtok_r(NULL, delimiter, &saveptr)) {
346
347
		if (realpath(token, real_path) != NULL) {
348
			token = real_path; /* could resolve path, add resolved to new string, otherwise use unresolved, probably it should be so */
349
		}
350
351
		tmp = realloc(newstr, ((newstr) ? (strlen(newstr) + strlen(delimiter)) : (0)) + strlen(token) + 1);
352
		if (!tmp) { /* not enough memory? abort */
353
			free(oldstr);
354
			if (newstr) free(newstr);
355
			return NULL;
356
		}
357
358
		if (newstr) strcat(tmp, delimiter); /* not first item, add delimiter */
359
		newstr = tmp;
360
		strcat(newstr, token);
361
	}
362
363
	free(oldstr);
364
365
	return newstr;
366
}
367
329
static regex_t *
368
static regex_t *
330
get_regex(const char *string)
369
get_regex(const char *string)
331
{
370
{
332
	regex_t *reg = xmalloc(sizeof (*reg));
371
	regex_t *reg = xmalloc(sizeof (*reg));
333
	int result;
372
	int result;
334
	char buffer[256];
373
	char buffer[256];
335
374
	char *resolved_regexp;
336
	if ((result = regcomp(reg, string, REG_EXTENDED | REG_NOSUB)) != 0)
375
	
376
	if ((resolved_regexp = regexp_resolve_symlinks(string, "|")) == NULL)
377
	{
378
		eerrorx("%s: couldn't resolve regexp", applet); /* I don't mind changing it for something more informative error */
379
		
380
		result = regcomp(reg, string, REG_EXTENDED | REG_NOSUB); /* Fallback to starting string */
381
	} else {
382
		result = regcomp(reg, resolved_regexp, REG_EXTENDED | REG_NOSUB);
383
		free(resolved_regexp);
384
	}
385
	
386
	if (result != 0)
337
	{
387
	{
338
		regerror(result, reg, buffer, sizeof(buffer));
388
		regerror(result, reg, buffer, sizeof(buffer));
339
		eerrorx("%s: invalid regex `%s'", applet, buffer);
389
		eerrorx("%s: invalid regex `%s'", applet, buffer);

Return to bug 381783