MudOS 代码安全性和性能分析:潜在 Bug 检测
// object.c
varargs int getoid(object ob) { int id;
if (!ob) ob = previous_object();
sscanf(file_name(ob), "%*s#%d", id);
return id;
}
// Get the owner of a file. Used by log_error() in master.c. string file_owner(string file) { string name, rest, dir;
if (file[0] != '/')
{
file = '/' + file;
}
if (sscanf(file, "/u/%s/%s/%s", dir, name, rest) == 3)
{
return name;
}
return 0;
}
// domain_file should return the domain associated with a given file. string domain_file(string file) { string domain;
if (sscanf(file, "/d/%s/%*s", domain))
return domain;
return ROOT_UID;
}
// creator_file should return the name of the creator of a specific file. string creator_file(string file) { string *path;
path = explode(file, '/') - ({ 0 });
switch (path[0])
{
case 'adm':
if (file == SIMUL_EFUN_OB) return 'MudOS';
else return ROOT_UID;
case 'cmds':
case 'shadow':
return ROOT_UID;
case 'u':
if (sizeof(path) >= 3) return path[1];
case 'd':
return 'Domain';
case 'clone':
return 'Clone';
case 'feature':
return 'Feature';
case 'kungfu':
return 'Kungfu';
case 'inherit':
return 'Inherit';
default:
return 'Unknown';
}
}
// author_file should return the name of the author of a specific file. string author_file(string file) { string name;
if (sscanf(file, "/u/%*s/%s/%*s", name))
return name;
return ROOT_UID;
}
// check the object's euid wehter is root int is_root(mixed ob) { if (stringp(ob)) return (SECURITY_D->get_status(ob) == '(admin)');
if (objectp(ob))
{
if (geteuid(ob) == ROOT_UID)
// Root object want to execute
return 1;
return (SECURITY_D->get_status(geteuid(ob)) == '(admin)');
}
return 1;
}
void destruct(object ob) { if (ob) { if (previous_object()) ob->remove(geteuid(previous_object())); else ob->remove(0); } if(environment(ob)) tell_room(environment(ob),'$jobout'+'look '+file_name(ob)+' '); efun::destruct(ob); }
object present( mixed str, object ob ) { object obj;
if(!ob&&previous_object())
{
ob = environment(previous_object());
}
if(stringp(str)&&(obj=find_object(str)))
{
if(ob) return efun::present(obj,ob);
else return efun::present(obj);
}
if(ob) return efun::present(str,ob);
else return efun::present(str);
}
潜在的 Bug 分析:
-
file_owner()函数: 该函数返回 0 作为失败情况,但同时也可能返回 0 作为文件所有者的合法名称。建议使用一个专门的错误代码,例如 -1,来表示失败情况,避免与合法所有者名称冲突。 -
creator_file()函数: 函数中的 default 分支拼写错误,应该是 'Unknown' 而不是 'Unknow'。 -
destruct()函数:ZJOBOUT应该是$jobout,可能是笔误。建议仔细检查代码中的变量名和常量名,确保拼写正确。 -
present()函数:find_object()调用存在潜在的安全和性能问题。- 安全性: 如果调用方没有足够的权限,
find_object()可能返回其他对象的引用,导致安全漏洞。 - 性能:
find_object()会进行全局搜索,效率较低。
建议使用
objectp()来验证输入字符串是否是有效的对象名,例如:if (stringp(str) && objectp(find_object(str))) { // ... }如果需要获取当前环境中的对象,可以使用
environment()函数。例如:
if (objectp(ob = environment(previous_object()))) { // ... } - 安全性: 如果调用方没有足够的权限,
原文地址: https://www.cveoy.top/t/topic/m5vS 著作权归作者所有。请勿转载和采集!