everywhere: use strlcpy and strlcat where appropriate

feature/tap-sh pkgconf-0.2
William Pitcock 2012-04-30 06:06:13 +00:00
parent 863498bfad
commit 3b154d8a5a
2 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@
* parse.c * parse.c
* Parser for .pc file. * Parser for .pc file.
* *
* Copyright (c) 2011 William Pitcock <nenolod@dereferenced.org>. * Copyright (c) 2011, 2012 William Pitcock <nenolod@dereferenced.org>.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -22,6 +22,7 @@
*/ */
#include "pkg.h" #include "pkg.h"
#include "bsdstubs.h"
static pkg_tuple_t * static pkg_tuple_t *
tuple_add(pkg_tuple_t *parent, const char *key, const char *value) tuple_add(pkg_tuple_t *parent, const char *key, const char *value)
@ -186,8 +187,8 @@ parse_deplist(pkg_t *pkg, const char *depends)
char *vstart = NULL; char *vstart = NULL;
char *package, *version; char *package, *version;
strncpy(buf, kvdepends, BUFSIZ); strlcpy(buf, kvdepends, sizeof buf);
strncat(buf, " ", BUFSIZ); strlcat(buf, " ", sizeof buf);
free(kvdepends); free(kvdepends);
while (*ptr) while (*ptr)

9
pkg.c
View File

@ -22,6 +22,7 @@
*/ */
#include "pkg.h" #include "pkg.h"
#include "bsdstubs.h"
#define PKG_CONFIG_EXT ".pc" #define PKG_CONFIG_EXT ".pc"
#define PKG_CONFIG_PATH_SZ (65535) #define PKG_CONFIG_PATH_SZ (65535)
@ -32,19 +33,17 @@ pkg_get_pkgconfig_path(void)
static bool computed = false; static bool computed = false;
static char path[PKG_CONFIG_PATH_SZ]; static char path[PKG_CONFIG_PATH_SZ];
char *env_path; char *env_path;
size_t len;
if (computed) if (computed)
return path; return path;
strncpy(path, PKG_DEFAULT_PATH, sizeof path); strlcpy(path, PKG_DEFAULT_PATH, sizeof path);
len = strlen(PKG_DEFAULT_PATH);
env_path = getenv("PKG_CONFIG_PATH"); env_path = getenv("PKG_CONFIG_PATH");
if (env_path != NULL) if (env_path != NULL)
{ {
strncat(path, ":", sizeof path - len - 1); strlcat(path, ":", sizeof path);
strncat(path, env_path, sizeof path - len - 2); strlcat(path, env_path, sizeof path);
} }
return path; return path;