On 10:43, Wojcik, Artur wrote: > - char path[200]; > + char path[PATH_MAX]; PATH_MAX might be undefined if we're not using glibc. AFAIK the best one can do is something like #ifdef PATH_MAX path_max = PATH_MAX; #else /* * The result of pathconf(3) may be huge and unsuitable for * mallocing memory. OTOH pathconf(3) may return -1 to signify * that PATH_MAX is not bounded. */ path_max = pathconf(name, _PC_PATH_MAX); if (path_max <= 0 || path_max >= 4096) path_max = 4096; #endif > char vbuf[1024]; > int nlen = strlen(sra->sys_name); > int dn; > if (de->d_name[0] == '.') > continue; > - sprintf(path, "/sys/block/%s/md/metadata_version", > + snprintf(path, PATH_MAX, "/sys/block/%s/md/metadata_version", > de->d_name); > if (load_sys(path, vbuf) < 0) > continue; If you are really paranoid, you have to terminate the buffer when using snprintf. Moreover, one should prefer sizeof(path) over the explicit PATH_MAX because if you ever change the size of path again, you avoid the risk to change it only in the definition of path but not in the snprintf() call. Best Andre -- The only person who always got his work done by Friday was Robinson Crusoe
Attachment:
signature.asc
Description: Digital signature