src/server/upid.rs: check for illegal characters

This commit is contained in:
Dietmar Maurer 2019-04-15 07:47:51 +02:00
parent d2981e2738
commit 37b87869b5
1 changed files with 13 additions and 2 deletions

View File

@ -3,7 +3,7 @@ use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use chrono::Local; use chrono::Local;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; use std::sync::atomic::{AtomicUsize, Ordering};
use crate::tools; use crate::tools;
@ -45,7 +45,18 @@ impl UPID {
let pid = unsafe { libc::getpid() }; let pid = unsafe { libc::getpid() };
static WORKER_TASK_NEXT_ID: AtomicUsize = ATOMIC_USIZE_INIT; let bad: &[_] = &['/', ':', ' '];
if worker_type.contains(bad) {
bail!("illegal characters in worker type '{}'", worker_type);
}
if let Some(ref worker_id) = worker_id {
if worker_id.contains(bad) {
bail!("illegal characters in worker id '{}'", worker_id);
}
}
static WORKER_TASK_NEXT_ID: AtomicUsize = AtomicUsize::new(0);
let task_id = WORKER_TASK_NEXT_ID.fetch_add(1, Ordering::SeqCst); let task_id = WORKER_TASK_NEXT_ID.fetch_add(1, Ordering::SeqCst);