mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix problems found by deepscan.io
This commit is contained in:
1 parent
e8dcd97561
commit
dd4ecdb029
13 files changed
+33
-29
No files matched your search
@@ -4,6 +4,7 @@ import axios from 'axios';
|
|||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
|
import { noop } from 'lodash';
|
||||||
import * as tmpfs from '../tmpfs';
|
import * as tmpfs from '../tmpfs';
|
||||||
import log from '../log';
|
import log from '../log';
|
||||||
import { compilerText, Queue } from '../utils';
|
import { compilerText, Queue } from '../utils';
|
||||||
@@ -99,7 +100,7 @@ class JudgeTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const clean of this.clean) await clean().catch();
|
for (const clean of this.clean) await clean().catch(noop);
|
||||||
tmpfs.umount(this.tmpdir);
|
tmpfs.umount(this.tmpdir);
|
||||||
fs.removeSync(this.tmpdir);
|
fs.removeSync(this.tmpdir);
|
||||||
}
|
}
|
||||||
@@ -257,7 +258,7 @@ export default class VJ4 {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
await fs.unlink(tmpFilePath);
|
await fs.unlink(tmpFilePath);
|
||||||
await this.processData(savePath).catch();
|
await this.processData(savePath).catch(noop);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (retry) await this.problemData(domainId, pid, savePath, retry - 1);
|
if (retry) await this.problemData(domainId, pid, savePath, retry - 1);
|
||||||
else throw e;
|
else throw e;
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ function judgeCase(c) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (status === STATUS.STATUS_RUNTIME_ERROR && code) {
|
} else if (status === STATUS.STATUS_RUNTIME_ERROR && code) {
|
||||||
status = STATUS.STATUS_RUNTIME_ERROR;
|
|
||||||
if (code < 32) message = signals[code];
|
if (code < 32) message = signals[code];
|
||||||
else message = `您的程序返回了 ${code}.`;
|
else message = `您的程序返回了 ${code}.`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const statusMap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function proc({
|
function proc({
|
||||||
execute = null,
|
execute = '',
|
||||||
time_limit_ms = 16000,
|
time_limit_ms = 16000,
|
||||||
memory_limit_mb = 1024,
|
memory_limit_mb = 1024,
|
||||||
process_limit = 32,
|
process_limit = 32,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ObjectID } from 'bson';
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { homedir, tmpdir } from 'os';
|
import { homedir, tmpdir } from 'os';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
declare module 'hydrooj/dist/interface' {
|
declare module 'hydrooj/dist/interface' {
|
||||||
interface SystemKeys {
|
interface SystemKeys {
|
||||||
@@ -83,7 +84,7 @@ async function postInit() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
await fs.unlink(tmpFilePath);
|
await fs.unlink(tmpFilePath);
|
||||||
await processData(savePath).catch();
|
await processData(savePath).catch(noop);
|
||||||
return savePath;
|
return savePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ async function postInit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
for (const clean of this.clean) await clean().catch();
|
for (const clean of this.clean) await clean().catch(noop);
|
||||||
tmpfs.umount(this.tmpdir);
|
tmpfs.umount(this.tmpdir);
|
||||||
fs.removeSync(this.tmpdir);
|
fs.removeSync(this.tmpdir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import path from 'path';
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import systeminformation from 'systeminformation';
|
import systeminformation from 'systeminformation';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
|
import { noop } from 'lodash';
|
||||||
import { judge } from './judge/run';
|
import { judge } from './judge/run';
|
||||||
import * as tmpfs from './tmpfs';
|
import * as tmpfs from './tmpfs';
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ int main(){
|
|||||||
tmpfs.mount(context.tmpdir, '64m');
|
tmpfs.mount(context.tmpdir, '64m');
|
||||||
await judge(context).catch((e) => console.error(e));
|
await judge(context).catch((e) => console.error(e));
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
for (const clean of context.clean) await clean().catch();
|
for (const clean of context.clean) await clean().catch(noop);
|
||||||
tmpfs.umount(context.tmpdir);
|
tmpfs.umount(context.tmpdir);
|
||||||
fs.removeSync(context.tmpdir);
|
fs.removeSync(context.tmpdir);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ const EMPTY_STR = /^[ \r\n\t]*$/i;
|
|||||||
|
|
||||||
export const cmd = parse;
|
export const cmd = parse;
|
||||||
|
|
||||||
|
export function noop() { }
|
||||||
|
|
||||||
export function parseTimeMS(str: string) {
|
export function parseTimeMS(str: string) {
|
||||||
const match = TIME_RE.exec(str);
|
const match = TIME_RE.exec(str);
|
||||||
if (!match) throw new FormatError(str, ['error parsing time']);
|
if (!match) throw new FormatError(str, ['error parsing time']);
|
||||||
|
|||||||
@@ -323,8 +323,8 @@ export class ProblemPretestConnectionHandler extends ConnectionHandler {
|
|||||||
@param('pid', Types.String)
|
@param('pid', Types.String)
|
||||||
async prepare(domainId: string, pid: string) {
|
async prepare(domainId: string, pid: string) {
|
||||||
const pdoc = await problem.get(domainId, pid);
|
const pdoc = await problem.get(domainId, pid);
|
||||||
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
|
||||||
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
|
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||||
|
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
this.pid = pdoc.docId.toString();
|
this.pid = pdoc.docId.toString();
|
||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.dispose = bus.on('record/change', this.onRecordChange.bind(this));
|
this.dispose = bus.on('record/change', this.onRecordChange.bind(this));
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
import type { Readable, Writable } from 'stream';
|
||||||
import { Readable, Writable } from 'stream';
|
import type { ObjectID } from 'mongodb';
|
||||||
import { ObjectID } from 'mongodb';
|
import type fs from 'fs';
|
||||||
import fs from 'fs';
|
import type { Dictionary, NumericDictionary } from 'lodash';
|
||||||
import { Dictionary, NumericDictionary } from 'lodash';
|
|
||||||
import type { Pdoc } from './model/problem';
|
import type { Pdoc } from './model/problem';
|
||||||
|
|
||||||
type document = typeof import('./model/document');
|
type document = typeof import('./model/document');
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ export async function getWithSecret(_id: ObjectID, secret: string, reject?: Func
|
|||||||
const file = await coll.findOne({ _id });
|
const file = await coll.findOne({ _id });
|
||||||
if (!file) throw new NotFoundError(_id);
|
if (!file) throw new NotFoundError(_id);
|
||||||
const timestamp = _timestamp();
|
const timestamp = _timestamp();
|
||||||
if (!(hash(file.secret, timestamp.toString()) === secret)) {
|
if (hash(file.secret, timestamp.toString()) !== secret) {
|
||||||
if (!(hash(file.secret, (timestamp - 1).toString()) === secret)) {
|
if (hash(file.secret, (timestamp - 1).toString()) !== secret) {
|
||||||
throw new ForbiddenError();
|
throw new ForbiddenError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export async function judge(domainId: string, rid: ObjectID) {
|
|||||||
if (rdoc.pid) {
|
if (rdoc.pid) {
|
||||||
const pdoc = await problem.get(domainId, rdoc.pid);
|
const pdoc = await problem.get(domainId, rdoc.pid);
|
||||||
if (!config) config = pdoc?.config || {};
|
if (!config) config = pdoc?.config || {};
|
||||||
data = pdoc.data;
|
data = pdoc?.data;
|
||||||
}
|
}
|
||||||
delete rdoc._id;
|
delete rdoc._id;
|
||||||
await task.add({
|
await task.add({
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ export class User implements _User {
|
|||||||
checkPassword(password: string) {
|
checkPassword(password: string) {
|
||||||
const h = global.Hydro.lib[`hash.${this.hashType}`];
|
const h = global.Hydro.lib[`hash.${this.hashType}`];
|
||||||
if (!h) throw new Error('Unknown hash method');
|
if (!h) throw new Error('Unknown hash method');
|
||||||
if (!(h(password, this.salt(), this) === this.hash())) {
|
if (h(password, this.salt(), this) !== this.hash()) {
|
||||||
throw new LoginError(this.uname);
|
throw new LoginError(this.uname);
|
||||||
} else if (this.hashType !== 'hydro') {
|
} else if (this.hashType !== 'hydro') {
|
||||||
setPassword(this._id, password);
|
setPassword(this._id, password);
|
||||||
|
|||||||
@@ -440,8 +440,7 @@ export class Handler {
|
|||||||
args.domainId = args.domainId || this.domainId;
|
args.domainId = args.domainId || this.domainId;
|
||||||
}
|
}
|
||||||
const { anchor } = args;
|
const { anchor } = args;
|
||||||
if (query) res = router.url(name, args, { query });
|
res = router.url(name, args, { query });
|
||||||
else res = router.url(name, args);
|
|
||||||
if (anchor) return `${res}#${anchor}`;
|
if (anchor) return `${res}#${anchor}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
@@ -563,10 +562,8 @@ export class Handler {
|
|||||||
this.ctx.response.status = 302;
|
this.ctx.response.status = 302;
|
||||||
this.ctx.redirect(this.response.redirect);
|
this.ctx.redirect(this.response.redirect);
|
||||||
} else {
|
} else {
|
||||||
if (this.response.body != null) {
|
this.ctx.response.body = this.response.body;
|
||||||
this.ctx.response.body = this.response.body;
|
this.ctx.response.status = this.response.status || 200;
|
||||||
this.ctx.response.status = this.response.status || 200;
|
|
||||||
}
|
|
||||||
this.ctx.response.type = this.request.json
|
this.ctx.response.type = this.request.json
|
||||||
? 'application/json'
|
? 'application/json'
|
||||||
: this.response.type
|
: this.response.type
|
||||||
@@ -683,7 +680,7 @@ const Checker = (permPrivChecker) => {
|
|||||||
if (typeof item === 'object') {
|
if (typeof item === 'object') {
|
||||||
if (typeof item.call !== 'undefined') {
|
if (typeof item.call !== 'undefined') {
|
||||||
checker = item;
|
checker = item;
|
||||||
} if (typeof item[0] === 'number') {
|
} else if (typeof item[0] === 'number') {
|
||||||
priv = item;
|
priv = item;
|
||||||
} else if (typeof item[0] === 'bigint') {
|
} else if (typeof item[0] === 'bigint') {
|
||||||
perm = item;
|
perm = item;
|
||||||
@@ -772,18 +769,22 @@ export class ConnectionHandler {
|
|||||||
url(name: string, kwargs: any = {}) {
|
url(name: string, kwargs: any = {}) {
|
||||||
let res = '#';
|
let res = '#';
|
||||||
const args: any = {};
|
const args: any = {};
|
||||||
|
const query: any = {};
|
||||||
for (const key in kwargs) {
|
for (const key in kwargs) {
|
||||||
if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString();
|
if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString();
|
||||||
else args[key] = kwargs[key].toString();
|
else args[key] = kwargs[key].toString();
|
||||||
}
|
}
|
||||||
|
for (const key in kwargs.query || {}) {
|
||||||
|
if (query[key] instanceof ObjectID) query[key] = kwargs.query[key].toHexString();
|
||||||
|
else query[key] = kwargs.query[key].toString();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (this.args.domainId !== 'system' || args.domainId) {
|
if (this.args.domainId !== 'system' || args.domainId) {
|
||||||
name += '_with_domainId';
|
name += '_with_domainId';
|
||||||
args.domainId = args.domainId || this.args.domainId;
|
args.domainId = args.domainId || this.args.domainId;
|
||||||
}
|
}
|
||||||
const { anchor, query } = args;
|
const { anchor } = args;
|
||||||
if (query) res = router.url(name, args, { query });
|
res = router.url(name, args, { query });
|
||||||
else res = router.url(name, args);
|
|
||||||
if (anchor) return `${res}#${anchor}`;
|
if (anchor) return `${res}#${anchor}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ async function message(src: Db, report: Function) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeInvalidPid(src: Db, report: Function) {
|
async function removeInvalidPid(report: Function) {
|
||||||
const count = await dst.collection('document').find({ docType: 10 }).count();
|
const count = await dst.collection('document').find({ docType: 10 }).count();
|
||||||
const bulk = dst.collection('document').initializeUnorderedBulkOp();
|
const bulk = dst.collection('document').initializeUnorderedBulkOp();
|
||||||
await report({ progress: 1, message: `Remove pid: ${count}` });
|
await report({ progress: 1, message: `Remove pid: ${count}` });
|
||||||
@@ -550,7 +550,7 @@ export async function run({
|
|||||||
await discussionNode(src, report);
|
await discussionNode(src, report);
|
||||||
await message(src, report);
|
await message(src, report);
|
||||||
await userfileUsage(src, report);
|
await userfileUsage(src, report);
|
||||||
await removeInvalidPid(src, report);
|
await removeInvalidPid(report);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user