介绍
想明白生命的意义吗?想真正的…活着吗?
Hi 程序员,当你收到这条消息,是否做好准备,开启一场未知的探险?
参赛地址:https://code83.ide.aliyun.com/
以下是答题界面,在线VSCode
安全题
1、以下哪种是sql注入攻击(不定项,3个正确答案) ( A B C ) \color{red}(ABC) (ABC)
A.content=1 union select 1
B.name=updatexml(1,user(),1)
C.id=i and 1 like 1
D.id=<script src="//bxssme.cn">
答案:A B C
2、以下哪种是xss攻击(不定项,3个正确答案) ( A B C ) \color{red}(ABC) (ABC)
A.id=confirm(1)
B.id=<img src=1 onerror=1>
C.id=<script>edoejx()</script>
D.content=1 and abs(2)
3、执行:ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oPort=8888,执行完之后,
任何一台机器ssh root@IP -p 8888,输入任意密码,成功登录。
问:该后门为什么能够任意密码登陆? (单选)
(
C
)
\color{red}(C)
(C)
A.sshd 不指定配置文件启动时,所有账号均可任意密码登陆
B.sshd 因为被链接到/tmp目录,由于文件权限原因,可任意密码登陆
C.sshd 因为被链接为/tmp/su,由于pam模块认证原因,可任意密码登陆
D.sshd 因为被链接到/tmp目录,由于位置发生变化导致无法找到/etc/shadow文件因此放行登陆请求
4、"\.\globalroot\device\condrv\kernelconnect 在谷歌浏览器输入以上地址并回车
可能会发生什么非预期的效果?" (单选)
(
C
)
\color{red}(C)
(C)
A.浏览器崩溃
B.成为阿里云锦鲤
C.蓝屏
D.黑屏
规约题
这些题目都是Java语言背景下的。
都是衍生自阿里巴巴开发规约,属于日常开发需要掌握。
1. filter方法意图过滤传入的订单列表中不属于当前系统时间所在日期的订单,
以下哪一行代码存在错误?(单选)
(
A
)
\color{red}(A)
(A)
A. 7行
B. 8行
C. 10行
D. 13行
public static void filter(ArrayList<Order> orders) {
if (orders == null) {
return;
}
SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd");
String currentDay = formatter.format(new Date());
Iterator<Order> iterator = orders.iterator();
while (iterator.hasNext()) {
Order order = iterator.next();
if (!currentDay.equals(order.getTransactionDay())) {
iterator.remove();
}
}
}
答案:
A,应为:yyyy-MM-dd
解析:
A,对应阿里巴巴开发规约 日期处理1,这里使用错误
B,对应阿里巴巴开发规约,并发处理5,这里使用,线程安全
D,对应阿里巴巴开发规约,集合处理14,这里使用正确
2. 以下哪种字符串拼接方式,是效率最高、并符合Alibaba Java Coding Guidelines规范的?(单选) ( A ) \color{red}(A) (A)
A.
public static String concat(List<String> strings) {
if (strings == null || strings.isEmpty()) {
return "";
}
StringBuilder builder = new StringBuilder();
for (String string : strings) {
builder.append(string);
}
return builder.toString();
}
B.
public static String concat(List<String> strings) {
if (strings == null || strings.isEmpty()) {
return "";
}
StringBuffer buffer = new StringBuffer();
for (String string : strings) {
builder.append(string);
}
return buffer.toString();
}
C.
public static String concat(List<String> strings) {
if (strings == null || strings.isEmpty()) {
return "";
}
String result = strings.get(0);
for (int i = 1; i < strings.length(); i++) {
result = result + strings.get(i);
}
return result;
}
D.
public static String concat(List<String> strings) {
if (strings == null || strings.isEmpty()) {
return "";
}
return strings.stream().reduce((x, y) -> x + y).get();
}
答案:A
B使用的StringBuffer为线程安全类,这里没有必要,synchronized代码块增加了时间开销;
C会不断创建String对象,造成内存资源浪费;
D和C同理,reduce的过程中不断创建String对象
解析:
对应《阿里巴巴开发规约》,OOP规约24,并发处理7
3. 以下哪段代码,调用getHelper的过程,不是线程安全的(单选) ( B ) \color{red}(B) (B)
A.
public class LazyInitDemo {
private Helper helper = null;
public static synchronized helper getHelper() {
if (helper == null) {
helper = new Helper();
}
return helper;
}
}
B.
public class LazyInitDemo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null) {
synchronized (this) {
if (helper == null) {
helper = new Helper();
}
}
}
return helper;
}
}
C.
public class LazyInitDemo {
private static class HelperHolder {
private static final Helper HELPER = new Helper();
}
public static final Helper getHelper() {
return HelperHolder.HELPER;
}
}
D.
public class PreInitDemo{
private static final Helper HELPER = new Helper();
public static Helper getHelper(){
return HELPER;
}
}
答案:B
ABCD分别是单例模式的四种写法,其中B的helper域的申明遗漏了volatile关键词
解析:
对应《阿里巴巴开发规约》,并发处理16
4. 以下哪个选项的getTypeString函数,没有bug?(单选) ( B ) \color{red}(B) (B)
A.
public class Type {
public enum TypeEnum {
ZERO,
ONE
}
private TypeEnum type;
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum type) {
this.type = type;
}
public String getTypeString() {
switch (type) {
case ZERO:
return "ZERO";
case ONE:
return "ONE";
default:
return "OTHER";
}
}
}
B.
public class Type {
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTypeString() {
switch (type) {
case "0":
return "ZERO";
case "1":
return "ONE";
default:
return "OTHER";
}
}
}
C.
public class Type {
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getTypeString() {
switch (type) {
case 0:
return "ZERO";
case 1:
return "ONE";
default:
return "OTHER";
}
}
}
D.
public class Type {
private Integer type;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getTypeString() {
switch (type) {
case 0:
return "ZERO";
case 1:
return "ONE";
default:
return "OTHER";
}
}
}
答案:C
当type为null时,A/B/D均会抛NullPointerException异常。C的type不进行显式初始化的情况下,默认值为0。
解析:
对应《阿里巴巴开发规约》,控制语句2
总结
以上是本次83行代码大赛的答案和解析。题目比较基础,基本上都是出自《阿里巴巴代码规范》,可见代码规范还是很重要的。
————生命不息,BUG不断,加油代码人!