MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / is_secure_file_path

Function is_secure_file_path

sql/mysqld.cc:2209–2261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2207*/
2208
2209bool is_secure_file_path(char *path)
2210{
2211 char buff1[FN_REFLEN], buff2[FN_REFLEN];
2212 size_t opt_secure_file_priv_len;
2213
2214 /*
2215 --secure-file-priv without argument means
2216 disable SELECT INTO OUTFILE/LOAD DATA INFILE
2217 */
2218 if (opt_secure_file_priv_noarg)
2219 return FALSE;
2220
2221 /*
2222 All paths are secure if opt_secure_file_path is 0
2223 */
2224 if (!opt_secure_file_priv)
2225 return TRUE;
2226
2227 opt_secure_file_priv_len= strlen(opt_secure_file_priv);
2228
2229 if (strlen(path) >= FN_REFLEN)
2230 return FALSE;
2231
2232 if (my_realpath(buff1, path, 0))
2233 {
2234 /*
2235 The supplied file path might have been a file and not a directory.
2236 */
2237 int length= (int)dirname_length(path);
2238 if (length >= FN_REFLEN)
2239 return FALSE;
2240 memcpy(buff2, path, length);
2241 buff2[length]= '\0';
2242 if (length == 0 || my_realpath(buff1, buff2, 0))
2243 return FALSE;
2244 }
2245 convert_dirname(buff2, buff1, NullS);
2246 if (!lower_case_file_system)
2247 {
2248 if (strncmp(opt_secure_file_priv, buff2, opt_secure_file_priv_len))
2249 return FALSE;
2250 }
2251 else
2252 {
2253 if (files_charset_info->coll->strnncoll(files_charset_info,
2254 (uchar *) buff2, strlen(buff2),
2255 (uchar *) opt_secure_file_priv,
2256 opt_secure_file_priv_len,
2257 TRUE))
2258 return FALSE;
2259 }
2260 return TRUE;
2261}
2262
2263
2264static int fix_paths(void)

Callers 1

val_strMethod · 0.85

Calls 3

my_realpathFunction · 0.85
dirname_lengthFunction · 0.85
convert_dirnameFunction · 0.85

Tested by

no test coverage detected