File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,23 @@ std::string PermsToSymbolicString(fs::perms p)
294
294
return perm_str;
295
295
}
296
296
297
+ static std::optional<unsigned > StringToOctal (const std::string& str)
298
+ {
299
+ unsigned ret = 0 ;
300
+ for (char c : str) {
301
+ if (c < ' 0' || c > ' 7' ) return std::nullopt;
302
+ ret = (ret << 3 ) | (c - ' 0' );
303
+ }
304
+ return ret;
305
+ }
306
+
307
+ static auto ConvertPermsToOctal (const std::string& str) noexcept -> std::optional<unsigned>
308
+ {
309
+ // Don't permit setting special bits as they're not relevant to cookie files
310
+ if (str.length () == 3 ) return StringToOctal (str);
311
+ return std::nullopt;
312
+ }
313
+
297
314
std::optional<fs::perms> InterpretPermString (const std::string& s)
298
315
{
299
316
if (s == " owner" ) {
@@ -305,6 +322,8 @@ std::optional<fs::perms> InterpretPermString(const std::string& s)
305
322
return fs::perms::owner_read | fs::perms::owner_write |
306
323
fs::perms::group_read |
307
324
fs::perms::others_read;
325
+ } else if (auto octal_perms = ConvertPermsToOctal (s)) {
326
+ return static_cast <fs::perms>(*octal_perms);
308
327
} else {
309
328
return std::nullopt;
310
329
}
You can’t perform that action at this time.
0 commit comments