| 1886 | | } else if (label[0] == '\0' || (strncasecmp(label, "", strlen("com.apple.launchd")) == 0) || |
| 1887 | | (strtol(label, NULL, 10) != 0)) { |
| 1888 | | jobmgr_log(jm, LOG_ERR, "Somebody attempted to use a reserved prefix for a label: %s", label); |
| 1889 | | /* the empty string, com.apple.launchd and number prefixes for labels are reserved */ |
| | 1887 | } else if (!jobmgr_label_test(jm, label)) { |
| | 1897 | } |
| | 1898 | |
| | 1899 | bool |
| | 1900 | jobmgr_label_test(jobmgr_t jm, const char *str) |
| | 1901 | { |
| | 1902 | char *endstr = NULL; |
| | 1903 | const char *ptr; |
| | 1904 | |
| | 1905 | if (str[0] == '\0') { |
| | 1906 | jobmgr_log(jm, LOG_ERR, "Empty job labels are not allowed"); |
| | 1907 | return false; |
| | 1908 | } |
| | 1909 | |
| | 1910 | for (ptr = str; *ptr; ptr++) { |
| | 1911 | if (iscntrl(*ptr)) { |
| | 1912 | jobmgr_log(jm, LOG_ERR, "ASCII control characters are not allowed in job labels. Index: %td Value: 0x%hhx", ptr - str, *ptr); |
| | 1913 | return false; |
| | 1914 | } |
| | 1915 | } |
| | 1916 | |
| | 1917 | strtoll(str, &endstr, 0); |
| | 1918 | |
| | 1919 | if (str != endstr) { |
| | 1920 | jobmgr_log(jm, LOG_ERR, "Job labels are not allowed to begin with numbers: %s", str); |
| | 1921 | return false; |
| | 1922 | } |
| | 1923 | |
| | 1924 | if ((strncasecmp(str, "com.apple.launchd", strlen("com.apple.launchd")) == 0) || |
| | 1925 | (strncasecmp(str, "com.apple.launchctl", strlen("com.apple.launchctl")) == 0)) { |
| | 1926 | jobmgr_log(jm, LOG_ERR, "Job labels are not allowed to use a reserved prefix: %s", str); |
| | 1927 | return false; |
| | 1928 | } |
| | 1929 | |
| | 1930 | return true; |