Increasing PPID via /proc reading buffer to avoid buffer overflow.

This commit is contained in:
Martin Dvorak 2015-02-13 10:55:42 +01:00
parent 36f0c3de69
commit 7db8f8271b
2 changed files with 5 additions and 3 deletions

View file

@ -1,6 +1,6 @@
hstr
====
Easily view, navigate, sort and use your command history with shell history suggest box for Bash and
Easily view, navigate, search and use your command history with shell history suggest box for Bash and
[Zsh](CONFIGURATION.md#zsh-history-settings).
[![BASH History Suggest Box](http://mindforger.com/projects/images/hh-animated-01.gif "BASH History Suggest Box @ YouTube")](http://www.youtube.com/watch?v=sPF29NyXe2U)

View file

@ -13,6 +13,8 @@
#define DEFAULT_COMMAND "pwd"
#define PROC_HOSTNAME "/proc/sys/kernel/hostname"
// TODO PID_BUFFER 11+ characters might be enough
#define PID_BUFFER_SIZE 128
// strdup() not in ISO C
char *hstr_strdup(const char * s)
@ -128,12 +130,12 @@ void toggle_case(char *str, bool lowercase) {
char *get_process_name_by_pid(const int pid)
{
char* name = (char*)calloc(10,sizeof(char));
char* name = (char*)calloc(PID_BUFFER_SIZE,sizeof(char));
if(name){
sprintf(name, "/proc/%d/cmdline",pid);
FILE* f = fopen(name,"r");
if(f){
size_t size = fread(name, sizeof(char), 10, f);
size_t size = fread(name, sizeof(char), PID_BUFFER_SIZE-1, f);
if(size>0){
if('\n'==name[size-1]) {
name[size-1]='\0';