C path matching issue
- Lenguaje dominante
- CodeQL
- Estrellas
- 10.1k
- Forks
- 2.1k
- Merge medio
- 2 d 15 h
- PR fusionados (30 d)
- 141
Descripción
C language code
```
#include
#include
#include
#include
char buf[32];
int main(int argc, char* argv[], char* envp[]){
if(argc<2){
printf("./fd [输入一个参数]\n");
return 0;
}
int fd = atoi( argv[1] ) - 0x1234;
int len = 0;
len = read(fd, buf, 32);
if(!strcmp("LETMEWIN\n", buf)){
printf("恭喜你!挑战成功!\n");
exit(0);
}
printf("程序结束\n");
return 0;
}
```
This is my rule.
```
/**
* @kind path-problem
* @problem.severity warning
* @id getenv-to-gethostbyname
*/
import cpp
import semmle.code.cpp.dataflow.new.DataFlow
import semmle.code.cpp.dataflow.ExternalFlow
module ReadConfig implements DataFlow::ConfigSig{
predicate isSource(DataFlow::Node source) {
exists(Parameter p, ArrayExpr ae |
p.getFunction().getName() = "main" and
ae.getArrayBase() = p.getAnAccess() and
source.asExpr() = ae
)
}
predicate isSink(DataFlow::Node sink) {
exists(FunctionCall fc |
fc.getTarget().getName() = "read" and
sink.asExpr() = fc.getArgument(0)
)
}
}
module ReadConfigFlow = DataFlow::Global;
import ReadConfigFlow::PathGraph
from ReadConfigFlow::PathNode source, ReadConfigFlow::PathNode sink
where ReadConfigFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "read",
source, "input"
```
The source can match argv[1].
The sink can also match the file descriptor (fd) of the read function.
However, the rule as a whole fails to match the path.
Please help me.
Guía de contribución
Línea de trabajo
Comienza con el ejemplo de C proporcionado y la configuración de DataFlow ReadConfig, comparando la fuente argv[1] con el argumento de descriptor de archivo de la llamada a read. Rastrea cómo se representan la asignación de fd y el argumento de read en el PathGraph y determina después por qué las coincidencias individuales no producen una ruta completa. Se considera terminado cuando se haya documentado o reproducido la causa y se haya identificado el comportamiento de matching esperado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c
- Área
- security
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100