mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zdev: Harden against invalid hypervisor data
Reduce chances of unintended side-effects when evaluating hypervisor data which might have been corrupted. Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
4ca93aa808
commit
a048670bec
32
zdev/include/sanitize.h
Normal file
32
zdev/include/sanitize.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* zdev - Modify and display the persistent configuration of devices
|
||||
*
|
||||
* Copyright IBM Corp. 2026
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef SANITIZE_H
|
||||
#define SANITIZE_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Valid control-program identifier special characters */
|
||||
#define VALID_CPNAME "/"
|
||||
|
||||
static inline int is_safe_char(unsigned char c, const char *set)
|
||||
{
|
||||
return isalnum(c) || strchr(set, c);
|
||||
}
|
||||
|
||||
static inline void sanitize(char *s, const char *set)
|
||||
{
|
||||
for (; *s; s++) {
|
||||
if (!is_safe_char((unsigned char)*s, set))
|
||||
*s = '_';
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SANITIZE_H */
|
||||
Reference in New Issue
Block a user