char * lg_getenv(const char *name, int *lenp) { size_t len; u_int i; char *ptr; if ((ptr = getenv(name)) == NULL) return (NULL); lg_urldecode(ptr); if (!(len = strlen(ptr))) return (NULL); if (lenp != NULL) *lenp = len; #define allowed_in_string(_x) \ (isalnum((unsigned char)_x) || strchr("-_.:/= ", _x)) for (i = 0; i < len; i++) { if (ptr[i] == '&') ptr[i] = '\0'; if (!allowed_in_string(ptr[i])) { printf("invalid character in input\n"); return (NULL); } } return (ptr); #undef allowed_in_string }
int lg_checkarg(char *arg) { size_t len; u_int i; if (!(len = strlen(arg))) return (0); #define allowed_in_string(_x) \ ((isalnum((unsigned char)_x) || isprint((unsigned char)_x)) && \ (_x != '%' && _x != '\\' && _x != ';' && _x != '&' && _x != '|')) for (i = 0; i < len; i++) { if (!allowed_in_string(arg[i])) { fprintf(stderr, "invalid character in input\n"); return (EPERM); } } #undef allowed_in_string return (0); }