MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_fullpath

Function plugin_fullpath

lightningd/plugin.c:1857–1894  ·  view source on GitHub ↗

If this is a valid plugin return full path name, otherwise NULL */

Source from the content-addressed store, hash-verified

1855
1856/* If this is a valid plugin return full path name, otherwise NULL */
1857static const char *plugin_fullpath(const tal_t *ctx, const char *dir,
1858 const char *basename)
1859{
1860 struct stat st;
1861 const char *fullname;
1862 struct utf8_state utf8 = UTF8_STATE_INIT;
1863
1864 for (size_t i = 0; basename[i]; i++) {
1865 if (!utf8_decode(&utf8, basename[i]))
1866 continue;
1867 /* Not valid UTF8? Let's not go there... */
1868 if (errno != 0)
1869 return NULL;
1870 if (utf8.used_len != 1)
1871 continue;
1872 if (!cispunct(utf8.c))
1873 continue;
1874 if (utf8.c != '-' && utf8.c != '_' && utf8.c != '.')
1875 return NULL;
1876 }
1877
1878 fullname = path_join(ctx, dir, basename);
1879 if (stat(fullname, &st) != 0)
1880 return tal_free(fullname);
1881 /* Only regular files please (or symlinks to such: stat not lstat!) */
1882 if ((st.st_mode & S_IFMT) != S_IFREG)
1883 return tal_free(fullname);
1884 /* Must be executable by someone. */
1885 if (!(st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
1886 return tal_free(fullname);
1887
1888 /* Someone actually runs this on NTFS, where everything apparently is
1889 * executable! This prevents the most obvious damage. */
1890 if (streq(basename, "README.md"))
1891 return tal_free(fullname);
1892
1893 return fullname;
1894}
1895
1896char *add_plugin_dir(struct plugins *plugins, const char *dir, bool error_ok)
1897{

Callers 1

add_plugin_dirFunction · 0.85

Calls 5

utf8_decodeFunction · 0.85
cispunctFunction · 0.85
path_joinFunction · 0.85
tal_freeFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected