wolkykim / qlibc

qLibc is a simple and yet powerful C library providing generic data structures and algorithms.

Home Page:http://wolkykim.github.io/qlibc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

qhex_decode segfault

rwhitworth opened this issue · comments

#include "qlibc.h"

int main(int argc, char *argv[]) {
  char* str = "JW";

  qhex_decode(str);

  return(0);
}

This program segfaults when run. The function definition says it will return NULL if there is any problem but I do not see any checks being done. Would it be enough to check if the characters are in the valid set of characters for this function? [0-9][a-f][A-F] or something similar.

Valgrind shows this:

==6475== Memcheck, a memory error detector
==6475== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==6475== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==6475== Command: ./ex
==6475==
==6475==
==6475== Process terminating with default action of signal 11 (SIGSEGV)
==6475==  Bad permissions for mapped region at address 0x111004
==6475==    at 0x10AE58: qhex_decode (qencode.c:448)
==6475==    by 0x10A43F: main (ex.c:6)
==6475==
==6475== HEAP SUMMARY:
==6475==     in use at exit: 0 bytes in 0 blocks
==6475==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==6475==
==6475== All heap blocks were freed -- no leaks are possible
==6475==
==6475== For counts of detected and suppressed errors, rerun with: -v
==6475== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

same reason as #70