Commit b7ed06a445e9e307a715d3a14b04e4e3b3e31cfe
Committed by
Stéphane Raimbault
1 parent
e68f4f46
Fix crash modbus_new_rtu when baud is 0
Showing
1 changed file
with
7 additions
and
0 deletions
src/modbus-rtu.c
| ... | ... | @@ -1146,6 +1146,13 @@ modbus_t* modbus_new_rtu(const char *device, |
| 1146 | 1146 | modbus_t *ctx; |
| 1147 | 1147 | modbus_rtu_t *ctx_rtu; |
| 1148 | 1148 | |
| 1149 | + /* Check baud argument */ | |
| 1150 | + if (baud == 0) { | |
| 1151 | + fprintf(stderr, "baud must not be zero\n"); | |
| 1152 | + errno = EINVAL; | |
| 1153 | + return NULL; | |
| 1154 | + } | |
| 1155 | + | |
| 1149 | 1156 | ctx = (modbus_t *) malloc(sizeof(modbus_t)); |
| 1150 | 1157 | _modbus_init_common(ctx); |
| 1151 | 1158 | ctx->backend = &_modbus_rtu_backend; | ... | ... |