aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-09-01 11:55:11 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2014-09-02 09:53:18 +0200
commit48bb3a37da6d0c9257b5cbb7bd2c6816b4ec5ab0 (patch)
tree68f9c16df4248cc544855bed4644c0065a2e7c64 /openbsc
parente3283ec3eb8d74423694ff5d54838ca6205f6991 (diff)
gbproxy: Remove nonnull attributes
The compiler also uses this attribute for code elimination. If the nonnull attribute has been given erroneously for an parameter, that is later been checked against NULL, this check is removed silently by the gcc if optimization is enabled. This can lead to hard-to-find segmentation violation faults. To be on the safe side, this patch removes all uses of the nonnull attribute in openbsc. Compiler: - gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1): no warning, segfault - clang 3.4 (3.4-1ubuntu3): no warning, no segfault, asm ok Example: /* foo.c */ int f(int* p) __attribute((nonnull)); int f(int *p) { if (!p) return 0; return *p; } /* main.c */ int f(int* p) __attribute((nonnull)); int g () { return f(arg); } int main() { return g(NULL); } When these files are compiled into an executable, no warnungs are issued but it will fail with a segfault when -O2 is used (unless LTO is active). Compiler output (gcc -O2): int f(int *p) { 0: 8b 44 24 04 mov 0x4(%esp),%eax 4: 8b 00 mov (%eax),%eax 6: c3 ret } Sponsored-by: On-Waves ehf
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/gb_proxy.h25
-rw-r--r--openbsc/include/openbsc/gprs_gb_parse.h8
2 files changed, 14 insertions, 19 deletions
diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h
index 9fcffd431..5c313211e 100644
--- a/openbsc/include/openbsc/gb_proxy.h
+++ b/openbsc/include/openbsc/gb_proxy.h
@@ -216,14 +216,12 @@ int gbproxy_check_imsi(
void gbproxy_patch_bssgp(
struct msgb *msg, uint8_t *bssgp, size_t bssgp_len,
struct gbproxy_peer *peer, struct gbproxy_tlli_info *tlli_info,
- int *len_change, struct gprs_gb_parse_context *parse_ctx)
- __attribute__((nonnull));
+ int *len_change, struct gprs_gb_parse_context *parse_ctx);
int gbproxy_patch_llc(
struct msgb *msg, uint8_t *llc, size_t llc_len,
struct gbproxy_peer *peer, struct gbproxy_tlli_info *tlli_info,
- int *len_change, struct gprs_gb_parse_context *parse_ctx)
- __attribute__((nonnull));
+ int *len_change, struct gprs_gb_parse_context *parse_ctx);
int gbproxy_set_patch_filter(
struct gbproxy_config *cfg, const char *filter, const char **err_msg);
@@ -233,20 +231,17 @@ int gbproxy_check_imsi(
/* Peer handling */
struct gbproxy_peer *gbproxy_peer_by_bvci(
- struct gbproxy_config *cfg, uint16_t bvci) __attribute__((nonnull));
+ struct gbproxy_config *cfg, uint16_t bvci);
struct gbproxy_peer *gbproxy_peer_by_nsei(
- struct gbproxy_config *cfg, uint16_t nsei) __attribute__((nonnull));
+ struct gbproxy_config *cfg, uint16_t nsei);
struct gbproxy_peer *gbproxy_peer_by_rai(
- struct gbproxy_config *cfg, const uint8_t *ra) __attribute__((nonnull));
+ struct gbproxy_config *cfg, const uint8_t *ra);
struct gbproxy_peer *gbproxy_peer_by_lai(
- struct gbproxy_config *cfg, const uint8_t *la) __attribute__((nonnull));
+ struct gbproxy_config *cfg, const uint8_t *la);
struct gbproxy_peer *gbproxy_peer_by_bssgp_tlv(
- struct gbproxy_config *cfg, struct tlv_parsed *tp)
- __attribute__((nonnull));
-struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci)
- __attribute__((nonnull));
-void gbproxy_peer_free(struct gbproxy_peer *peer) __attribute__((nonnull));
-int gbproxy_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci)
- __attribute__((nonnull));
+ struct gbproxy_config *cfg, struct tlv_parsed *tp);
+struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci);
+void gbproxy_peer_free(struct gbproxy_peer *peer);
+int gbproxy_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci);
#endif
diff --git a/openbsc/include/openbsc/gprs_gb_parse.h b/openbsc/include/openbsc/gprs_gb_parse.h
index e5ef4ef43..0aa364765 100644
--- a/openbsc/include/openbsc/gprs_gb_parse.h
+++ b/openbsc/include/openbsc/gprs_gb_parse.h
@@ -40,13 +40,13 @@ struct gprs_gb_parse_context {
};
int gprs_gb_parse_dtap(uint8_t *data, size_t data_len,
- struct gprs_gb_parse_context *parse_ctx) __attribute__((nonnull));
+ struct gprs_gb_parse_context *parse_ctx);
int gprs_gb_parse_llc(uint8_t *llc, size_t llc_len,
- struct gprs_gb_parse_context *parse_ctx) __attribute__((nonnull));
+ struct gprs_gb_parse_context *parse_ctx);
int gprs_gb_parse_bssgp(uint8_t *bssgp, size_t bssgp_len,
- struct gprs_gb_parse_context *parse_ctx) __attribute__((nonnull));
+ struct gprs_gb_parse_context *parse_ctx);
void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
- const char *default_msg_name) __attribute__((nonnull(1)));
+ const char *default_msg_name);