| 1959 | | } else if (unlikely(label[0] == '\0' || (strncasecmp(label, "", strlen("com.apple.launchd")) == 0) || |
| 1960 | | (strtol(label, NULL, 10) != 0))) { |
| 1961 | | jobmgr_log(jm, LOG_ERR, "Somebody attempted to use a reserved prefix for a label: %s", label); |
| 1962 | | /* the empty string, com.apple.launchd and number prefixes for labels are reserved */ |
| | 1960 | } else if (unlikely(!jobmgr_label_test(jm, label))) { |
| | 1970 | } |
| | 1971 | |
| | 1972 | bool |
| | 1973 | jobmgr_label_test(jobmgr_t jm, const char *str) |
| | 1974 | { |
| | 1975 | char *endstr = NULL; |
| | 1976 | const char *ptr; |
| | 1977 | |
| | 1978 | if (str[0] == '\0') { |
| | 1979 | jobmgr_log(jm, LOG_ERR, "Empty job labels are not allowed"); |
| | 1980 | return false; |
| | 1981 | } |
| | 1982 | |
| | 1983 | for (ptr = str; *ptr; ptr++) { |
| | 1984 | if (iscntrl(*ptr)) { |
| | 1985 | jobmgr_log(jm, LOG_ERR, "ASCII control characters are not allowed in job labels. Index: %td Value: 0x%hhx", ptr - str, *ptr); |
| | 1986 | return false; |
| | 1987 | } |
| | 1988 | } |
| | 1989 | |
| | 1990 | strtoll(str, &endstr, 0); |
| | 1991 | |
| | 1992 | if (str != endstr) { |
| | 1993 | jobmgr_log(jm, LOG_ERR, "Job labels are not allowed to begin with numbers: %s", str); |
| | 1994 | return false; |
| | 1995 | } |
| | 1996 | |
| | 1997 | if ((strncasecmp(str, "com.apple.launchd", strlen("com.apple.launchd")) == 0) || |
| | 1998 | (strncasecmp(str, "com.apple.launchctl", strlen("com.apple.launchctl")) == 0)) { |
| | 1999 | jobmgr_log(jm, LOG_ERR, "Job labels are not allowed to use a reserved prefix: %s", str); |
| | 2000 | return false; |
| | 2001 | } |
| | 2002 | |
| | 2003 | return true; |