aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-02-08 18:49:32 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2015-02-08 18:49:32 +0100
commit940cb233cebc5b932f875371df15d802984085f7 (patch)
treefcbe73c202e61a87aaba03e2fa9bb5ce2beefcec
parenta653e27a2e949bb62041509c2aab9787b3fbd480 (diff)
downloadlibssh-940cb233cebc5b932f875371df15d802984085f7.tar.gz
libssh-940cb233cebc5b932f875371df15d802984085f7.tar.xz
libssh-940cb233cebc5b932f875371df15d802984085f7.zip
buffer: buffer_pack & unpack on non-gnu compilersfreebsd
-rw-r--r--include/libssh/priv.h5
-rw-r--r--src/buffer.c20
2 files changed, 19 insertions, 6 deletions
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 4adcf898..90ae5bb4 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -304,6 +304,7 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
/**
* Get the argument cound of variadic arguments
*/
+#ifdef HAVE_GCC_NARG_MACRO
#define __VA_NARG__(...) \
(__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
#define __VA_NARG_(...) \
@@ -324,6 +325,10 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
+#else
+/* clang does not support the above construction */
+#define __VA_NARG__(...) (-1)
+#endif
#endif /* _LIBSSH_PRIV_H */
/* vim: set ts=4 sw=4 et cindent: */
diff --git a/src/buffer.c b/src/buffer.c
index d5ef6778..cb4b661d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -710,7 +710,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
for (p = format, count = 0; *p != '\0'; p++, count++) {
/* Invalid number of arguments passed */
- if (count > argc) {
+ if (argc != -1 && count > argc) {
return SSH_ERROR;
}
@@ -782,7 +782,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
}
}
- if (argc != count) {
+ if (argc != -1 && argc != count) {
return SSH_ERROR;
}
@@ -790,7 +790,11 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
/* Check if our canary is intact, if not somthing really bad happened */
uint32_t canary = va_arg(ap, uint32_t);
if (canary != SSH_BUFFER_PACK_END) {
- abort();
+ if (argc == -1){
+ return SSH_ERROR;
+ } else {
+ abort();
+ }
}
}
return rc;
@@ -865,7 +869,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
for (p = format, count = 0; *p != '\0'; p++, count++) {
/* Invalid number of arguments passed */
- if (count > argc) {
+ if (argc != -1 && count > argc) {
return SSH_ERROR;
}
@@ -956,7 +960,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
}
}
- if (argc != count) {
+ if (argc != -1 && argc != count) {
rc = SSH_ERROR;
}
@@ -964,7 +968,11 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
/* Check if our canary is intact, if not somthing really bad happened */
uint32_t canary = va_arg(ap, uint32_t);
if (canary != SSH_BUFFER_PACK_END){
- abort();
+ if (argc == -1){
+ rc = SSH_ERROR;
+ } else {
+ abort();
+ }
}
}